[llvm-commits] [zorg] r125863 - /zorg/trunk/llvmlab/llvmlab/ui/app.py
Daniel Dunbar
daniel at zuster.org
Fri Feb 18 08:40:48 PST 2011
Author: ddunbar
Date: Fri Feb 18 10:40:48 2011
New Revision: 125863
URL: http://llvm.org/viewvc/llvm-project?rev=125863&view=rev
Log:
llvmlab: Pull out an LLVMLabApp 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=125863&r1=125862&r2=125863&view=diff
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/app.py (original)
+++ zorg/trunk/llvmlab/llvmlab/ui/app.py Fri Feb 18 10:40:48 2011
@@ -7,47 +7,51 @@
import llvmlab.data
import llvmlab.user
-def load_llvmlab_data(app):
- """load_llvmlab_data(app) -> data.Data
-
- Load the LLVM-Lab data for the given application.
- """
-
- data_path = app.config["DATA_PATH"]
- data_file = open(data_path, "rb")
- data_object = flask.json.load(data_file)
- data_file.close()
-
- # Create the internal Data object.
- data = llvmlab.data.Data.fromdata(data_object)
-
- # 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']))
-
- return data
-
-def authenticate_login(username, password):
- passhash = hashlib.sha256(password + app.config["SECRET_KEY"]).hexdigest()
- user = app.config.data.users.get(username)
- return user and passhash == user.passhash
+class LLVMLabApp(flask.Flask):
+ def __init__(self, name):
+ super(LLVMLabApp, self).__init__(name)
+
+ def load_config(self):
+ # Load the configuration file.
+ app.config.from_envvar("LLVMLAB_CONFIG")
+
+ # Set the application secret key.
+ app.secret_key = app.config["SECRET_KEY"]
+
+ def load_data(self):
+ data_path = app.config["DATA_PATH"]
+ data_file = open(data_path, "rb")
+ data_object = flask.json.load(data_file)
+ data_file.close()
+
+ # Create the internal Data object.
+ data = llvmlab.data.Data.fromdata(data_object)
+
+ # 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']))
+
+ 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)
+ return user and passhash == user.passhash
###
# Construct the Flask application.
-app = flask.Flask(__name__)
-
-# Load the configuration file.
-app.config.from_envvar("LLVMLAB_CONFIG")
+app = LLVMLabApp(__name__)
-# Set the application secret key.
-app.secret_key = app.config["SECRET_KEY"]
+# Load the application configuration.
+app.load_config()
# Load the LLVM-Lab database.
-app.config.data = load_llvmlab_data(app)
+app.load_data()
###
# Routing
@@ -72,7 +76,7 @@
# Authenticate the user.
username = request.form['username']
- if not authenticate_login(username, request.form['password']):
+ if not app.authenticate_login(username, request.form['password']):
return render_template("login.html",
error="Invalid login")
More information about the llvm-commits
mailing list