1+ # pylint: disable=wrong-import-order
2+ from ._version import __version__
3+
14import os
2- import subprocess
35from datetime import datetime
6+
7+ import structlog
8+ from csh_ldap import CSHLDAP
49from flask import Flask , redirect , request , render_template , g
5- from flask_sqlalchemy import SQLAlchemy
610from flask_migrate import Migrate
7- from csh_ldap import CSHLDAP
8- from raven import fetch_git_sha
11+ from flask_sqlalchemy import SQLAlchemy
912from raven .contrib .flask import Sentry
10- from raven . exceptions import InvalidGitRepository
11- import structlog
13+
14+ from conditional import config
1215
1316app = Flask (__name__ )
1417
15- config = os .path .join (app .config .get ('ROOT_DIR' , os .getcwd ()), "config.py" )
18+ app .config .from_object (config )
19+ if os .path .exists (os .path .join (os .getcwd (), "config.py" )):
20+ app .config .from_pyfile (os .path .join (os .getcwd (), "config.py" ))
1621
17- app .config .from_pyfile (config )
1822app .config ["SQLALCHEMY_TRACK_MODIFICATIONS" ] = False
1923
20- app .config ["GIT_REVISION" ] = subprocess .check_output (['git' ,
21- 'rev-parse' ,
22- '--short' ,
23- 'HEAD' ]).decode ('utf-8' ).rstrip ()
24-
25-
2624db = SQLAlchemy (app )
2725migrate = Migrate (app , db )
2826sentry = Sentry (app )
3129 app .config ['LDAP_BIND_PW' ],
3230 ro = app .config ['LDAP_RO' ])
3331
32+
3433def start_of_year ():
3534 start = datetime (datetime .today ().year , 6 , 1 )
3635 if datetime .today () < start :
37- start = datetime (datetime .today ().year - 1 , 6 , 1 )
36+ start = datetime (datetime .today ().year - 1 , 6 , 1 )
3837 return start
3938
39+
4040# pylint: disable=C0413
41- from conditional .models .models import UserLog
41+ from .models .models import UserLog
42+
4243
4344# Configure Logging
44- def request_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
45+ def request_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
4546 if 'request' in event_dict :
4647 flask_request = event_dict ['request' ]
4748 event_dict ['user' ] = flask_request .headers .get ("x-webauth-user" )
@@ -52,7 +53,7 @@ def request_processor(logger, log_method, event_dict): # pylint: disable=unused-
5253 return event_dict
5354
5455
55- def database_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
56+ def database_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
5657 if 'request' in event_dict :
5758 if event_dict ['method' ] != 'GET' :
5859 log = UserLog (
@@ -62,35 +63,35 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unused
6263 blueprint = event_dict ['blueprint' ],
6364 path = event_dict ['path' ],
6465 description = event_dict ['event' ]
65- )
66+ )
6667 db .session .add (log )
6768 db .session .flush ()
6869 db .session .commit ()
6970 del event_dict ['request' ]
7071 return event_dict
7172
73+
7274structlog .configure (processors = [
7375 request_processor ,
7476 database_processor ,
7577 structlog .processors .KeyValueRenderer ()
76- ])
78+ ])
7779
7880logger = structlog .get_logger ()
7981
80-
81- from conditional .blueprints .dashboard import dashboard_bp # pylint: disable=ungrouped-imports
82- from conditional .blueprints .attendance import attendance_bp
83- from conditional .blueprints .major_project_submission import major_project_bp
84- from conditional .blueprints .intro_evals import intro_evals_bp
85- from conditional .blueprints .intro_evals_form import intro_evals_form_bp
86- from conditional .blueprints .housing import housing_bp
87- from conditional .blueprints .spring_evals import spring_evals_bp
88- from conditional .blueprints .conditional import conditionals_bp
89- from conditional .blueprints .member_management import member_management_bp
90- from conditional .blueprints .slideshow import slideshow_bp
91- from conditional .blueprints .cache_management import cache_bp
92- from conditional .blueprints .co_op import co_op_bp
93- from conditional .blueprints .logs import log_bp
82+ from .blueprints .dashboard import dashboard_bp # pylint: disable=ungrouped-imports
83+ from .blueprints .attendance import attendance_bp
84+ from .blueprints .major_project_submission import major_project_bp
85+ from .blueprints .intro_evals import intro_evals_bp
86+ from .blueprints .intro_evals_form import intro_evals_form_bp
87+ from .blueprints .housing import housing_bp
88+ from .blueprints .spring_evals import spring_evals_bp
89+ from .blueprints .conditional import conditionals_bp
90+ from .blueprints .member_management import member_management_bp
91+ from .blueprints .slideshow import slideshow_bp
92+ from .blueprints .cache_management import cache_bp
93+ from .blueprints .co_op import co_op_bp
94+ from .blueprints .logs import log_bp
9495
9596app .register_blueprint (dashboard_bp )
9697app .register_blueprint (attendance_bp )
@@ -106,7 +107,8 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unused
106107app .register_blueprint (co_op_bp )
107108app .register_blueprint (log_bp )
108109
109- from conditional .util .ldap import ldap_get_member
110+ from .util .ldap import ldap_get_member
111+
110112
111113@app .route ('/<path:path>' )
112114def static_proxy (path ):
@@ -118,6 +120,7 @@ def static_proxy(path):
118120def default_route ():
119121 return redirect ('/dashboard' )
120122
123+
121124@app .errorhandler (404 )
122125@app .errorhandler (500 )
123126def route_errors (error ):
@@ -149,15 +152,17 @@ def route_errors(error):
149152 error_desc = type (error ).__name__
150153
151154 return render_template ('errors.html' ,
152- error = error_desc ,
153- error_code = code ,
154- event_id = g .sentry_event_id ,
155- public_dsn = sentry .client .get_public_dsn ('https' ),
156- ** data ), int (code )
155+ error = error_desc ,
156+ error_code = code ,
157+ event_id = g .sentry_event_id ,
158+ public_dsn = sentry .client .get_public_dsn ('https' ),
159+ ** data ), int (code )
160+
157161
158162@app .cli .command ()
159163def zoo ():
160164 from conditional .models .migrate import free_the_zoo
161165 free_the_zoo (app .config ['ZOO_DATABASE_URI' ])
162166
167+
163168logger .info ('conditional started' )
0 commit comments