-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathClientJob.py
More file actions
executable file
·196 lines (158 loc) · 6.26 KB
/
Copy pathClientJob.py
File metadata and controls
executable file
·196 lines (158 loc) · 6.26 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import socket, base64, time, sys, subprocess
import os
import hashlib
from Crypto.PublicKey import RSA
from Crypto import Random
def importKey():
mainPath=os.path.dirname(os.path.abspath( __file__ ))
file=open(mainPath + "/my",'r')
st = "".join(file.readlines())
key = RSA.importKey(st)
#print "KEY Opened" , key
return key
def sign(owner,scm,msg):
b = (owner + scm + msg).encode('utf-8')
key = (importKey().encrypt(b, "")[0])
return base64.encodebytes(key).decode("utf8")
def createGetBranchs(workdir, scm, owner,options=None):
sec= sign(owner,scm,"LIST-BRNACHS")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n' % (owner, "LIST-BRNACHS", sec, scm)
f += '<workdir>%s</workdir>' % workdir
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
# Provide id, owner and command as string
# inputsFiles as List of file path
def createCloneMessage(owner, repo, workdir, key, scm, options=None):
sec = sign(owner, scm, "CLONE")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n'%( owner,"CLONE",sec,scm)
f += '<workdir>%s</workdir>'%workdir
f += '<repo>%s</repo>'%repo
f += '<sshkey>%s</sshkey>'%key
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
def createPullMessage(owner,workdir,key, scm, options=None):
sec = sign(owner, scm, "PULL")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n'%( owner,"PULL",sec,scm)
f += '<workdir>%s</workdir>'%workdir
#f += '<repo>%s</repo>'%repo
f += '<sshkey>%s</sshkey>'%key
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
def createListTagsMessage(owner, workdir,key, scm, options=None):
sec = sign(owner, scm, "LIST-TAGS")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n'%( owner,"LIST-TAGS",sec,scm)
f += '<workdir>%s</workdir>'%workdir
f += '<sshkey>%s</sshkey>'%key
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
def createSwitchTagMessage(owner, workdir, scm, tag, options=None):
sec = sign(owner, scm, "SWITCH-TAG")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n'%( owner,"SWITCH-TAG",sec,scm)
f += '<workdir>%s</workdir>'%workdir
f += '<tag>%s</tag>'%tag
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
def createDeployMessage(owner, workdir, scm, configFile, options=None):
sec = sign(owner, scm, "DEPLOY")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n'%( owner,"DEPLOY",sec,scm)
f += '<workdir>%s</workdir>'%workdir
f += '<configFile>%s</configFile>'%configFile
print(configFile)
conf=open(str(configFile)).read()
f += '<file>%s</file>'%(base64.encodestring(conf))
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
def createIntegrateMessage(jobID,owner, workdir, scm, configFile, options=None):
sec = sign(owner, scm, "INTEGRATE")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n'%(owner,"INTEGRATE",sec,scm)
f += '<jobID>%s</jobID>'%jobID
f += '<workdir>%s</workdir>'%workdir
f += '<configFile>%s</configFile>'%str(configFile)
conf=open(configFile).read()
f += '<file>%s</file>'%(conf)
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
def createListCommitsMessage(owner, workdir, key, scm, options=None):
sec = sign(owner, scm, "LIST-COMMITS")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n'%( owner,"LIST-COMMITS",sec,scm)
f += '<workdir>%s</workdir>'%workdir
f += '<sshkey>%s</sshkey>'%key
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
def createSwitchCommitMessage(owner, workdir, commit,scm, options=None):
sec = sign(owner, scm, "SWITCH-COMMIT")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n'%( owner,"SWITCH-COMMIT",sec,scm)
f += '<workdir>%s</workdir>'%workdir
f += '<commit>%s</commit>'%commit
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
def creategetCommitsDiffMessage(owner, workdir, commit, scm,options=None):
print(owner,workdir,commit,scm)
sec = sign(owner, scm, "DIFF-COMMIT")
#sec=base64.encodestring(importKey().encrypt(owner+scm+"DIFF-COMMIT","")[0])
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n'%( owner,"DIFF-COMMIT",sec,scm)
f += '<workdir>%s</workdir>'%workdir
f += '<commit>%s</commit>'%commit
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f
def createGetChangeLog(owner,workdir,scm,options=None):
sec = sign(owner, scm, "LIST-CHANGES")
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n' % (owner, "LIST-CHANGES", sec, scm)
f += '<workdir>%s</workdir>' % workdir
if options:
f += '<options>'
for option in list(options.keys()):
f += "<option name='%s'>%s</option>" % (option, options[option])
f += "</options>"
f += '</job>'
return f