-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (55 loc) · 1.8 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
65
66
import logging
import os
import re
import sys
import wsgiref.handlers
from google.appengine.ext import webapp
# use zipped gaeo
try:
import os
if os.path.exists("gaeo.zip"):
import sys
sys.path.insert(0, 'gaeo.zip')
except:
print "use normal gaeo folder"
import gaeo
from gaeo.dispatch import router
def initRoutes():
r = router.Router()
r.connect('/:countrycode', controller='proxy', action='proxy')
r.connect('/:controller/:action/:id')
r.root(controller='proxy', action='proxy')
def initPlugins():
"""
Initialize the installed plugins
"""
plugins_root = os.path.join(os.path.dirname(__file__), 'plugins')
if os.path.exists(plugins_root):
plugins = os.listdir(plugins_root)
for plugin in plugins:
if not re.match('^__|^\.', plugin):
try:
exec('from plugins import %s' % plugin)
except ImportError:
logging.error('Unable to import %s' % (plugin))
except SyntaxError:
logging.error('Unable to import name %s' % (plugin))
def main():
# add the project's directory to the import path list.
sys.path.append(os.path.dirname(__file__))
sys.path.append(os.path.join(os.path.dirname(__file__), 'application'))
# get the gaeo's config (singleton)
config = gaeo.Config()
# setup the templates' location
config.template_dir = os.path.join(
os.path.dirname(__file__), 'application', 'templates')
initRoutes()
# initialize the installed plugins
initPlugins()
app = webapp.WSGIApplication([
(r'.*', gaeo.MainHandler),
], debug=True)
logging.getLogger().setLevel(logging.DEBUG)
wsgiref.handlers.CGIHandler().run(app)
if __name__ == '__main__':
main()