def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-d", "--debug", dest="debug", action="store_true", default=False, help="Run server in debug mode (autoreload)") parser.add_option("-f", "--config-file", dest="config", default=config.CONFIG_FILE_PATH, help="Path to configuration file", metavar="FILE") import logging logging.basicConfig(level=logging.DEBUG) log = logging.getLogger('tserver') (opt, args) = parser.parse_args() log.debug(opt) log.debug(args) if exists(opt.config): log.info('Using config file "%s"', normpath(opt.config)) read_config_file(opt.config) if(opt.debug): log.info('Debug mode enabled') from sps.utils.autoreload_eventlet import autoreload try: autoreload() except: exit(0) try: log.info('Starting transaction server on port %d' % config.TRANSACTION_SERVER_PORT) transaction_server = TransactionServer(('0.0.0.0', config.TRANSACTION_SERVER_PORT)) transaction_server.start() except KeyboardInterrupt: print >> sys.stderr, '\nInterrupted' exit(0) except Exception as e: log.error(e) exit(1)
from flask import Flask, request, render_template, abort, session, redirect, url_for import logging from os.path import dirname, abspath, join, normpath, exists from sps.config import config, read_config_file from lxml import objectify # Setup logging logging.basicConfig(level=logging.DEBUG) log = logging.getLogger('web') # Load optional config file config_file = join(abspath(dirname(__file__)), '..', '..', 'config.py') if exists(config_file): log.info('Using config file "%s"', normpath(config_file)) read_config_file(config_file) import transaction_interface import command_forms app = Flask(__name__) app.secret_key = '\x1dO\xdf\xf8\x82)\xe3\t\xf8ZmXD\xff\xbck\xa4\xfaH\xa7\x80EM\xfa' @app.route("/") def home(): if 'username' not in session: return redirect(url_for('login')) return render_template('form.html', form=command_forms, user=session['username']) @app.route("/login", methods=['GET', 'POST']) def login():