4
4
#
5
5
6
6
import argparse
7
- import sys
8
7
9
8
# --- patch sys.path to make sure 'import roundup' finds correct version
10
9
import os .path as osp
10
+ import sys
11
11
12
12
thisdir = osp .dirname (osp .abspath (__file__ ))
13
13
rootdir = osp .dirname (osp .dirname (thisdir ))
18
18
# --/
19
19
20
20
# import also verifies python version as side effect
21
- from roundup import version_check # noqa: F401 E402
22
- from roundup import admin , configuration , demo , instance # noqa: E402
23
- from roundup import __version__ as roundup_version # noqa: E402
24
- from roundup .anypy .my_input import my_input # noqa: E402
25
- from roundup .backends import list_backends # noqa: E402
26
- from roundup .i18n import _ # noqa: E402
27
-
21
+ from roundup import __version__ as roundup_version # noqa: E402
22
+ from roundup import admin , configuration , demo , instance , version_check # noqa: F401 E402
23
+ from roundup .anypy .my_input import my_input # noqa: E402
24
+ from roundup .backends import list_backends # noqa: E402
25
+ from roundup .i18n import _ # noqa: E402
28
26
29
27
DEFAULT_HOME = './demo'
30
28
DEFAULT_TEMPLATE = 'classic'
@@ -46,12 +44,29 @@ def usage(home, cli, msg=''):
46
44
if msg :
47
45
print (msg )
48
46
47
+
48
+ def ask_for_template (default_template , templates ):
49
+ import pdb ; pdb .set_trace ()
50
+ template = my_input (
51
+ _ ('Enter tracker template to use (one of (%(template_list)s)) [%(default_template)s]: ' ) %
52
+ {'template_list' : ',' .join (templates ),
53
+ 'default_template' : default_template })
54
+
55
+ if not template :
56
+ template = default_template
57
+ elif template not in templates :
58
+ print ("Unknown template: %s. Exiting." % template )
59
+ return None
60
+
61
+ return template
62
+
63
+
49
64
def run ():
50
65
templates = admin .AdminTool ().listTemplates ().keys ()
51
66
backends = list_backends ()
52
67
53
68
cli = argparse .ArgumentParser (
54
- description = """
69
+ description = """
55
70
Instant gratification demo - Roundup Issue Tracker
56
71
57
72
Run a demo server. Config and database files are created in
@@ -70,35 +85,35 @@ def run():
70
85
71
86
cli .add_argument ('-B' , '--bind_address' ,
72
87
default = "127.0.0.1" ,
73
- help = ( "Choose address for server to listen at.\n "
74
- "Use 0.0.0.0 to bind to all addreses. Use\n "
75
- "the external name of the computer to bind to\n "
76
- "the external host interface.\n "
77
- "Default: %(default)s.\n \n " ))
88
+ help = ("Choose address for server to listen at.\n "
89
+ "Use 0.0.0.0 to bind to all addreses. Use\n "
90
+ "the external name of the computer to bind to\n "
91
+ "the external host interface.\n "
92
+ "Default: %(default)s.\n \n " ))
78
93
cli .add_argument ('-b' , '--backend_db' ,
79
94
choices = backends ,
80
- help = ( "Choose backend database. Default: %s.\n \n " %
81
- DEFAULT_BACKEND ))
95
+ help = ("Choose backend database. Default: %s.\n \n " %
96
+ DEFAULT_BACKEND ))
82
97
cli .add_argument ('-H' , '--hostname' ,
83
98
default = "localhost" ,
84
- help = ( "Choose hostname for the server.\n "
85
- "Default: %(default)s.\n \n "
99
+ help = ("Choose hostname for the server.\n "
100
+ "Default: %(default)s.\n \n "
86
101
))
87
102
cli .add_argument ('-t' , '--template' ,
88
103
choices = templates ,
89
104
help = "Use specified template. (*)\n \n " )
90
105
cli .add_argument ('-p' , '--port' ,
91
106
type = int ,
92
- help = ( "Listen at this port. Default: search for\n "
93
- "open port starting at %s\n \n " % DEFAULT_PORT ))
107
+ help = ("Listen at this port. Default: search for\n "
108
+ "open port starting at %s\n \n " % DEFAULT_PORT ))
94
109
cli .add_argument ('-P' , '--urlport' ,
95
110
type = int ,
96
- help = ( "Set docker external port. If using\n "
97
- " docker ... -p 9090:8917 ...\n "
98
- "this should be set to 9090.\n "
99
- "Default: as selected by --port\n \n " ))
111
+ help = ("Set docker external port. If using\n "
112
+ " docker ... -p 9090:8917 ...\n "
113
+ "this should be set to 9090.\n "
114
+ "Default: as selected by --port\n \n " ))
100
115
cli .add_argument ('-V' , '--version' , action = 'version' ,
101
- version = 'Roundup version %s' % roundup_version ,
116
+ version = 'Roundup version %s' % roundup_version ,
102
117
help = (
103
118
"Show program's version number: %s and exit\n " %
104
119
roundup_version ))
@@ -109,20 +124,21 @@ def run():
109
124
# add 'nuke' to choices so backend will accept nuke if only 2 args.
110
125
choices = backends + ['nuke' ]
111
126
cli .add_argument ('backend' , nargs = '?' , metavar = 'backend' , choices = choices ,
112
- help = ( "Choose backend database. "
113
- "Depricated, use -b instead.\n "
127
+ help = ("Choose backend database. "
128
+ "Depricated, use -b instead.\n "
114
129
"If it is used, you *must* specify directory.\n \n " ))
115
130
116
131
cli .add_argument ('nuke' , nargs = '?' , metavar = 'nuke' , choices = ['nuke' ],
117
- help = ( "The word 'nuke' will delete tracker and reset.\n "
118
- "E.G. %(prog)s -b sqlite \\ \n "
119
- "-t classic ./mytracker nuke\n " ) % {"prog" : sys .argv [0 ]})
132
+ help = ("The word 'nuke' will delete tracker and reset.\n "
133
+ "E.G. %(prog)s -b sqlite \\ \n "
134
+ "-t classic ./mytracker nuke\n " ) % {"prog" : sys .argv [0 ]})
120
135
121
136
cli_args = cli .parse_args ()
122
137
123
138
# collect all positional args in order in array to parse
124
139
# strip all None.
125
- cli_args .cmd = [ x for x in [cli_args .directory , cli_args .backend , cli_args .nuke ] if x != None ]
140
+ cli_args .cmd = [x for x in [cli_args .directory , cli_args .backend , cli_args .nuke ]
141
+ if x is not None ]
126
142
127
143
try :
128
144
nuke = cli_args .cmd [- 1 ] == 'nuke'
@@ -155,43 +171,34 @@ def run():
155
171
# if there is no tracker in home, force nuke
156
172
try :
157
173
instance .open (home )
158
- valid_home = True
159
174
except configuration .NoConfigError :
160
175
nuke = True
161
- valid_home = False
162
176
163
177
# if we are to create the tracker, prompt for settings
164
178
if nuke :
165
179
# FIXME: i'd like to have an option to abort the tracker creation
166
180
# say, by entering a single dot. but i cannot think of
167
181
# appropriate prompt for that.
168
- if not cli_args .template in templates :
169
- template = my_input (
170
- _ ('Enter tracker template to use (one of (%(template_list)s)) [%(default_template)s]: ' ) %
171
- { 'template_list' : ',' .join (templates ),
172
- 'default_template' : template })
182
+ if cli_args .template not in templates :
183
+ template = ask_for_template (template , templates )
173
184
if not template :
174
- template = DEFAULT_TEMPLATE
175
- elif template not in templates :
176
- print ("Unknown template: %s. Exiting." % template )
177
- exit (1 )
185
+ sys .exit (1 )
178
186
# install
179
187
url_port = cli_args .urlport or cli_args .port or DEFAULT_PORT
180
188
demo .install_demo (home , backend ,
181
189
admin .AdminTool ().listTemplates ()[template ]['path' ],
182
190
use_port = url_port , use_host = cli_args .hostname )
183
- else :
184
- # make sure that no options are specified that are only useful on initialization.
185
- if ( cli_args .backend or cli_args .template or
186
- cli_args .backend_db ):
187
- usage (home , cli , msg = (
188
- "Specifying backend or template is only allowed when\n "
189
- "creating a tracker or with nuke.\n " ))
190
- exit (1 )
191
+ elif (cli_args .backend or cli_args .template or cli_args .backend_db ):
192
+ # options were specified that are only useful on initialization.
193
+ usage (home , cli , msg = (
194
+ "Specifying backend or template is only allowed when\n "
195
+ "creating a tracker or with nuke.\n " ))
196
+ sys .exit (1 )
191
197
# run
192
198
demo .run_demo (home , bind_addr = cli_args .bind_address ,
193
199
bind_port = cli_args .port )
194
200
201
+
195
202
if __name__ == '__main__' :
196
203
run ()
197
204
0 commit comments