svn-gvsig-desktop / trunk / extensions / ext3Dgui / buildman / bin / bmplugins / DepManGetPlugIn.py @ 26254
History | View | Annotate | Download (7.81 KB)
1 |
from bmbase.IPlugIn import IPlugIn |
---|---|
2 |
from bmbase.PlugInManager import PlugInManager |
3 |
from bmcore.BMUtil import BMUtil |
4 |
from xml.dom import minidom |
5 |
import os |
6 |
|
7 |
class DepManGetPlugIn(IPlugIn): |
8 |
def __init__(self): |
9 |
IPlugIn.__init__(self)
|
10 |
self._default_repository = "" |
11 |
self._url = "" |
12 |
self._group = "" |
13 |
self._artifact = "" |
14 |
self._version = "" |
15 |
self._platform = "" |
16 |
self._artifact = "" |
17 |
self._compiler = "" |
18 |
self._arch = "" |
19 |
self._ltype = "" |
20 |
self._forceCache = False |
21 |
self._isInteractive = True |
22 |
|
23 |
def setURL(self,url): |
24 |
self._url = url
|
25 |
|
26 |
def setGroup(self,group): |
27 |
self._group = group
|
28 |
|
29 |
def setArtifact(self,artifact): |
30 |
self._artifact = artifact
|
31 |
|
32 |
def setVersion(self,version): |
33 |
self._version = version
|
34 |
|
35 |
def setPlatform(self,platform): |
36 |
self._platform = platform
|
37 |
|
38 |
def setCompiler(self,compiler): |
39 |
self._compiler = compiler
|
40 |
|
41 |
def setArch(self,arch): |
42 |
self._arch = arch
|
43 |
|
44 |
def setLibraryType(self,ltype): |
45 |
self._ltype = ltype
|
46 |
|
47 |
def setForceCache(self): |
48 |
self._forceCache = True |
49 |
self._isInteractive = False |
50 |
|
51 |
def setForceRemote(self): |
52 |
self._forceCache = False |
53 |
self._isInteractive = False |
54 |
|
55 |
def init(self): |
56 |
self.addGoal("get", "downloads an artifact if not in cache.") |
57 |
self.addGoalOption("get","--url", "URL base for the DepMan repository.") |
58 |
self.addGoalOption("get","--group", "Group namespace of the artifact.") |
59 |
self.addGoalOption("get","--artifact", "Name of the artifact to download.") |
60 |
self.addGoalOption("get","--version", "Version of the artifact.") |
61 |
self.addGoalOption("get","--platform", "Platform of the artifact.") |
62 |
self.addGoalOption("get","--compiler", "Selects the compiler version that was used to compile the artifact.") |
63 |
self.addGoalOption("get","--arch", "Selects the architecture of the artifact.") |
64 |
self.addGoalOption("get","--ltype", "Type of library of the artifact.") |
65 |
self.addGoalOption("get","--cache", "Forces the use of cache files without asking.") |
66 |
self.addGoalOption("get","--remote", "Forces the download of remote without the use of the cache and without asking.") |
67 |
|
68 |
self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") |
69 |
if self._dmplugin == None: |
70 |
self.reportError("PlugIn `depman` not found") |
71 |
return
|
72 |
self._default_repository = self._dmplugin.getDepManPath() |
73 |
|
74 |
isGet = False
|
75 |
while self._arguments.read("get"): |
76 |
isGet = True
|
77 |
|
78 |
if not isGet: |
79 |
return
|
80 |
|
81 |
args=[""]
|
82 |
if self._arguments.read("--url",args): |
83 |
self._url = args[0] |
84 |
|
85 |
args=[""]
|
86 |
if self._arguments.read("--group",args): |
87 |
self._group = args[0] |
88 |
|
89 |
args=[""]
|
90 |
if self._arguments.read("--artifact",args): |
91 |
self._artifact = args[0] |
92 |
|
93 |
args=[""]
|
94 |
if self._arguments.read("--version",args): |
95 |
self._version = args[0] |
96 |
|
97 |
args=[""]
|
98 |
if self._arguments.read("--platform",args): |
99 |
self._platform = args[0] |
100 |
|
101 |
args=[""]
|
102 |
if self._arguments.read("--compiler",args): |
103 |
self._compiler = args[0] |
104 |
|
105 |
args=[""]
|
106 |
if self._arguments.read("--arch",args): |
107 |
self._arch = args[0] |
108 |
|
109 |
args=[""]
|
110 |
if self._arguments.read("--ltype",args): |
111 |
self._ltype = args[0] |
112 |
|
113 |
if self._arguments.read("--cache"): |
114 |
self._forceCache = True |
115 |
self._isInteractive = False |
116 |
|
117 |
if self._arguments.read("--remote"): |
118 |
self._forceCache = False |
119 |
self._isInteractive = False |
120 |
|
121 |
self.setExecute(True) |
122 |
|
123 |
|
124 |
def initFromXML(self,node): |
125 |
pass
|
126 |
#TODO: . . .
|
127 |
|
128 |
def execute(self): |
129 |
print "Executing Plugin:" + str(self.__class__) |
130 |
if self._url == "": |
131 |
self.reportError("Missing url option") |
132 |
return
|
133 |
if self._artifact == "": |
134 |
self.reportError("Missing artifact option") |
135 |
return
|
136 |
if self._group == "": |
137 |
self.reportError("Missing group option") |
138 |
return
|
139 |
if self._version == "": |
140 |
self.reportError("Missing version option") |
141 |
return
|
142 |
if self._platform == "": |
143 |
self.reportError("Missing platform option") |
144 |
return
|
145 |
if self._compiler == "": |
146 |
self.reportError("Missing compiler option") |
147 |
return
|
148 |
if self._arch == "": |
149 |
self.reportError("Missing artifact option") |
150 |
return
|
151 |
if self._ltype == "": |
152 |
self.reportError("Missing library type option") |
153 |
return
|
154 |
|
155 |
|
156 |
if self._platform not in self._dmplugin.getSupportedPlatforms(): |
157 |
self.reportError("* Platform not supported: " + self._platform) |
158 |
return
|
159 |
|
160 |
if self._compiler not in self._dmplugin.getSupportedCompilers(): |
161 |
self.reportError("* Compiler not supported: "+ self._compiler) |
162 |
return
|
163 |
|
164 |
if self._arch not in self._dmplugin.getSupportedArchs(): |
165 |
self.reportError("* Architecture not supported: "+ self._arch) |
166 |
return
|
167 |
|
168 |
if self._ltype not in self._dmplugin.getSupportedLibraryTypes(): |
169 |
self.reportError("* Library type not supported: " + self._ltype) |
170 |
return
|
171 |
|
172 |
if self._platform!=self._dmplugin.getOSPlatform() and self._platform!="all": |
173 |
print "* Warning: Forced platform ",self._platform |
174 |
return self.get() |
175 |
|
176 |
def get(self, unPackList = None): |
177 |
#transform namespaces org.foo to org/foo
|
178 |
group=self._group.replace(".","/") |
179 |
|
180 |
print "[",self._artifact,"]" |
181 |
|
182 |
file_name=self._artifact+"-"+self._version+"-"+self._platform+"-"+self._compiler+"-"+self._arch+"-"+self._ltype |
183 |
tarname=file_name+".tar.gz"
|
184 |
md5name=tarname+".md5"
|
185 |
|
186 |
download_path = 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 |
187 |
download_dir = group+"/"+self._artifact+"/"+self._version+"/"+self._platform+"/"+self._compiler+"/"+self._arch+"/"+self._ltype |
188 |
cache_path = self._default_repository+os.path.sep+".cache"+os.path.sep+download_path |
189 |
|
190 |
|
191 |
tstr=self._version.lower()
|
192 |
if tstr.find("snapshot")!=-1: |
193 |
is_snapshot=True
|
194 |
else:
|
195 |
is_snapshot=False
|
196 |
|
197 |
dmutil = BMUtil() |
198 |
|
199 |
is_tar=True
|
200 |
is_md5=True
|
201 |
if not dmutil.checkUrl(self._url+"/"+download_dir+"/"+md5name): |
202 |
#print "Error: File ",baseurl+"/"+download_dir+"/"+md5name, " not found in the repository"
|
203 |
is_md5=False
|
204 |
|
205 |
if not dmutil.checkUrl(self._url+"/"+download_dir+"/"+tarname): |
206 |
#print "Error: File ",baseurl+"/"+download_dir+"/"+tarname, " not found in the repository"
|
207 |
is_tar=False
|
208 |
|
209 |
dmutil.mkdir(cache_path) |
210 |
|
211 |
|
212 |
if not os.path.isfile(cache_path+os.path.sep+md5name): |
213 |
is_cache=False
|
214 |
else:
|
215 |
is_cache=True
|
216 |
|
217 |
#Once all variables have been collected, lets decide what to do with the artifact
|
218 |
must_download=False
|
219 |
|
220 |
if (not is_md5 or not is_tar) and not is_cache: |
221 |
print "Error: Artifact ",tarname," not found" |
222 |
return False |
223 |
|
224 |
if not is_md5 and not is_tar and is_cache: |
225 |
print "* file not found in repository, using cache..." |
226 |
must_download=False
|
227 |
|
228 |
if is_md5 and is_tar and not is_cache: |
229 |
print "* file is not in cache, downloading..." |
230 |
must_download=True
|
231 |
|
232 |
if is_md5 and is_tar and is_cache: |
233 |
if is_snapshot:
|
234 |
if self._isInteractive: |
235 |
repo=raw_input("What snapshot do you want to use? (cache/remote): ") |
236 |
else:
|
237 |
if self._forceCache: |
238 |
repo="cache"
|
239 |
else:
|
240 |
repo="remote"
|
241 |
|
242 |
must_download=False
|
243 |
|
244 |
#in case of misspeling, using cache by default
|
245 |
if repo!="cache" and repo!="remote": |
246 |
repo="cache"
|
247 |
else:
|
248 |
repo="remote"
|
249 |
|
250 |
if repo=="remote": |
251 |
print "* file cached, checking md5..." |
252 |
dmutil.download(self._url+"/"+download_dir+"/"+md5name,cache_path+os.path.sep+md5name+".new") |
253 |
|
254 |
if dmutil.diff(cache_path+os.path.sep+md5name,cache_path+os.path.sep+md5name+".new"): |
255 |
print "* no md5 matching, re-downloading..." |
256 |
must_download=True
|
257 |
else:
|
258 |
print "* md5 matching succesful" |
259 |
must_download=False
|
260 |
os.remove(cache_path+os.path.sep+md5name+".new")
|
261 |
|
262 |
if must_download==True: |
263 |
print "URL :", self._url |
264 |
dmutil.download(self._url+"/"+download_dir+"/"+md5name,cache_path+os.path.sep+md5name) |
265 |
#print "* downloaded [",md5name,"]"
|
266 |
dmutil.download(self._url+"/"+download_dir+"/"+tarname,cache_path+os.path.sep+tarname) |
267 |
#print "* downloaded[",tarname,"]"
|
268 |
if unPackList != None: |
269 |
if (cache_path+os.path.sep+tarname) not in unPackList: |
270 |
unPackList.append(cache_path+os.path.sep+tarname) |
271 |
|
272 |
return True |
273 |
|
274 |
PlugInManager().registerPlugIn("DepManGetPlugIn",DepManGetPlugIn())
|
275 |
|
276 |
|