[llvm-commits] [zorg] r125855 - in /zorg/trunk/llvmlab: llvmlab/TODO.txt llvmlab/llvmlabtool/ llvmlab/llvmlabtool/__init__.py llvmlab/llvmlabtool/lab.cfg.sample llvmlab/llvmlabtool/main.py llvmlab/ui/app.py llvmlab/ui/templates/layout.html setup.py
Daniel Dunbar
daniel at zuster.org
Fri Feb 18 08:40:24 PST 2011
Author: ddunbar
Date: Fri Feb 18 10:40:24 2011
New Revision: 125855
URL: http://llvm.org/viewvc/llvm-project?rev=125855&view=rev
Log:
llvmlab: Add basic llvmlab tool and config file.
Added:
zorg/trunk/llvmlab/llvmlab/llvmlabtool/
zorg/trunk/llvmlab/llvmlab/llvmlabtool/__init__.py
zorg/trunk/llvmlab/llvmlab/llvmlabtool/lab.cfg.sample
zorg/trunk/llvmlab/llvmlab/llvmlabtool/main.py
Modified:
zorg/trunk/llvmlab/llvmlab/TODO.txt
zorg/trunk/llvmlab/llvmlab/ui/app.py
zorg/trunk/llvmlab/llvmlab/ui/templates/layout.html
zorg/trunk/llvmlab/setup.py
Modified: zorg/trunk/llvmlab/llvmlab/TODO.txt
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/TODO.txt?rev=125855&r1=125854&r2=125855&view=diff
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/TODO.txt (original)
+++ zorg/trunk/llvmlab/llvmlab/TODO.txt Fri Feb 18 10:40:24 2011
@@ -5,8 +5,6 @@
Go-Live Requirements
====================
- - Config Logic
-
- User Login
o Expect superset of committer list.
Added: zorg/trunk/llvmlab/llvmlab/llvmlabtool/__init__.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/llvmlabtool/__init__.py?rev=125855&view=auto
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/llvmlabtool/__init__.py (added)
+++ zorg/trunk/llvmlab/llvmlab/llvmlabtool/__init__.py Fri Feb 18 10:40:24 2011
@@ -0,0 +1,3 @@
+__all__ = ['main']
+
+from main import main
Added: zorg/trunk/llvmlab/llvmlab/llvmlabtool/lab.cfg.sample
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/llvmlabtool/lab.cfg.sample?rev=125855&view=auto
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/llvmlabtool/lab.cfg.sample (added)
+++ zorg/trunk/llvmlab/llvmlab/llvmlabtool/lab.cfg.sample Fri Feb 18 10:40:24 2011
@@ -0,0 +1,20 @@
+# -*- Python -*-
+
+"""
+LLVM Lab Configuration File
+"""
+
+# Server administrator information.
+ADMIN_LOGIN = %(admin_login)r
+ADMIN_PASSHASH = %(admin_passhash)r
+ADMIN_NAME = %(admin_name)r
+ADMIN_EMAIL = %(admin_email)r
+
+# Should server run in debug mode?
+DEBUG = %(debug_server)r
+
+# Secret key for this server instance.
+SECRET_KEY = %(secret_key)r
+
+# Path to the managed data file.
+DATA_PATH = %(data_path)r
Added: zorg/trunk/llvmlab/llvmlab/llvmlabtool/main.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/llvmlabtool/main.py?rev=125855&view=auto
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/llvmlabtool/main.py (added)
+++ zorg/trunk/llvmlab/llvmlab/llvmlabtool/main.py Fri Feb 18 10:40:24 2011
@@ -0,0 +1,110 @@
+"""Implements the command line 'llvmlab' tool."""
+
+import hashlib
+import os
+import random
+import shutil
+import sys
+
+import flask
+
+def action_create(name, args):
+ """create an llvmlab installation"""
+
+ import llvmlab
+ from optparse import OptionParser, OptionGroup
+ parser = OptionParser("%%prog %s [options] <path>" % name)
+ parser.add_option("-f", "--force", dest="force", action="store_true",
+ help="overwrite existing files")
+
+ group = OptionGroup(parser, "CONFIG OPTIONS")
+ group.add_option("", "--admin-login", dest="admin_login",
+ help="administrator login [%default]", default='admin')
+ group.add_option("", "--admin-name", dest="admin_name",
+ help="administrator name [%default]",
+ default='Administrator')
+ group.add_option("", "--admin-password", dest="admin_password",
+ help="administrator password [%default]", default='admin')
+ group.add_option("", "--admin-email", dest="admin_email",
+ help="administrator email [%default]",
+ default='admin at example.com')
+
+ group.add_option("", "--debug-server", dest="debug_server",
+ help="run server in debug mode [%default]",
+ action="store_true", default=False)
+ parser.add_option_group(group)
+
+ (opts, args) = parser.parse_args(args)
+
+ if len(args) != 1:
+ parser.error("invalid number of arguments")
+
+ basepath, = args
+ basepath = os.path.abspath(basepath)
+ cfg_path = os.path.join(basepath, 'lab.cfg')
+ data_path = os.path.join(basepath, 'lab-data.json')
+
+ if not os.path.exists(basepath):
+ try:
+ os.mkdir(basepath)
+ except:
+ parser.error("unable to create directory: %r" % basepath)
+ elif not os.path.isdir(basepath):
+ parser.error("%r exists but is not a directory" % basepath)
+
+ if not opts.force:
+ if os.path.exists(cfg_path):
+ parser.error("%r exists (use --force to override)" % cfg_path)
+ if os.path.exists(data_path):
+ parser.error("%r exists (use --force to override)" % data_path)
+
+ # Construct the config file.
+ sample_cfg_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
+ "lab.cfg.sample")
+ sample_cfg_file = open(sample_cfg_path, "rb")
+ sample_cfg_data = sample_cfg_file.read()
+ sample_cfg_file.close()
+
+ # Fill in the sample config.
+ secret_key = hashlib.sha1(str(random.getrandbits(256))).hexdigest()
+ cfg_options = dict(opts.__dict__)
+ cfg_options['admin_passhash'] = hashlib.sha256(
+ opts.admin_password + secret_key).hexdigest()
+ cfg_options['secret_key'] = secret_key
+ cfg_options['data_path'] = data_path
+ cfg_data = sample_cfg_data % cfg_options
+
+ # Write the initial config file.
+ cfg_file = open(cfg_path, 'w')
+ cfg_file.write(cfg_data)
+ cfg_file.close()
+
+ # Write the initial (empty) data file.
+ data_file = open(data_path, 'w')
+ flask.json.dump({}, data_file, indent=2)
+ print >>data_file
+ data_file.close()
+
+###
+
+commands = dict((name[7:], f) for name,f in locals().items()
+ if name.startswith('action_'))
+
+def usage():
+ print >>sys.stderr, "Usage: %s command [options]" % (
+ os.path.basename(sys.argv[0]))
+ print >>sys.stderr
+ print >>sys.stderr, "Available commands:"
+ cmds_width = max(map(len, commands))
+ for name,func in sorted(commands.items()):
+ print >>sys.stderr, " %-*s - %s" % (cmds_width, name, func.__doc__)
+ sys.exit(1)
+
+def main():
+ import sys
+
+ if len(sys.argv) < 2 or sys.argv[1] not in commands:
+ usage()
+
+ cmd = sys.argv[1]
+ commands[cmd](cmd, sys.argv[2:])
Modified: zorg/trunk/llvmlab/llvmlab/ui/app.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/ui/app.py?rev=125855&r1=125854&r2=125855&view=diff
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/app.py (original)
+++ zorg/trunk/llvmlab/llvmlab/ui/app.py Fri Feb 18 10:40:24 2011
@@ -1,9 +1,14 @@
+import os
+
import flask
from flask import redirect, render_template, url_for
# Construct the Flask application.
app = flask.Flask(__name__)
+# Load the configuration file.
+app.config.from_envvar("LLVMLAB_CONFIG")
+
@app.route('/')
def index():
return render_template("index.html")
@@ -13,5 +18,5 @@
return redirect(url_for('static', filename='favicon.ico'))
if __name__ == '__main__':
- app.debug = True
+ app.debug = app.config['DEBUG']
app.run()
Modified: zorg/trunk/llvmlab/llvmlab/ui/templates/layout.html
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/ui/templates/layout.html?rev=125855&r1=125854&r2=125855&view=diff
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/templates/layout.html (original)
+++ zorg/trunk/llvmlab/llvmlab/ui/templates/layout.html Fri Feb 18 10:40:24 2011
@@ -15,7 +15,11 @@
<div class="body">{% block body %}{% endblock %}</div>
<div class="footer">
<a href="{{ url_for('index') }}">{#
- #}lab.llvm.org</a>
+ #}lab.llvm.org</a><br>
+ <i>Administered by <a href="mailto:{{
+ config['ADMIN_EMAIL'] }}">{{
+ config['ADMIN_NAME'] }} <{{
+ config['ADMIN_EMAIL'] }}></a>
</div>
</body>
</html>
Modified: zorg/trunk/llvmlab/setup.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/setup.py?rev=125855&r1=125854&r2=125855&view=diff
==============================================================================
--- zorg/trunk/llvmlab/setup.py (original)
+++ zorg/trunk/llvmlab/setup.py Fri Feb 18 10:40:24 2011
@@ -35,8 +35,11 @@
],
zip_safe = False,
-
packages = find_packages(),
-
+ entry_points = {
+ 'console_scripts': [
+ 'llvmlab = llvmlab.llvmlabtool:main',
+ ],
+ },
install_requires=['Flask'],
)
More information about the llvm-commits
mailing list