comparison roundup/scripts/roundup_demo.py @ 7340:7b9bddda9d2d

Add support for demo mode in docker. roundup/demo.py Make changes to allow exposed port in docker to be specified separately from the port that demo mode binds to. Also permit bind address specification as well. roundup/scripts/roundup_demo.py: Update required by changes in demo.py. Also move away from positional arguments to prefer flag arguments. Required for passing port and host specification. Flake8 fixes. share/man/man1/roundup-demo.1 Document use of option flags rather than positional params. Other cleanups. doc/installation.txt: Document new docker modes: demo, shell and admin. Update docs: overview section - reorg, added template info for the impatient section - added docker demo mode reference, more docs on top level demo.py use. new section on docker demo mode removed getting roundup section. folded into installing roundup. also prior for the impatient section describes how to download. install via pip in venv recommended supported method document all provided templates. not just minimal and classic. added index references. move sections around, decreased sectin depth, reformatting scripts/Docker/roundup_healthcheck: When running roundup-demo, there is no tracker spec. So default to demo if no tracker=directory args found. Prevent's docker from reporting an unhealthy container when running demo. scripts/Docker/roundup_start: implement demo, shell, admin docker modes.
author John Rouillard <rouilj@ieee.org>
date Sun, 14 May 2023 09:43:53 -0400
parents 062a54eeb0a1
children c73a1177c2b2
comparison
equal deleted inserted replaced
7339:5eadba24e148 7340:7b9bddda9d2d
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 # 2 #
3 # Copyright 2004 Richard Jones (richard@mechanicalcat.net) 3 # Copyright 2004 Richard Jones (richard@mechanicalcat.net)
4 # 4 #
5 5
6 DEFAULT_HOME = './demo' 6 import argparse
7 DEFAULT_TEMPLATE = 'classic'
8
9
10 import sys 7 import sys
11
12 8
13 # --- patch sys.path to make sure 'import roundup' finds correct version 9 # --- patch sys.path to make sure 'import roundup' finds correct version
14 import os.path as osp 10 import os.path as osp
15 11
16 thisdir = osp.dirname(osp.abspath(__file__)) 12 thisdir = osp.dirname(osp.abspath(__file__))
19 osp.exists(rootdir + '/roundup/__init__.py')): 15 osp.exists(rootdir + '/roundup/__init__.py')):
20 # the script is located inside roundup source code 16 # the script is located inside roundup source code
21 sys.path.insert(0, rootdir) 17 sys.path.insert(0, rootdir)
22 # --/ 18 # --/
23 19
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
24 27
25 from roundup import admin, configuration, demo, instance 28
26 from roundup.i18n import _ 29 DEFAULT_HOME = './demo'
27 from roundup.anypy.my_input import my_input 30 DEFAULT_TEMPLATE = 'classic'
28 from roundup import version_check 31 DEFAULT_BACKEND = 'sqlite'
32 DEFAULT_PORT = 8917
33
34
35 def usage(home, cli, msg=''):
36
37 # massage the help. I want [directory [backend]] but there is no way to
38 # specify that in argparse, so replace the three positional args with
39 # the proper syntax.
40 usage = cli.format_help() % dict(locals())
41 usage = usage.replace('[directory] [backend] [nuke]',
42 '[[directory] [backend]] [nuke]')
43
44 print("%s\n" % usage)
45
46 if msg:
47 print(msg)
29 48
30 def run(): 49 def run():
31 home = DEFAULT_HOME 50 templates = admin.AdminTool().listTemplates().keys()
32 template = DEFAULT_TEMPLATE 51 backends = list_backends()
33 nuke = sys.argv[-1] == 'nuke' 52
53 cli = argparse.ArgumentParser(
54 description= """
55 Instant gratification demo - Roundup Issue Tracker
56
57 Run a demo server. Config and database files are created in
58 'directory' (current setting/default '%(home)s') which should
59 not exist or should exist and already be a tracker home
60 directory (usually used with nuke).
61
62 'nuke' will re-initialize the tracker instance, deleting the old data.
63
64 The tracker that is created will have email notifications turned off.
65 """ % {"home": DEFAULT_HOME},
66 epilog=("\nIf items marked with (*) are missing, they will be "
67 "asked for interactively when setting up the tracker."),
68 formatter_class=argparse.RawTextHelpFormatter,
69 add_help=True)
70
71 cli.add_argument('-B', '--bind_address',
72 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.\n"
75 "Default: %(default)s.\n\n"))
76 cli.add_argument('-b', '--backend_db',
77 choices=backends,
78 help=( "Choose backend database. Default: %s.\n\n" %
79 DEFAULT_BACKEND))
80 cli.add_argument('-t', '--template',
81 choices=templates,
82 help="Use specified template. (*)\n\n")
83 cli.add_argument('-p', '--port',
84 type=int,
85 help=( "Listen at this port. Default: search for\n"
86 "open port starting at %s\n\n" % DEFAULT_PORT))
87 cli.add_argument('-P', '--urlport',
88 type=int,
89 help=( "Set docker external port. If using\n"
90 " docker ... -p 9090:8917 ..."
91 "this should be set to 9090. "
92 "Default: as selected by --port\n\n"))
93 cli.add_argument('-V', '--version', action='version',
94 version='Roundup version %s'%roundup_version,
95 help=(
96 "Show program's version number: %s and exit\n" %
97 roundup_version))
98
99 cli.add_argument('directory', nargs='?',
100 help="Create home for tracker in directory. (*)\n")
101
102 # add 'nuke' to choices so backend will accept nuke if only 2 args.
103 choices = backends + ['nuke']
104 cli.add_argument('backend', nargs='?', metavar='backend', choices=choices,
105 help=( "Choose backend database. "
106 "Depricated, use -b instead.\n"
107 "If it is used, you *must* specify directory.\n\n"))
108
109 cli.add_argument('nuke', nargs='?', metavar='nuke', choices=['nuke'],
110 help=( "The word 'nuke' will delete tracker and reset.\n"
111 "E.G. %(prog)s -b sqlite -t classic ./mytracker nuke\n") % {"prog": sys.argv[0]})
112
113 cli_args = cli.parse_args()
114
115 # collect all positional args in order in array to parse
116 # strip all None.
117 cli_args.cmd = [ x for x in [cli_args.directory, cli_args.backend, cli_args.nuke] if x != None ]
118
119 try:
120 nuke = cli_args.cmd[-1] == 'nuke'
121 if nuke:
122 _ignore = cli_args.cmd.pop() # remove nuke
123 except IndexError:
124 nuke = False
125
126 try:
127 tracker_home = cli_args.cmd[0]
128 except IndexError:
129 tracker_home = None
130
131 # invoked as demo tracker_dir sqlite [nuke]
132 try:
133 cli_backend = cli_args.cmd[1]
134 except IndexError:
135 cli_backend = None
136
137 home = tracker_home or DEFAULT_HOME
138 template = cli_args.template or DEFAULT_TEMPLATE
139 backend = cli_args.backend_db or cli_backend or DEFAULT_BACKEND
140
34 # if there is no tracker in home, force nuke 141 # if there is no tracker in home, force nuke
35 try: 142 try:
36 instance.open(home) 143 instance.open(home)
144 valid_home = True
37 except configuration.NoConfigError: 145 except configuration.NoConfigError:
38 nuke = 1 146 nuke = True
39 # if we are to create the tracker, prompt for home 147 valid_home = False
148
149 # if we are to create the tracker, prompt for settings
40 if nuke: 150 if nuke:
41 if len(sys.argv) > 2:
42 backend = sys.argv[-2]
43 else:
44 backend = 'anydbm'
45 # FIXME: i'd like to have an option to abort the tracker creation 151 # FIXME: i'd like to have an option to abort the tracker creation
46 # say, by entering a single dot. but i cannot think of 152 # say, by entering a single dot. but i cannot think of
47 # appropriate prompt for that. 153 # appropriate prompt for that.
48 home = my_input( 154 if not tracker_home:
49 _('Enter directory path to create demo tracker [%s]: ') % home) 155 home = my_input(
50 if not home: 156 _('Enter directory path to create demo tracker [%s]: ') % home)
51 home = DEFAULT_HOME 157 if not home:
52 templates = admin.AdminTool().listTemplates().keys() 158 home = DEFAULT_HOME
53 template = my_input( 159
54 _('Enter tracker template to use (one of (%(template_list)s)) [%(d\ 160 if not cli_args.template in templates:
55 efault_template)s]: ') % 161 template = my_input(
162 _('Enter tracker template to use (one of (%(template_list)s)) [%(default_template)s]: ') %
56 { 'template_list': ','.join(templates), 163 { 'template_list': ','.join(templates),
57 'default_template': template}) 164 'default_template': template})
58 if not template: 165 if not template:
59 template = DEFAULT_TEMPLATE 166 template = DEFAULT_TEMPLATE
167 elif template not in templates:
168 print("Unknown template: %s. Exiting." % template)
169 exit(1)
60 # install 170 # install
61 demo.install_demo(home, backend, 171 demo.install_demo(home, backend,
62 admin.AdminTool().listTemplates()[template]['path']) 172 admin.AdminTool().listTemplates()[template]['path'],
173 use_port=cli_args.urlport or DEFAULT_PORT)
174 else:
175 # make sure that no options are specified that are only useful on initialization.
176 if ( cli_args.backend or cli_args.template or
177 cli_args.backend_db ):
178 usage(home, cli, msg=(
179 "Specifying backend or template is only allowed when\n"
180 "creating a tracker or with nuke.\n"))
181 exit(1)
63 # run 182 # run
64 demo.run_demo(home) 183 demo.run_demo(home, bind_addr=cli_args.bind_address,
65 184 bind_port=cli_args.port)
66 185
67 if __name__ == '__main__': 186 if __name__ == '__main__':
68 run() 187 run()
69 188
70 # vim: set et sts=4 sw=4 : 189 # vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/