Mercurial > mamba
changeset 550:91e1a95343b2
Add option to inform CIA of new levels.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Tue, 20 Sep 2011 17:29:38 +0200 |
parents | f0a29c9d57ee |
children | 9d3ed4d05f55 |
files | mamba/forest.py |
diffstat | 1 files changed, 64 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/forest.py Sun Sep 18 20:58:34 2011 +0200 +++ b/mamba/forest.py Tue Sep 20 17:29:38 2011 +0200 @@ -4,11 +4,14 @@ from flask import Flask, request, abort from datetime import datetime +import xmlrpclib +import time import os import sys app = Flask(__name__) app.config['LEVEL_FOLDER'] = None # set later +app.config['CIA_PROJECT'] = None # set to activate CIA sending def path(ctype): @@ -54,14 +57,71 @@ leveldata = request.form['data'].encode('ascii') with open(levelpath, 'w') as level: level.write(leveldata) + inform_cia(levelname, "New level uploaded.", branch="uncurated") return "Ssss." else: abort(405, "Post levels here. Hsss.") +MAMBA_VERSION = "0.1" +MAMBA_URL = "https://ctpug.org.za/hg/mamba" +CIA_URL = "http://cia.navi.cx" +CIA_MSG_TEMPLATE = """ +<message + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="schema.xsd"> + <generator> + <name>Mutable Mamba Level Server</name> + <version>%(mamba_version)s</version> + <url>%(mamba_url)s</url> + </generator> + <source> + <project>%(project)s</project> + <module>%(module)s</module> + <branch>%(branch)s</branch> + </source> + <timestamp> + %(timestamp)d + </timestamp> + <body> + <commit> + <revision>%(revision)s</revision> + <author>%(author)s</author> + <files> + <file>%(file)s</file> + </files> + <log> + %(log)s + </log> + </commit> + </body> +</message> +""" + + +def inform_cia(filename, log, branch='uncurated'): + if app.config['CIA_PROJECT'] is None: + return + msg = CIA_MSG_TEMPLATE % { + 'mamba_version': MAMBA_VERSION, + 'mamba_url': MAMBA_URL, + 'project': app.config['CIA_PROJECT'], + 'module': 'level-server', + 'branch': branch, + 'timestamp': int(time.time()), + 'revision': '0', + 'author': 'unknown', + 'file': filename, + 'log': log, + } + srv = xmlrpclib.Server(CIA_URL) + srv.hub.deliver(msg) + + if __name__ == "__main__": - if len(sys.argv) != 3: - print "Usage: python -m mamba.forest <port> <level folder>" + if len(sys.argv) not in (3, 4): + print ("Usage: python -m mamba.forest <port> <level folder>" + " [<cia project>]") sys.exit(1) host = '0.0.0.0' @@ -74,7 +134,9 @@ if not os.path.isdir(folder): print "Level folder must be a folder." sys.exit(1) + cia_project = sys.argv[3] if len(sys.argv) > 3 else None app.config['LEVEL_FOLDER'] = level_folder + app.config['CIA_PROJECT'] = cia_project # app.debug = True app.run(host=host, port=port)