Mercurial > p > roundup > code
view roundup/demo.py @ 6628:2bb6d7baa47d
"Comment" out the meta data - will not process under 1.7.5 sphinx
Apparently field names with : fail on 1.7.5 sphinx which is the
virtual env version on sourceforge. It works on my 1.6.7 python2
install.
Looks like I need to add sphinxext-opengraph to get this to work.
However that is python3 only so need to spin up new virtualenv etc.
Looks like no python3 on sourceforge which may be an issue.
On sourceforge in /home/project-web/roundup/src/docbuilder these
packages are used and must be scp'ed as pip has no network access
outside of sourceforge:
Babel-2.6.0-py2.py3-none-any.whl
Jinja2-2.10-py2.py3-none-any.whl
MarkupSafe-1.0.tar.gz
Pygments-2.2.0-py2.py3-none-any.whl
Sphinx-1.7.5
Sphinx-1.7.5-py2.py3-none-any.whl
Sphinx-1.7.5.tar.gz
alabaster-0.7.11-py2.py3-none-any.whl
certifi-2018.4.16-py2.py3-none-any.whl
chardet-3.0.4-py2.py3-none-any.whl
docutils-0.14-py2-none-any.whl
idna-2.7-py2.py3-none-any.whl
imagesize-1.0.0-py2.py3-none-any.whl
packaging-17.1-py2.py3-none-any.whl
pip-10.0.1
pip-10.0.1.tar.gz
pyparsing-2.2.0-py2.py3-none-any.whl
pytz-2018.5-py2.py3-none-any.whl
requests-2.19.1-py2.py3-none-any.whl
setuptools-39.2.0-py2.py3-none-any.whl
six-1.11.0-py2.py3-none-any.whl
snowballstemmer-1.2.1-py2.py3-none-any.whl
sphinxcontrib_websupport-1.1.0-py2.py3-none-any.whl
typing-3.6.4-py2-none-any.whl
urllib3-1.23-py2.py3-none-any.whl
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 27 Mar 2022 13:57:04 -0400 |
| parents | 5a3a386aa8e7 |
| children | 7147a4c833e9 |
line wrap: on
line source
#!/usr/bin/env python # # Copyright (c) 2003 Richard Jones (richard@mechanicalcat.net) # from __future__ import print_function import errno import os import shutil import socket import sys import getopt try: import urlparse except ImportError: import urllib.parse as urlparse from roundup import configuration from roundup.scripts import roundup_server # Path where demo instance files will be stored TRACKER_HOME = os.path.abspath('demo') def install_demo(home, backend, template): """Install a demo tracker Parameters: home: tracker home directory path backend: database backend name template: tracker template """ from roundup import init, instance, password # set up the config for this tracker template_dir = os.path.join('share', 'roundup', 'templates', template) # Load optional override ini file. Missing ini file is ignored. template_cfg = configuration.UserConfig(template_dir + "/config_ini.ini") config = configuration.CoreConfig(settings={ i.name: i.get() for i in template_cfg.items() }) config['TRACKER_HOME'] = home config['MAIL_DOMAIN'] = 'localhost' config['DATABASE'] = 'db' config['WEB_DEBUG'] = True if backend in ('mysql', 'postgresql'): config['RDBMS_HOST'] = 'localhost' config['RDBMS_USER'] = 'rounduptest' config['RDBMS_PASSWORD'] = 'rounduptest' config['RDBMS_NAME'] = 'rounduptest' config['RDBMS_BACKEND'] = backend # see if we need to clean up existing directory if os.path.exists(home): if os.path.exists(home + '/config.ini'): # clear everything out to avoid conflicts with former # extensions and detectors print("Nuking directory left from the previous demo instance.") shutil.rmtree(home) else: print("Error: Refusing to nuke non-tracker directory:") print(" %s" % home) sys.exit(1) init.install(home, template_dir) # Remove config_ini.ini file from tracker_home (not template dir). # Ignore file not found - not all templates have # config_ini.ini files. try: os.remove(home + "/config_ini.ini") except OSError as e: # FileNotFound exception under py3 if e.errno == 2: pass else: raise # don't have email flying around nosyreaction = os.path.join(home, 'detectors', 'nosyreaction.py') if os.path.exists(nosyreaction): os.remove(nosyreaction) nosyreaction += 'c' if os.path.exists(nosyreaction): os.remove(nosyreaction) # figure basic params for server hostname = 'localhost' # pick a fairly odd, random port port = 8917 while 1: print('Trying to set up web server on port %d ...' % port,) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: s.connect((hostname, port)) except socket.error as e: if not hasattr(e, 'args') or e.args[0] != errno.ECONNREFUSED: raise print('should be ok.') break else: s.close() print('already in use.') port += 100 config['TRACKER_WEB'] = 'http://%s:%s/demo/' % (hostname, port) # write the config config['INSTANT_REGISTRATION'] = 1 config.save(os.path.join(home, config.INI_FILE)) # open the tracker and initialise tracker = instance.open(home) tracker.init(password.Password('admin')) # add the "demo" user db = tracker.open('admin') # FIXME: Move tracker-specific demo initialization into the tracker # templates. if os.path.basename(template) == 'minimal': db.user.create(username='demo', password=password.Password('demo'), roles='User') else: db.user.create(username='demo', password=password.Password('demo'), realname='Demo User', roles='User') db.commit() db.close() def run_demo(home): """Run the demo tracker instance from its ``home`` directory""" print("Demo Tracker Home:", home) cfg = configuration.CoreConfig(home) url = cfg["TRACKER_WEB"] hostname, port = urlparse.urlparse(url)[1].split(':') port = int(port) success_message = '''Server running - connect to: %(url)s 1. Log in as "demo"/"demo" or "admin"/"admin". 2. Hit Control-C to stop the server. 3. Re-start the server by running "%(script)s" again. 4. Reset the tracker by running "%(script)s nuke". By default the demo tracker is set up to be accessed from "localhost". If you want to run it on a server, edit "%(datadir)s/config.ini" and set the "web" option in section "[tracker]" to your host name, then restart demo. If you want to change backend types, you must use "nuke". ''' % dict(url=url, script=sys.argv[0], datadir=TRACKER_HOME) # disable command line processing in roundup_server sys.argv = sys.argv[:1] + ['-p', str(port), '-n', hostname, 'demo=' + home] roundup_server.run(success_message=success_message) def usage(msg=''): if msg: print(msg) print("""\ Usage: %(script)s [options] [nuke] Run a demo server. Config and database files are created in %(datadir)s subdirectory of %(script)s dir. 'nuke' will re-initialize the demo instance, deleting the old data. See docs/installation "For The Really Impatient" for more details. Options: -h -- print this help message -t template -- specify the tracker template to use -b backend -- specify the database backend to use """ % dict(script=sys.argv[0], datadir=TRACKER_HOME+os.sep)) def main(): """Run a demo server for users to play with for instant gratification. Sets up the web service on localhost. Disables nosy lists. """ try: opts, args = getopt.getopt(sys.argv[1:], 't:b:h') except getopt.GetoptError as e: usage(str(e)) return 1 for opt, _arg in opts: if opt == '-h': usage() return 0 home = os.path.abspath(TRACKER_HOME) nuke = args and args[0] == 'nuke' if not os.path.exists(home) or nuke: backend = 'anydbm' template = 'classic' for opt, arg in opts: if opt == '-t': template = arg elif opt == '-b': backend = arg if (len(args) > 1 or (len(args) == 1 and args[0] != 'nuke')): usage() return 1 print("Initializing demo instance in:\n %s" % home) install_demo(home, backend, template) elif opts: print("Error: Arguments are not allowed when running an existing demo.") print(" Use the 'nuke' command to start over.") sys.exit(1) run_demo(home) if __name__ == '__main__': sys.exit(main()) # vim: set filetype=python sts=4 sw=4 et si :
