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