MCPcopy Create free account
hub / github.com/Eyepea/API-Hour / Application

Class Application

api_hour/application.py:13–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12
13class Application(GunicornApp):
14 def init(self, parser, opts, args):
15 if len(args) < 1:
16 parser.error("No application module specified.")
17
18 self.cfg.set("default_proc_name", args[0])
19 self.app_uri = args[0]
20
21 logging.captureWarnings(True)
22 if opts.auto_config:
23 # Default config_dir
24 config_dir = os.path.join(self.cfg.chdir,
25 'etc',
26 self.app_uri.split(":", 1)[0])
27 if os.path.exists(config_dir):
28 self.cfg.set('config_dir', config_dir) # Define dev etc folder as default config directory
29
30 # generate config_dir directly: egg or chicken problem
31 if opts.config_dir:
32 self.cfg.set('config_dir', opts.config_dir)
33
34 if not opts.config:
35 opts.config = os.path.join(self.cfg.config_dir, 'api_hour/gunicorn_conf.py')
36
37 if not self.cfg.logconfig:
38 self.cfg.set('logconfig', os.path.join(self.cfg.config_dir, 'api_hour/logging.ini'))
39 else:
40 # To avoid with Gunicorn 19 that the console it's empty when you test
41 if not opts.errorlog:
42 opts.errorlog = '-'
43 if not opts.accesslog:
44 opts.accesslog = '-'
45
46 def load_default_config(self):
47 # init configuration
48 self.cfg = Config(self.usage, prog=self.prog)
49 self.cfg.set('worker_class', 'api_hour.Worker') # Define api_hour.Worker as default
50
51 def load_config(self):
52 # parse console args
53 super().load_config()
54 if self.cfg.config_dir:
55 self.config = get_config({'config_dir': self.cfg.config_dir})
56 else:
57 self.config = None
58 # import ipdb; ipdb.set_trace()
59
60 def chdir(self):
61 # chdir to the configured path before loading,
62 # default is the current dir
63 os.chdir(self.cfg.chdir)
64
65 # add the path to sys.path
66 sys.path.insert(0, self.cfg.chdir)
67
68 def load(self):
69 self.chdir()
70

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected