blob: 72f0676a642739633370b99e243f4dd7a19224b1 (
plain)
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
|
# vim: set filencoding=utf8
"""
Kronos Command Line UI
@author: Mike Crute (mcrute@ag.com)
@organization: American Greetings Interactive
@date: February 05, 2010
"""
import sys
from optparse import OptionParser
from kronos.parser import parse_activity
from kronos.controllers import StartController, StopController
class CommandLineUI(object):
def __init__(self, args):
self.args = args
self.controllers = {
'start': StartController(),
'stop': StopController(),
}
def usage(self):
print "You're doin' it wrong."
raise SystemExit
def _parse_args(self):
self.action = self.args[1]
activity = ' '.join(self.args[2:])
self.activity = parse_activity(activity)
def run(self):
if len(self.args) < 2:
self.usage()
else:
self._parse_args()
controller = self.controllers.get(self.action)
if not controller:
self.usage()
controller(self.activity)
def main():
CommandLineUI(sys.argv[:]).run()
if __name__ == "__main__":
main()
|