root / trunk / extensions / ext3Dgui / buildman / bin / bmplugins / DepManCreatePlugIn.py @ 26254
History | View | Annotate | Download (10.6 KB)
1 |
#depman create plugin
|
---|---|
2 |
|
3 |
from bmbase.IPlugIn import IPlugIn |
4 |
from bmbase.PlugInManager import PlugInManager |
5 |
from bmcore.BMUtil import BMUtil |
6 |
from xml.dom import minidom |
7 |
import string |
8 |
import shutil |
9 |
import os |
10 |
import sys |
11 |
import subprocess |
12 |
|
13 |
class DepManCreatePlugIn(IPlugIn): |
14 |
|
15 |
def __init__(self): |
16 |
IPlugIn.__init__(self)
|
17 |
|
18 |
self._path="." |
19 |
self._group=""
|
20 |
self._artifact="" |
21 |
self._version="" |
22 |
self._platform="default" |
23 |
self._arch="default" |
24 |
self._compiler="default" |
25 |
self._ltype="" |
26 |
self._upload=False |
27 |
self._is_Interactive=True |
28 |
self._xmlfile = "" |
29 |
self._packageNode = None |
30 |
|
31 |
self._default_ssh="murray.ai2.upv.es" |
32 |
self._default_login="depman" |
33 |
self._default_destdir = "/projects/AI2/www-aliases/depman/" |
34 |
|
35 |
|
36 |
def init(self): |
37 |
self.addGoal("create", "Create an artifact") |
38 |
self.addGoalOption("create","--path", "Specifies source directory") |
39 |
self.addGoalOption("create","--group", "Specifies artifact group name") |
40 |
self.addGoalOption("create","--artifact", "Specifies artifact name") |
41 |
self.addGoalOption("create","--version", "Specifies artifact version") |
42 |
self.addGoalOption("create","--platform", "Specifies artifact OS platform") |
43 |
self.addGoalOption("create","--arch", "Specifies artifact hardware architecture") |
44 |
self.addGoalOption("create","--compiler", "Specifies artifact compiler version") |
45 |
self.addGoalOption("create","--ltype", "Specifies library type if needed") |
46 |
self.addGoalOption("create","--upload", "Whenever the artifact must be uploaded or not") |
47 |
self.addGoalOption("create","--from-xml", "Uses the given depman.xml file to create the package") |
48 |
|
49 |
isCreate = False
|
50 |
if self._arguments.read("create"): |
51 |
self.setExecute(True) |
52 |
isCreate = True
|
53 |
|
54 |
if not isCreate: |
55 |
return
|
56 |
|
57 |
args=[""]
|
58 |
use_xml=False
|
59 |
if self._arguments.read("--from-xml",args): |
60 |
self._xmlfile=args[0] |
61 |
use_xml=True
|
62 |
|
63 |
if use_xml:
|
64 |
self.loadXMLFile(self._xmlfile) |
65 |
|
66 |
|
67 |
args=[""]
|
68 |
if self._arguments.read("--path",args): |
69 |
self._path=args[0] |
70 |
|
71 |
args=[""]
|
72 |
if self._arguments.read("--group",args): |
73 |
self._group=args[0] |
74 |
self._is_Interactive=False |
75 |
|
76 |
args=[""]
|
77 |
if self._arguments.read("--artifact",args): |
78 |
self._artifact=args[0] |
79 |
self._is_Interactive=False |
80 |
|
81 |
args=[""]
|
82 |
if self._arguments.read("--version",args): |
83 |
self._version=args[0] |
84 |
self._is_Interactive=False |
85 |
|
86 |
|
87 |
args=[""]
|
88 |
if self._arguments.read("--platform",args): |
89 |
self._platform=args[0] |
90 |
self._is_Interactive=False |
91 |
|
92 |
args=[""]
|
93 |
if self._arguments.read("--arch",args): |
94 |
self._arch=args[0] |
95 |
self._is_Interactive=False |
96 |
|
97 |
args=[""]
|
98 |
if self._arguments.read("--compiler",args): |
99 |
self._compiler=args[0] |
100 |
self._is_Interactive=False |
101 |
|
102 |
args=[""]
|
103 |
if self._arguments.read("--ltype",args): |
104 |
self._ltype=args[0] |
105 |
self._is_Interactive=False |
106 |
|
107 |
if self._arguments.read("--upload"): |
108 |
self._upload=True |
109 |
|
110 |
|
111 |
def initFromXML(self,node): |
112 |
if node.localName == "create": |
113 |
if node.hasAttributes():
|
114 |
if node.attributes.has_key("from-xml"): |
115 |
self._xmlfile=node.attributes.get("from-xml").value |
116 |
self.loadXMLFile(self._xmlfile) |
117 |
if node.attributes.has_key("path"): |
118 |
self._path = node.attributes.get("path").value |
119 |
if node.attributes.has_key("upload"): |
120 |
value = node.attributes.get("upload").value
|
121 |
if value =="True" or value =="true": |
122 |
self._upload = True |
123 |
|
124 |
else:
|
125 |
if node.localName == "depman": |
126 |
self._packageNode = node
|
127 |
self._is_Interactive=False |
128 |
|
129 |
def execute(self): |
130 |
print "Executing Plugin:" + str(self.__class__) |
131 |
return self.create() |
132 |
|
133 |
def create(self): |
134 |
|
135 |
self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") |
136 |
if self._dmplugin == None: |
137 |
self.reportError("PlugIn `depman` not found") |
138 |
return False |
139 |
|
140 |
#user questions
|
141 |
if self._is_Interactive: |
142 |
self._group=raw_input("Group: ") |
143 |
|
144 |
self._artifact=raw_input("Artifact: ") |
145 |
|
146 |
self._version=raw_input("Version: ") |
147 |
|
148 |
tmpstr=""
|
149 |
for p in self._dmplugin.getSupportedPlatforms(): |
150 |
tmpstr=tmpstr+p+" "
|
151 |
print "( ",tmpstr,")" |
152 |
tmstr="Platform [*]:"
|
153 |
self._platform=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSPlatform())) |
154 |
if len(self._platform)==0: |
155 |
self._platform=self._dmplugin.getOSPlatform() |
156 |
|
157 |
tmpstr=""
|
158 |
for p in self._dmplugin.getSupportedCompilers(): |
159 |
tmpstr=tmpstr+p+" "
|
160 |
print "( ",tmpstr,")" |
161 |
tmstr="Compiler [*]:"
|
162 |
self._compiler=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSCompiler())) |
163 |
if len(self._compiler)==0: |
164 |
self._compiler=self._dmplugin.getOSCompiler() |
165 |
|
166 |
tmpstr=""
|
167 |
for p in self._dmplugin.getSupportedArchs(): |
168 |
tmpstr=tmpstr+p+" "
|
169 |
print "( ",tmpstr,")" |
170 |
tmstr="Architecture [*]:"
|
171 |
self._arch=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSArch())) |
172 |
if len(self._arch)==0: |
173 |
self._arch=self._dmplugin.getOSArch() |
174 |
|
175 |
tmpstr=""
|
176 |
for p in self._dmplugin.getSupportedLibraryTypes(): |
177 |
tmpstr=tmpstr+p+" "
|
178 |
print "( ",tmpstr,")" |
179 |
self._ltype=raw_input("Library Type: ") |
180 |
|
181 |
upload_response = raw_input("Upload to server? (y/n): ") |
182 |
if upload_response == "y" or upload_response == "yes": |
183 |
self._upload=True |
184 |
|
185 |
if self._packageNode != None: |
186 |
for n in self._packageNode.childNodes: |
187 |
if n.localName=="package": |
188 |
processPackage = True
|
189 |
if n.hasAttributes():
|
190 |
if n.attributes.has_key("platform"): |
191 |
values = n.attributes.get("platform").value.split(",") |
192 |
if self._dmplugin.getOSPlatform() in values: |
193 |
processPackage = True
|
194 |
else:
|
195 |
processPackage = False
|
196 |
if processPackage:
|
197 |
print "Processing for platform..." |
198 |
for p in n.childNodes: |
199 |
if p.localName=="group": |
200 |
self._group=p.childNodes[0].nodeValue |
201 |
if p.localName=="artifact": |
202 |
self._artifact=p.childNodes[0].nodeValue |
203 |
if p.localName=="version": |
204 |
self._version=p.childNodes[0].nodeValue |
205 |
if p.localName=="platform": |
206 |
self._platform=p.childNodes[0].nodeValue |
207 |
if p.localName=="compiler": |
208 |
self._compiler=p.childNodes[0].nodeValue |
209 |
if p.localName=="arch": |
210 |
self._arch=p.childNodes[0].nodeValue |
211 |
if p.localName=="libraryType": |
212 |
self._ltype=p.childNodes[0].nodeValue |
213 |
|
214 |
if p.localName =="upload": |
215 |
#TODO: Maybe upload should be an external plugin
|
216 |
for k in p.childNodes: |
217 |
if k.localName == "sshserver": |
218 |
self._default_ssh = k.childNodes[0].nodeValue |
219 |
if k.localName == "destdir": |
220 |
self._default_destdir = k.childNodes[0].nodeValue |
221 |
if k.localName == "username": |
222 |
self._default_login = k.childNodes[0].nodeValue |
223 |
|
224 |
if self._group == "": |
225 |
self.reportError("Group cannot be empty") |
226 |
return False |
227 |
if self._artifact == "": |
228 |
self.reportError("Artifact cannot be empty") |
229 |
return False |
230 |
if self._version == "": |
231 |
self.reportError("Version cannog be empty") |
232 |
return
|
233 |
self._group=self._group.replace(".","/") |
234 |
if self._platform=="default": |
235 |
self._platform=self._dmplugin.getOSPlatform() |
236 |
if self._compiler=="default": |
237 |
self._compiler=self._dmplugin.getOSCompiler() |
238 |
if self._arch=="default": |
239 |
self._arch=self._dmplugin.getOSArch() |
240 |
|
241 |
|
242 |
#let's check user input consistency
|
243 |
|
244 |
if self._platform not in self._dmplugin.getSupportedPlatforms(): |
245 |
self.reportError("Platform not supported: " + self._platform + ". Supported platforms:" + str(self._dmplugin.getSupportedPlatforms())) |
246 |
return False |
247 |
|
248 |
if self._compiler not in self._dmplugin.getSupportedCompilers(): |
249 |
self.reportError("Compiler not supported: " + self._compiler + ". Supported compilers:" +str(self._dmplugin.getSupportedCompilers())) |
250 |
return False |
251 |
|
252 |
if self._arch not in self._dmplugin.getSupportedArchs(): |
253 |
self.reportError("Architecture not supported: " + self._arch + ". Supported archs:" +str(self._dmplugin.getSupportedArchs())) |
254 |
return False |
255 |
|
256 |
if self._ltype not in self._dmplugin.getSupportedLibraryTypes(): |
257 |
self.reportError("Library type not supported: " + self._ltype + ". Supported libraries:" +str(self._dmplugin.getSupportedLibraryTypes())) |
258 |
return False |
259 |
|
260 |
#artifact and md5 generation
|
261 |
|
262 |
file_name=self._artifact+"-"+self._version+"-"+self._platform+"-"+self._compiler+"-"+self._arch+"-"+self._ltype |
263 |
|
264 |
|
265 |
tarname=file_name+".tar.gz"
|
266 |
md5name=tarname+".md5"
|
267 |
dmfile=file_name+".xml"
|
268 |
|
269 |
dmutil = BMUtil() |
270 |
|
271 |
tmpdir=self._dmplugin.getDepManPath()+os.path.sep+".cache"+os.path.sep+self._group+os.path.sep+self._artifact+os.path.sep+self._version+os.path.sep+self._platform+os.path.sep+self._compiler+os.path.sep+self._arch+os.path.sep+self._ltype |
272 |
|
273 |
dmutil.mkdir(tmpdir) |
274 |
print tmpdir+os.path.sep+tarname,self._path |
275 |
dmutil.targz(os.path.join(tmpdir,tarname),self._path)
|
276 |
#print "targz ",tmpdir+os.path.sep+tarname
|
277 |
dmutil.createMD5(tmpdir+os.path.sep+tarname,tmpdir+os.path.sep+md5name) |
278 |
if self._xmlfile != "": |
279 |
shutil.copyfile(self._xmlfile,tmpdir+os.path.sep+dmfile)
|
280 |
print "Artifact " + tarname + " created in:\n" + tmpdir |
281 |
|
282 |
if self._upload: |
283 |
dmutil.rmdir(".dmn_tmp") # Prevent for uploading bad previous compilations! |
284 |
sshtmpdir=".dmn_tmp"+os.path.sep+self._group+os.path.sep+self._artifact+os.path.sep+self._version+os.path.sep+self._platform+os.path.sep+self._compiler+os.path.sep+self._arch+os.path.sep+self._ltype |
285 |
dmutil.mkdir(sshtmpdir) |
286 |
shutil.copyfile(tmpdir+os.path.sep+tarname,sshtmpdir+os.path.sep+tarname) |
287 |
shutil.copyfile(tmpdir+os.path.sep+md5name,sshtmpdir+os.path.sep+md5name) |
288 |
if self._xmlfile != "": |
289 |
shutil.copyfile(tmpdir+os.path.sep+dmfile,sshtmpdir+os.path.sep+dmfile) |
290 |
url = self._default_ssh;
|
291 |
destdir = self._default_destdir
|
292 |
login = self._default_login
|
293 |
|
294 |
if self._is_Interactive: |
295 |
tmstr="SSH Server [*]:"
|
296 |
url=raw_input(string.replace(tmstr,"*",self._default_ssh)) |
297 |
if len(url)==0: |
298 |
url=self._default_ssh
|
299 |
|
300 |
tmstr="Destination Directory [*]:"
|
301 |
destdir=raw_input(string.replace(tmstr,"*",self._default_destdir)) |
302 |
if len(destdir)==0: |
303 |
destdir=self._default_destdir
|
304 |
|
305 |
tmstr="Login [*]:"
|
306 |
login=raw_input(string.replace(tmstr,"*",self._default_login)) |
307 |
if len(login)==0: |
308 |
login=self._default_login
|
309 |
|
310 |
download_dir = self._group+"/"+self._artifact+"/"+self._version+"/"+self._platform+"/"+self._compiler+"/"+self._arch+"/"+self._ltype |
311 |
|
312 |
print "* Uploading ",tarname |
313 |
print "* Uploading ",md5name |
314 |
|
315 |
#scp
|
316 |
base_ssh=destdir |
317 |
url_ssh=url |
318 |
scpcommand = "scp"
|
319 |
pscppath = ""
|
320 |
if sys.platform == "win32": |
321 |
scpcommand=self._dmplugin.getDepManDataPath()+os.path.sep+"win32"+os.path.sep+"pscp.exe" |
322 |
scpcommand = '"'+os.path.normpath(scpcommand)+'"' |
323 |
cmdstr=scpcommand +" -r "+".dmn_tmp"+os.path.sep+"*"+" "+login+"@"+url_ssh+":"+base_ssh |
324 |
|
325 |
print cmdstr
|
326 |
os.system(cmdstr) |
327 |
|
328 |
#scp
|
329 |
|
330 |
dmutil.rmdir(".dmn_tmp")
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
PlugInManager().registerPlugIn("DepManCreatePlugIn",DepManCreatePlugIn())
|