-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspatialcache.py
executable file
·66 lines (54 loc) · 1.41 KB
/
spatialcache.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
#!/usr/bin/env python
from logger import Logger
from config import Configuration
from server import CacheServer
from daemon import Daemon
from tiles import TilesManager
import pid
class SpatialCache(Daemon):
"""
Application main class
It has the responsibility to instantiate, initialize, and configure all
the application services/modules
"""
def __init__(self):
self.config = Configuration()
self.server = CacheServer()
self.tilesManager = TilesManager()
def configure(self, cfgfile):
self.config.load(cfgfile)
Logger().configure(self.config.logger)
self.tilesManager.configure(self.config.tiles)
self.server.configure(self.config.server)
if self.config.general.daemon:
Logger().info("Running as daemon")
self.daemonize()
def start(self):
pid.writePID()
self.server.start()
def stop(self):
self.server.stop()
if __name__ == '__main__':
from constants.general import CONFIGURATION_FILE, HELP_FILE, VERSION
import sys
# Import Psyco if available
try:
import psyco
psyco.full()
except ImportError:
pass
# TODO: Extract argument parsing method
cfgfile = CONFIGURATION_FILE
# Parse params
for i in range(len(sys.argv)):
if sys.argv[i] == "-c":
cfgfile = sys.argv[i+1]
elif sys.argv[i] == "-h":
print open(HELP_FILE).read()
sys.exit()
elif sys.argv[i] == "-v":
print VERSION
sys.exit()
cache = SpatialCache()
cache.configure(cfgfile)
cache.start()