-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskmanager.py
82 lines (67 loc) · 1.82 KB
/
taskmanager.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import sys
#from jobs.mysql import MysqlJob
import getopt
from tasks.util import bcolors
def usage():
print 'Deploy Help'
print ''
print '-s, --source Use source to define a source file'
def importTask(module,klass):
mod = __import__(module, fromlist=[klass])
klass = getattr(mod, klass)
return klass
def getVarFromFile(filename):
import imp
f = open(filename)
global settings
settings = imp.load_source('settings', '', f)
f.close()
def checkOpt(argv):
print 'Deploying....'
opts, args = getopt.getopt(argv, "s:a:", ["source","action"])
global source
source = ''
action = ''
for o, a in opts:
if o == "-s":
source = a
elif o == "-a":
action = a
if ( source == '' ):
print 'You must define at least a source file'
return False
if ( action == 'install' ):
install()
elif ( action == 'uninstall' ):
uninstall()
elif ( action == 'status' ):
status()
elif ( action == '' ):
print 'No action has been defined'
return False
def uninstall():
getVarFromFile(source)
for task in settings.tasks:
x = task.rfind(".")
klass = task[x+1:]
module = task[:-len(task)+x]
aTask = importTask(module,klass)(settings)
aTask.uninstall()
def status():
return False
def install():
getVarFromFile(source)
print ''
print 'Setting mode: ' + bcolors.WARNING + settings.mode.upper() + bcolors.ENDC
print ''
for task in settings.tasks:
x = task.rfind(".")
klass = task[x+1:]
module = task[:-len(task)+x]
aTask = importTask(module,klass)(settings)
aTask.install()
def main(argv):
print 'Running JobManager'
checkOpt(argv)
if __name__ == "__main__":
main(sys.argv[1:])