-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththor.py
executable file
·69 lines (60 loc) · 2.03 KB
/
thor.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/env python3
from defaults import *
from thor.routes import thorApp
import thor.const as const
import thor.util as util
import sys
import logging
import thor.frozendict as frozendict
import werkzeug.contrib.cache as cache
printTree = False
# Read arguments from command line
for argument in sys.argv:
if "--help" in argument or "-h" in argument:
util.printHelp(sys.argv[0])
sys.exit(1)
elif "--app-name=" in argument:
appName = argument.replace("--app-name", "")
elif "--debug" == argument:
logLevel = logging.DEBUG
elif "--netCDF-folder=" in argument:
ncFolder = argument.replace("--netCDF-folder=", "")
elif "--log-file=" in argument:
logFiles.append(argument.replace("--log-file=", ""))
elif "--print-tree" in argument:
printTree = True
elif "--disable-cache" in argument:
enableCache = False
# appName and subfolder to read netCDF files from
const.appName = appName
# Create a logger that outputs to console and supplied log-files
const.log = logging.getLogger(const.appName)
const.log.setLevel(logLevel)
consoleHandler = logging.StreamHandler()
consoleHandler.setLevel(logLevel)
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
consoleHandler.setFormatter(formatter)
const.log.addHandler(consoleHandler)
for logFile in logFiles:
fileHandler = logging.FileHandler(logFile)
fileHandler.setLevel(logLevel)
fileHandler.setFormatter(formatter)
const.log.addHandler(fileHandler)
# Load ncFiles
const.ncFolder = ncFolder
const.ncFiles = frozendict.FrozenDict(util.openFiles(ncFolder))
if printTree:
util.printTree(ncFolder)
# This defines valid arguments for API
const.apiMustArgs = apiMustArgs
const.apiOptionalArgs = apiOptionalArgs
# init cache
const.enableCache = enableCache
const.cacheMaxAge = cacheMaxAge
if const.enableCache:
const.thorCache = cache.MemcachedCache(['127.0.0.1:11211'])
# If running as main exec (i e not under uwsgi)
if __name__ == "__main__":
thorApp.run()