Revision 27642 branches/v2_0_0_prep/build/buildman/bin/bmplugins/DepManCreatePlugIn.py
DepManCreatePlugIn.py | ||
---|---|---|
2 | 2 |
|
3 | 3 |
from bmbase.IPlugIn import IPlugIn |
4 | 4 |
from bmbase.PlugInManager import PlugInManager |
5 |
from bmcore.BMUtil import BMUtil
|
|
5 |
from bmcore.BMUtil import *
|
|
6 | 6 |
from bmcore.ftpslib import * |
7 | 7 |
from xml.dom import minidom |
8 | 8 |
import string |
... | ... | |
17 | 17 |
IPlugIn.__init__(self) |
18 | 18 |
|
19 | 19 |
self._path="." |
20 |
self._group="" |
|
21 |
self._artifact="" |
|
22 |
self._version="" |
|
23 |
self._platform="default" |
|
24 |
self._distribution="default" |
|
25 |
self._arch="default" |
|
26 |
self._compiler="default" |
|
27 |
self._ltype="" |
|
28 | 20 |
self._upload=False |
29 |
self._is_Interactive=True |
|
30 |
self._xmlfile = "" |
|
31 |
self._packageNode = None |
|
21 |
self._is_Interactive=False |
|
22 |
self._dependency = None |
|
32 | 23 |
|
33 | 24 |
self._default_ftp="downloads.gvsig.org" |
34 | 25 |
self._default_login="maven" |
... | ... | |
38 | 29 |
def init(self): |
39 | 30 |
self.addGoal("create", "Create an artifact") |
40 | 31 |
self.addGoalOption("create","--path", "Specifies source directory") |
41 |
self.addGoalOption("create","--group", "Specifies artifact group name") |
|
42 |
self.addGoalOption("create","--artifact", "Specifies artifact name") |
|
43 |
self.addGoalOption("create","--version", "Specifies artifact version") |
|
44 |
self.addGoalOption("create","--platform", "Specifies artifact OS platform") |
|
45 |
self.addGoalOption("create","--distribution", "Specifies artifact OS distribution") |
|
46 |
self.addGoalOption("create","--arch", "Specifies artifact hardware architecture") |
|
47 |
self.addGoalOption("create","--compiler", "Specifies artifact compiler version") |
|
48 |
self.addGoalOption("create","--ltype", "Specifies library type if needed") |
|
49 | 32 |
self.addGoalOption("create","--upload", "Whenever the artifact must be uploaded or not") |
50 |
self.addGoalOption("create","--from-xml", "Uses the given depman.xml file to create the package") |
|
51 |
|
|
52 |
isCreate = False |
|
53 |
if self._arguments.read("create"): |
|
54 |
self.setExecute(True) |
|
55 |
isCreate = True |
|
33 |
self.addGoalOption("create","--interactive", "ask for server or artifact deployment configuration") |
|
34 |
self.addPreGoal("create", "depman") |
|
35 |
self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") |
|
56 | 36 |
|
57 |
if not isCreate: |
|
58 |
return |
|
37 |
if self._dmplugin == None: |
|
38 |
self.reportError("PlugIn `depman` not found") |
|
39 |
return False |
|
59 | 40 |
|
41 |
|
|
42 |
if self._arguments.read("create"): |
|
43 |
self.setExecute(True) |
|
44 |
|
|
60 | 45 |
args=[""] |
61 |
use_xml=False |
|
62 |
if self._arguments.read("--from-xml",args): |
|
63 |
self._xmlfile=args[0] |
|
64 |
use_xml=True |
|
65 |
|
|
66 |
if use_xml: |
|
67 |
self.loadXMLFile(self._xmlfile) |
|
68 |
|
|
69 |
|
|
70 |
args=[""] |
|
71 | 46 |
if self._arguments.read("--path",args): |
72 | 47 |
self._path=args[0] |
73 | 48 |
|
74 |
args=[""] |
|
75 |
if self._arguments.read("--group",args): |
|
76 |
self._group=args[0] |
|
77 |
self._is_Interactive=False |
|
78 |
|
|
79 |
args=[""] |
|
80 |
if self._arguments.read("--artifact",args): |
|
81 |
self._artifact=args[0] |
|
82 |
self._is_Interactive=False |
|
83 |
|
|
84 |
args=[""] |
|
85 |
if self._arguments.read("--version",args): |
|
86 |
self._version=args[0] |
|
87 |
self._is_Interactive=False |
|
88 |
|
|
89 |
|
|
90 |
args=[""] |
|
91 |
if self._arguments.read("--platform",args): |
|
92 |
self._platform=args[0] |
|
93 |
self._is_Interactive=False |
|
94 |
|
|
95 |
args=[""] |
|
96 |
if self._arguments.read("--distribution",args): |
|
97 |
self._distribution=args[0] |
|
98 |
self._is_Interactive=False |
|
99 |
|
|
100 |
args=[""] |
|
101 |
if self._arguments.read("--arch",args): |
|
102 |
self._arch=args[0] |
|
103 |
self._is_Interactive=False |
|
104 |
|
|
105 |
args=[""] |
|
106 |
if self._arguments.read("--compiler",args): |
|
107 |
self._compiler=args[0] |
|
108 |
self._is_Interactive=False |
|
109 |
|
|
110 |
args=[""] |
|
111 |
if self._arguments.read("--ltype",args): |
|
112 |
self._ltype=args[0] |
|
113 |
self._is_Interactive=False |
|
114 |
|
|
115 | 49 |
if self._arguments.read("--upload"): |
116 | 50 |
self._upload=True |
117 | 51 |
|
52 |
if self._arguments.read("--interactive"): |
|
53 |
self._is_Interactive=True |
|
118 | 54 |
|
55 |
|
|
119 | 56 |
def initFromXML(self,node): |
120 |
if node.localName == "create": |
|
121 |
if node.hasAttributes(): |
|
122 |
if node.attributes.has_key("from-xml"): |
|
123 |
self._xmlfile=node.attributes.get("from-xml").value |
|
124 |
self.loadXMLFile(self._xmlfile) |
|
125 |
if node.attributes.has_key("path"): |
|
126 |
self._path = node.attributes.get("path").value |
|
127 |
if node.attributes.has_key("upload"): |
|
128 |
value = node.attributes.get("upload").value |
|
129 |
if value =="True" or value =="true": |
|
130 |
self._upload = True |
|
57 |
for n in node.childNodes: |
|
58 |
if n.localName=="package": |
|
59 |
processPackage = True |
|
60 |
if n.hasAttributes(): |
|
61 |
if n.attributes.has_key("platform"): |
|
62 |
values = n.attributes.get("platform").value.split(",") |
|
63 |
if self._dmplugin.getOSPlatform() in values: |
|
64 |
processPackage = True |
|
65 |
else: |
|
66 |
processPackage = False |
|
67 |
if processPackage: |
|
68 |
print "Processing for platform..." |
|
69 |
self._dependency = DepManDependency(self._dmplugin) |
|
70 |
for p in n.childNodes: |
|
71 |
if p.localName=="group": |
|
72 |
self._dependency.group=p.childNodes[0].nodeValue |
|
73 |
if p.localName=="artifact": |
|
74 |
self._dependency.artifact=p.childNodes[0].nodeValue |
|
75 |
if p.localName=="version": |
|
76 |
self._dependency.version=p.childNodes[0].nodeValue |
|
77 |
if p.localName=="platform": |
|
78 |
self._dependency.platform=p.childNodes[0].nodeValue |
|
79 |
if p.localName=="distribution": |
|
80 |
self._dependency.distribution=p.childNodes[0].nodeValue |
|
81 |
if p.localName=="compiler": |
|
82 |
self._dependency.compiler=p.childNodes[0].nodeValue |
|
83 |
if p.localName=="arch": |
|
84 |
self._dependency.arch=p.childNodes[0].nodeValue |
|
85 |
if p.localName=="libraryType": |
|
86 |
self._dependency.libraryType=p.childNodes[0].nodeValue |
|
87 |
|
|
88 |
print "Creating Artifact:" + str(self._dependency) |
|
89 |
#if p.localName =="upload": |
|
90 |
#TODO: Maybe upload should be an external plugin |
|
91 |
# for k in p.childNodes: |
|
92 |
# if k.localName == "sshserver": |
|
93 |
# self._default_ssh = k.childNodes[0].nodeValue |
|
94 |
# if k.localName == "destdir": |
|
95 |
# self._default_destdir = k.childNodes[0].nodeValue |
|
96 |
# if k.localName == "username": |
|
97 |
# self._default_login = k.childNodes[0].nodeValue |
|
98 |
|
|
131 | 99 |
|
132 |
else: |
|
133 |
if node.localName == "depman": |
|
134 |
self._packageNode = node |
|
135 |
self._is_Interactive=False |
|
136 | 100 |
|
137 | 101 |
def execute(self): |
138 | 102 |
print "Executing Plugin:" + str(self.__class__) |
139 | 103 |
return self.create() |
140 | 104 |
|
141 | 105 |
def create(self): |
142 |
|
|
143 |
self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") |
|
144 |
if self._dmplugin == None: |
|
145 |
self.reportError("PlugIn `depman` not found") |
|
146 |
return False |
|
147 |
|
|
106 |
self.initFromXML(self._dmplugin.getNode()) |
|
148 | 107 |
#user questions |
149 |
if self._is_Interactive: |
|
150 |
self._group=raw_input("Group: ") |
|
151 |
|
|
152 |
self._artifact=raw_input("Artifact: ") |
|
153 |
|
|
154 |
self._version=raw_input("Version: ") |
|
155 |
|
|
156 |
tmpstr="" |
|
157 |
for p in self._dmplugin.getSupportedPlatforms(): |
|
158 |
tmpstr=tmpstr+p+" " |
|
159 |
print "( ",tmpstr,")" |
|
160 |
tmstr="Platform [*]:" |
|
161 |
self._platform=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSPlatform())) |
|
162 |
if len(self._platform)==0: |
|
163 |
self._platform=self._dmplugin.getOSPlatform() |
|
164 |
|
|
165 |
if self._platform!="all": |
|
166 |
tmstr="OS Distribution [*]:" |
|
167 |
self._distribution=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSDistribution())) |
|
168 |
if len(self._distribution)==0: |
|
169 |
self._distribution=self._dmplugin.getOSDistribution() |
|
170 |
|
|
171 |
tmpstr="" |
|
172 |
for p in self._dmplugin.getSupportedCompilers(): |
|
173 |
tmpstr=tmpstr+p+" " |
|
174 |
print "( ",tmpstr,")" |
|
175 |
tmstr="Compiler [*]:" |
|
176 |
self._compiler=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSCompiler())) |
|
177 |
if len(self._compiler)==0: |
|
178 |
self._compiler=self._dmplugin.getOSCompiler() |
|
108 |
if self._dependency==None: |
|
109 |
self._dependency = DepManDependency(self._dmplugin) |
|
110 |
self._is_Interactive = True |
|
111 |
self._dependency.raw_input() |
|
179 | 112 |
|
180 |
tmpstr="" |
|
181 |
for p in self._dmplugin.getSupportedArchs(): |
|
182 |
tmpstr=tmpstr+p+" " |
|
183 |
print "( ",tmpstr,")" |
|
184 |
tmstr="Architecture [*]:" |
|
185 |
self._arch=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSArch())) |
|
186 |
if len(self._arch)==0: |
|
187 |
self._arch=self._dmplugin.getOSArch() |
|
188 |
|
|
189 |
tmpstr="" |
|
190 |
for p in self._dmplugin.getSupportedLibraryTypes(): |
|
191 |
tmpstr=tmpstr+p+" " |
|
192 |
print "( ",tmpstr,")" |
|
193 |
self._ltype=raw_input("Library Type: ") |
|
194 |
|
|
195 | 113 |
upload_response = raw_input("Upload to server? (y/n): ") |
196 | 114 |
if upload_response == "y" or upload_response == "yes": |
197 | 115 |
self._upload=True |
198 |
|
|
199 |
if self._packageNode != None: |
|
200 |
for n in self._packageNode.childNodes: |
|
201 |
if n.localName=="package": |
|
202 |
processPackage = True |
|
203 |
if n.hasAttributes(): |
|
204 |
if n.attributes.has_key("platform"): |
|
205 |
values = n.attributes.get("platform").value.split(",") |
|
206 |
if self._dmplugin.getOSPlatform() in values: |
|
207 |
processPackage = True |
|
208 |
else: |
|
209 |
processPackage = False |
|
210 |
if processPackage: |
|
211 |
print "Processing for platform..." |
|
212 |
for p in n.childNodes: |
|
213 |
if p.localName=="group": |
|
214 |
self._group=p.childNodes[0].nodeValue |
|
215 |
if p.localName=="artifact": |
|
216 |
self._artifact=p.childNodes[0].nodeValue |
|
217 |
if p.localName=="version": |
|
218 |
self._version=p.childNodes[0].nodeValue |
|
219 |
if p.localName=="platform": |
|
220 |
self._platform=p.childNodes[0].nodeValue |
|
221 |
if p.localName=="distribution": |
|
222 |
self._distribution=p.childNodes[0].nodeValue |
|
223 |
if p.localName=="compiler": |
|
224 |
self._compiler=p.childNodes[0].nodeValue |
|
225 |
if p.localName=="arch": |
|
226 |
self._arch=p.childNodes[0].nodeValue |
|
227 |
if p.localName=="libraryType": |
|
228 |
self._ltype=p.childNodes[0].nodeValue |
|
229 |
|
|
230 |
if p.localName =="upload": |
|
231 |
#TODO: Maybe upload should be an external plugin |
|
232 |
for k in p.childNodes: |
|
233 |
if k.localName == "sshserver": |
|
234 |
self._default_ssh = k.childNodes[0].nodeValue |
|
235 |
if k.localName == "destdir": |
|
236 |
self._default_destdir = k.childNodes[0].nodeValue |
|
237 |
if k.localName == "username": |
|
238 |
self._default_login = k.childNodes[0].nodeValue |
|
239 |
|
|
240 |
if self._group == "": |
|
241 |
self.reportError("Group cannot be empty") |
|
116 |
|
|
117 |
if not self._dmplugin.validateDependency(self._dependency): |
|
242 | 118 |
return False |
243 |
if self._artifact == "": |
|
244 |
self.reportError("Artifact cannot be empty") |
|
245 |
return False |
|
246 |
if self._version == "": |
|
247 |
self.reportError("Version cannog be empty") |
|
248 |
return |
|
249 |
self._group=self._group.replace(".","/") |
|
250 |
if self._platform=="default": |
|
251 |
self._platform=self._dmplugin.getOSPlatform() |
|
252 |
if self._distribution=="default": |
|
253 |
self._distribution=self._dmplugin.getOSDistribution() |
|
254 |
if self._compiler=="default": |
|
255 |
self._compiler=self._dmplugin.getOSCompiler() |
|
256 |
if self._arch=="default": |
|
257 |
self._arch=self._dmplugin.getOSArch() |
|
258 |
|
|
259 |
|
|
260 |
#let's check user input consistency |
|
261 |
|
|
262 |
if self._platform not in self._dmplugin.getSupportedPlatforms(): |
|
263 |
self.reportError("Platform not supported: " + self._platform + ". Supported platforms:" + str(self._dmplugin.getSupportedPlatforms())) |
|
264 |
return False |
|
119 |
|
|
265 | 120 |
|
266 |
if self._platform != "all": |
|
267 |
|
|
268 |
if self._compiler not in self._dmplugin.getSupportedCompilers(): |
|
269 |
self.reportError("Compiler not supported: " + self._compiler + ". Supported compilers:" +str(self._dmplugin.getSupportedCompilers())) |
|
270 |
return False |
|
271 |
|
|
272 |
if self._arch not in self._dmplugin.getSupportedArchs(): |
|
273 |
self.reportError("Architecture not supported: " + self._arch + ". Supported archs:" +str(self._dmplugin.getSupportedArchs())) |
|
274 |
return False |
|
275 |
|
|
276 |
if self._ltype not in self._dmplugin.getSupportedLibraryTypes(): |
|
277 |
self.reportError("Library type not supported: " + self._ltype + ". Supported libraries:" +str(self._dmplugin.getSupportedLibraryTypes())) |
|
278 |
return False |
|
279 |
|
|
280 | 121 |
#artifact and md5 generation |
281 |
file_name=self._artifact+"-"+self._version+"-"+self._platform |
|
282 |
file_path=self._group+os.path.sep+self._artifact+os.path.sep+self._version+os.path.sep+self._platform |
|
283 |
if self._platform!="all": |
|
284 |
file_name=file_name+"-"+self._distribution+"-"+self._compiler+"-"+self._arch+"-"+self._ltype |
|
285 |
file_path=file_path+os.path.sep+self._distribution+os.path.sep+self._compiler+os.path.sep+self._arch+os.path.sep+self._ltype |
|
122 |
file_name=self._dependency.getDepManFileName() |
|
123 |
file_path=self._dependency.getDepManUrlPath() |
|
286 | 124 |
|
287 | 125 |
tarname=file_name+".tar.gz" |
288 | 126 |
md5name=tarname+".md5" |
... | ... | |
296 | 134 |
dmutil.targz(os.path.join(tmpdir,tarname),self._path) |
297 | 135 |
#print "targz ",tmpdir+os.path.sep+tarname |
298 | 136 |
dmutil.createMD5(tmpdir+os.path.sep+tarname,tmpdir+os.path.sep+md5name) |
299 |
if self._xmlfile != "": |
|
300 |
shutil.copyfile(self._xmlfile,tmpdir+os.path.sep+dmfile) |
|
137 |
|
|
138 |
if not self._is_Interactive: |
|
139 |
shutil.copyfile(self._dmplugin.getXMLFile(),tmpdir+os.path.sep+dmfile) |
|
140 |
|
|
301 | 141 |
print "Artifact " + tarname + " created in:\n" + tmpdir |
302 | 142 |
|
303 | 143 |
if self._upload: |
... | ... | |
311 | 151 |
url = self._default_ftp; |
312 | 152 |
destdir = self._default_destdir |
313 | 153 |
login = self._default_login |
314 |
|
|
154 |
pwd = "" |
|
315 | 155 |
if self._is_Interactive: |
316 | 156 |
tmstr="FTP Server [*]:" |
317 | 157 |
url=raw_input(string.replace(tmstr,"*",self._default_ftp)) |
... | ... | |
351 | 191 |
|
352 | 192 |
#scp |
353 | 193 |
''' |
194 |
pwd = "*****" |
|
354 | 195 |
#ftp |
355 |
pwd = '*****' |
|
356 | 196 |
self.uploadFTPFile(url,login,pwd,destdir,os.path.sep+file_path,tmpdir+os.path.sep+tarname,tarname) |
357 | 197 |
self.uploadFTPFile(url,login,pwd,destdir,os.path.sep+file_path,tmpdir+os.path.sep+md5name,md5name) |
358 |
if self._xmlfile:
|
|
198 |
if not self._is_Interactive:
|
|
359 | 199 |
self.uploadFTPFile(url,login,pwd,destdir,os.path.sep+file_path,tmpdir+os.path.sep+dmfile,dmfile) |
360 | 200 |
|
361 | 201 |
#dmutil.rmdir(".dmn_tmp") |
Also available in: Unified diff