-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
68 lines (52 loc) · 1.79 KB
/
server.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
65
66
67
68
#!/usr/bin/python
import os;
import shutil;
import json;
import web;
#from collections import defaultdict;
#from config import *;
from urls import *;
from QuaintEgg.lib.Util import GenericUtil;
from QuaintEgg.lib.WebPyCustomizations import QuaintEggApplication;
from QuaintEgg.framework.controllers import Authentication;
application = None;
options = None;
if __name__ == "__main__":
p = QuaintEggApplication.getParser()
options = p.parse_args();
WEBCONFIG = {};
if not os.path.exists(options.config):
print "Configuration file does not exist";
else:
WEBCONFIG = json.load(open(options.config));
else:
WEBCONFIG = json.load(open("config.json"));
web.config.debug = False
app = QuaintEggApplication(urls, globals());
sessionDict = GenericUtil.getDefaultSessionDict();
for k,v in WEBCONFIG["defaultSessionVariables"].items():
sessionDict[k] = v;
session = web.session.Session(app, web.session.DiskStore(WEBCONFIG["sessionDir"]), initializer=sessionDict)
WEBCONFIG["session"] = session;
WEBCONFIG["defaultSessionVariables"] = sessionDict;
import __builtin__;
__builtin__.WEBCONFIG = WEBCONFIG;
sessionHook = QuaintEggApplication.SessionHook(session);
app.add_processor(web.loadhook(sessionHook.session_hook))
if __name__=="__main__":
if options.reset_tmp:
print "Resetting tmp directory...";
if os.path.exists(WEBCONFIG["tmpDir"]):
shutil.rmtree(WEBCONFIG["tmpDir"]);
if options.reset_db:
print "Resetting the database...";
if os.path.exists(WEBCONFIG["dbName"]):
os.remove(WEBCONFIG["dbName"]);
Authentication.setupDefaultDatabase(WEBCONFIG);
if not os.path.exists(WEBCONFIG["tmpDir"]):
os.mkdir(WEBCONFIG["tmpDir"]);
app.run(port=options.port, host=options.host);
else:
if not os.path.exists(WEBCONFIG["tmpDir"]):
os.mkdir(WEBCONFIG["tmpDir"]);
application = app.wsgifunc();