[llvm-commits] [zorg] r125865 - /zorg/trunk/llvmlab/llvmlab/ui/app.py

Daniel Dunbar daniel at zuster.org
Fri Feb 18 08:40:53 PST 2011


Author: ddunbar
Date: Fri Feb 18 10:40:53 2011
New Revision: 125865

URL: http://llvm.org/viewvc/llvm-project?rev=125865&view=rev
Log:
llvmlab: Move more logic into App class.

Modified:
    zorg/trunk/llvmlab/llvmlab/ui/app.py

Modified: zorg/trunk/llvmlab/llvmlab/ui/app.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/ui/app.py?rev=125865&r1=125864&r2=125865&view=diff
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/app.py (original)
+++ zorg/trunk/llvmlab/llvmlab/ui/app.py Fri Feb 18 10:40:53 2011
@@ -7,19 +7,38 @@
 import llvmlab.user
 import llvmlab.ui.views
 
-class LLVMLabApp(flask.Flask):
+class App(flask.Flask):
+    @staticmethod
+    def create_standalone():
+        # Construct the application.
+        app = App(__name__)
+
+        # Load the application configuration.
+        app.load_config()
+
+        # Load the database.
+        app.load_data()
+
+        # Load the application routes.
+        app.register_module(llvmlab.ui.views.ui)
+
+        return app
+
     def __init__(self, name):
-        super(LLVMLabApp, self).__init__(name)
+        super(App, self).__init__(name)
 
     def load_config(self):
         # Load the configuration file.
-        app.config.from_envvar("LLVMLAB_CONFIG")
+        self.config.from_envvar("LLVMLAB_CONFIG")
 
         # Set the application secret key.
-        app.secret_key = app.config["SECRET_KEY"]
+        self.secret_key = self.config["SECRET_KEY"]
+
+        # Set the debug mode.
+        self.debug = self.config["DEBUG"]
 
     def load_data(self):
-        data_path = app.config["DATA_PATH"]
+        data_path = self.config["DATA_PATH"]
         data_file = open(data_path, "rb")
         data_object = flask.json.load(data_file)
         data_file.close()
@@ -29,35 +48,19 @@
 
         # Set the admin pseudo-user.
         data.set_admin_user(llvmlab.user.User(
-                id = app.config['ADMIN_LOGIN'],
-                passhash = app.config['ADMIN_PASSHASH'],
-                name = app.config['ADMIN_NAME'],
-                email = app.config['ADMIN_EMAIL']))
+                id = self.config['ADMIN_LOGIN'],
+                passhash = self.config['ADMIN_PASSHASH'],
+                name = self.config['ADMIN_NAME'],
+                email = self.config['ADMIN_EMAIL']))
 
         self.config.data = data
 
     def authenticate_login(self, username, password):
         passhash = hashlib.sha256(
-            password + app.config["SECRET_KEY"]).hexdigest()
-        user = app.config.data.users.get(username)
+            password + self.config["SECRET_KEY"]).hexdigest()
+        user = self.config.data.users.get(username)
         return user and passhash == user.passhash
 
-###
-
-# Construct the Flask application.
-app = LLVMLabApp(__name__)
-
-# Load the application configuration.
-app.load_config()
-
-# Load the LLVM-Lab database.
-app.load_data()
-
-# Load the application routes.
-app.register_module(llvmlab.ui.views.ui)
-
-###
-
 if __name__ == '__main__':
-    app.debug = app.config['DEBUG']
+    app = App.create_standalone()
     app.run()





More information about the llvm-commits mailing list