Workout With Friends Stay fit with a little motivation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Properties
__init__.py
Go to the documentation of this file.
1 import argparse
2 import sys
3 from wowf.config import settings
4 from wowf.lib.utils import Storage
5 from pyramid.paster import bootstrap, setup_logging
6
7
8 def make_main(Command):
9 def main(argv=None):
10 if argv is None:
11 argv = sys.argv
12 command = Command(argv)
13 sys.exit(command.run())
14 return main
15
16
17 class BaseCommand(object):
18
19 parser = argparse.ArgumentParser()
20 parser.add_argument('config_uri', action='store', help='Configuration file to use')
21
22 ##
23 #
24 # Setup the necessary environment to run the script.
25 #
26 def __init__(self, argv):
27 self.args = self.parser.parse_args(argv[1:])
28 setup_logging(self.args.config_uri)
29 try:
30 self.env = Storage(bootstrap(self.args.config_uri))
31 except Exception as e:
32 self.env = None
33 raise SystemExit(e)
34 self.env.request.host = settings.host
35 self.settings = settings
36
37 def __del__(self):
38 if self.env is not None:
39 self.env.closer()
40
41 def run(self):
42 raise NotImplementedError()
43