summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Wagner <bwagner@thoughtworks.com>2014-10-27 14:59:57 +0100
committerBruno Wagner <bwagner@thoughtworks.com>2014-10-27 15:00:08 +0100
commit5636572f391de8cbd37d6f7322fd279d241862bd (patch)
tree03ab0a744827c70ebae82d75fd435c51c0b1ce7b
parent28956f2657f518978f917a698c6d1e7e249dc050 (diff)
User agent won't hang anymore when registering user
-rw-r--r--service/pixelated/config/app_factory.py2
-rw-r--r--service/pixelated/config/reactor_manager.py7
-rw-r--r--service/pixelated/runserver.py67
3 files changed, 40 insertions, 36 deletions
diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py
index 38395325..735313b4 100644
--- a/service/pixelated/config/app_factory.py
+++ b/service/pixelated/config/app_factory.py
@@ -89,7 +89,7 @@ def init_leap_session(app):
return leap_session
-def create_app(debug_enabled, app):
+def create_app(app, debug_enabled):
with app.app_context():
leap_session = init_leap_session(app)
diff --git a/service/pixelated/config/reactor_manager.py b/service/pixelated/config/reactor_manager.py
index 813714a8..af140c5b 100644
--- a/service/pixelated/config/reactor_manager.py
+++ b/service/pixelated/config/reactor_manager.py
@@ -22,11 +22,6 @@ import logging
from twisted.internet import reactor
-def signal_handler(signal, frame):
- stop_reactor_on_exit()
- sys.exit(0)
-
-
def start_reactor(logging=False):
if logging:
enable_logging()
@@ -45,8 +40,6 @@ def stop_reactor_on_exit():
global REACTOR_THREAD
REACTOR_THREAD = None
-signal.signal(signal.SIGINT, signal_handler)
-
def enable_logging():
logging.basicConfig(level=logging.DEBUG,
diff --git a/service/pixelated/runserver.py b/service/pixelated/runserver.py
index 194c95c0..ac3dee94 100644
--- a/service/pixelated/runserver.py
+++ b/service/pixelated/runserver.py
@@ -15,57 +15,68 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import os
-import os.path
import logging
from flask import Flask
from leap.common.events import server as events_server
from pixelated.config import app_factory
import pixelated.config.args as input_args
-import pixelated.config.credentials_prompt as credentials_prompt
import pixelated.bitmask_libraries.register as leap_register
+from pixelated.bitmask_libraries.leap_srp import LeapAuthException
+import pixelated.config.credentials_prompt as credentials_prompt
import pixelated.config.reactor_manager as reactor_manager
import pixelated.support.ext_protobuf # monkey patch for protobuf in OSX
import pixelated.support.ext_sqlcipher # monkey patch for sqlcipher in debian
-from pixelated.bitmask_libraries.leap_srp import LeapAuthException
-from twisted.internet import error
app = Flask(__name__, static_url_path='', static_folder=app_factory.get_static_folder())
def setup():
- args = input_args.parse()
- app.config.update({'HOST': args.host, 'PORT': args.port})
+ try:
+ args = input_args.parse()
+ app.config.update({'HOST': args.host, 'PORT': args.port})
+
+ debugger = setup_debugger(args.debug)
+
+ if args.register:
+ register(*args.register[::-1])
+ else:
+ if args.dispatcher:
+ raise Exception('Dispatcher mode not implemented yet')
+ else:
+ configuration_setup(app, args.config)
+ start_services(app, debugger)
+ finally:
+ reactor_manager.stop_reactor_on_exit()
- debug_enabled = args.debug or os.environ.get('DEBUG', False)
+
+def register(username, server_name):
+ try:
+ leap_register.register_new_user(username, server_name)
+ except LeapAuthException:
+ print('User already exists')
+
+def setup_debugger(enabled):
+ debug_enabled = enabled or os.environ.get('DEBUG', False)
if not debug_enabled:
logging.basicConfig()
logger = logging.getLogger('werkzeug')
logger.setLevel(logging.INFO)
- reactor_manager.start_reactor(logging=debug_enabled)
- events_server.ensure_server(port=8090)
-
- if args.register:
- try:
- server_name, username = args.register
- leap_register.register_new_user(username, server_name)
- except LeapAuthException:
- print('User already exists')
- exit(1)
+def configuration_setup(app, config):
+ if config is not None:
+ config_file = os.path.abspath(os.path.expanduser(config))
+ app.config.from_pyfile(config_file)
else:
- if args.dispatcher:
- raise Exception('Dispatcher mode not implemented yet')
- elif args.config is not None:
- config_file = os.path.abspath(os.path.expanduser(args.config))
- app.config.from_pyfile(config_file)
- else:
- provider, user, password = credentials_prompt.run()
- app.config['LEAP_SERVER_NAME'] = provider
- app.config['LEAP_USERNAME'] = user
- app.config['LEAP_PASSWORD'] = password
+ provider, user, password = credentials_prompt.run()
+ app.config['LEAP_SERVER_NAME'] = provider
+ app.config['LEAP_USERNAME'] = user
+ app.config['LEAP_PASSWORD'] = password
- app_factory.create_app(debug_enabled, app)
+def start_services(app, debug):
+ reactor_manager.start_reactor(logging=debug)
+ events_server.ensure_server(port=8090)
+ app_factory.create_app(app, debug)
if __name__ == '__main__':