This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
64 lines (52 loc) · 2.13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import logging
from camelot.core.conf import settings, SimpleSettings
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('main')
# begin custom settings
NO_CONF_ACK = [False]
class MySettings(SimpleSettings):
def ENGINE(self):
import os
from sqlalchemy import create_engine
user_pw = os.environ.get("GRADEBOOK_USER_PW")
if user_pw is None:
db_file_name = os.environ.get("GRADEBOOK_DATABASE")
if db_file_name is None:
db_file_name = "gradebook-default.sqlite"
if not NO_CONF_ACK[0]:
print "-"*75
print "No configuration detected"
print "-"*75
print "Neither GRADEBOOK_USER_PW nor GRADEBOOK_DATABASE"
print "was found as an environment variable. I'll run with"
print " a default database of '%s'." % db_file_name
print "-"*75
print "Hint [Enter] if that sounds good, and Ctrl-C[Enter] "\
"if you'd like to stop."
raw_input()
NO_CONF_ACK[0] = True
return create_engine('sqlite:///'+db_file_name)
else:
return create_engine('postgresql://%s@127.0.0.1:5432/grades' % user_pw)
def setup_model(self):
from camelot.core.sql import metadata
from sqlalchemy.orm import configure_mappers
import camelot.model.authentication
import camelot.model.i18n
import camelot.model.memento # noqa
import gradebook.model # noqa
metadata.bind = self.ENGINE()
configure_mappers()
metadata.create_all()
# ugh, breaks stuff
#from camelot.core.sql import update_database_from_model
#update_database_from_model()
my_settings = MySettings('My University', 'Grade book')
settings.append(my_settings)
# end custom settings
def start_application():
from camelot.view.main import main
from gradebook.application_admin import MyApplicationAdmin
main(MyApplicationAdmin())
if __name__ == '__main__':
start_application()