3 # Copyright (C) 2013 Ipsilon project Contributors, for license see COPYING
6 sys.stdout = sys.stderr
11 from ipsilon import find_config
12 from ipsilon.util.data import AdminStore
13 from ipsilon.util import page
14 from ipsilon.root import Root
15 from jinja2 import Environment, FileSystemLoader, ChoiceLoader
16 import ipsilon.util.sessions
19 def nuke_session_locks():
20 if cherrypy.config['tools.sessions.on']:
22 sessdir = cherrypy.config['tools.sessions.storage_path']
23 for l in glob.glob(os.path.join(sessdir, '*.lock')):
26 except Exception: # pylint: disable=broad-except
28 except Exception: # pylint: disable=broad-except
31 cfgfile = find_config()
33 cherrypy.lib.sessions.SqlSession = ipsilon.util.sessions.SqlSession
34 cherrypy.config.update(cfgfile)
36 # Force cherrypy logging to work. Note that this ignores the config-file
38 cherrypy.log.screen = True
42 datastore = AdminStore()
43 admin_config = datastore.load_config()
44 for option in admin_config:
45 cherrypy.config[option] = admin_config[option]
48 default_template_dir = 'templates'
49 template_dir = cherrypy.config.get('template_dir', default_template_dir)
50 if template_dir.startswith('/'):
51 template_loaders.append(FileSystemLoader(template_dir))
53 template_loaders.append(FileSystemLoader(
54 os.path.join(cherrypy.config['base.dir'],
56 # Fall-back to the default templates
57 template_loaders.append(FileSystemLoader(
58 os.path.join(cherrypy.config['base.dir'],
59 default_template_dir)))
60 template_env = Environment(loader=ChoiceLoader(template_loaders),
62 extensions=['jinja2.ext.autoescape'])
64 if __name__ == "__main__":
65 conf = {'/': {'tools.staticdir.root': os.getcwd()},
66 '/ui': {'tools.staticdir.on': True,
67 'tools.staticdir.dir': 'ui'},
68 '/cache': {'tools.staticdir.on': True,
69 'tools.staticdir.dir': 'cache'}}
70 cherrypy.quickstart(Root('default', template_env),
71 cherrypy.config['base.mount'], conf)
74 cherrypy.config['environment'] = 'embedded'
76 if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
77 cherrypy.engine.start(blocking=False)
78 atexit.register(cherrypy.engine.stop)
80 application = cherrypy.Application(Root('default', template_env),
81 script_name=None, config=None)