Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / build / buildman / bin / bmplugins / DepManGetPlugIn.py @ 27363

History | View | Annotate | Download (8.57 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._distribution = ""
17
                self._artifact = ""
18
                self._compiler = ""
19
                self._arch = ""
20
                self._ltype = ""
21
                self._forceCache = False
22
                self._isInteractive = True
23
                
24
        def setURL(self,url):
25
                self._url = url
26

    
27
        def setGroup(self,group):
28
                self._group = group
29

    
30
        def setArtifact(self,artifact):
31
                self._artifact = artifact                
32
        
33
        def setVersion(self,version):
34
                self._version = version
35
        
36
        def setPlatform(self,platform):
37
                self._platform = platform
38

    
39
        def setDistribution(self,distribution):
40
                self._distribution = distribution
41

    
42
        def setCompiler(self,compiler):
43
                self._compiler = compiler
44

    
45
        def setArch(self,arch):
46
                self._arch = arch
47

    
48
        def setLibraryType(self,ltype):
49
                self._ltype = ltype
50

    
51
        def setForceCache(self):
52
                self._forceCache = True
53
                self._isInteractive = False
54

    
55
        def setForceRemote(self):
56
                self._forceCache = False
57
                self._isInteractive = False
58
        
59
        def init(self):
60
                self.addGoal("get", "downloads an artifact if not in cache.")
61
                self.addGoalOption("get","--url", "URL base for the DepMan repository.")
62
                self.addGoalOption("get","--group", "Group namespace of the artifact.")
63
                self.addGoalOption("get","--artifact", "Name of the artifact to download.")
64
                self.addGoalOption("get","--version", "Version of the artifact.")
65
                self.addGoalOption("get","--platform", "Platform of the artifact.")
66
                self.addGoalOption("get","--distribution", "Distribution of the artifact.")
67
                self.addGoalOption("get","--compiler", "Selects the compiler version that was used to compile the artifact.")
68
                self.addGoalOption("get","--arch", "Selects the architecture of the artifact.")
69
                self.addGoalOption("get","--ltype", "Type of library of the artifact.")
70
                self.addGoalOption("get","--cache", "Forces the use of cache files without asking.")
71
                self.addGoalOption("get","--remote", "Forces the download of remote without the use of the cache and without asking.")
72

    
73
                self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn")
74
                if self._dmplugin == None:
75
                        self.reportError("PlugIn `depman` not found")
76
                        return
77
                self._default_repository = self._dmplugin.getDepManPath()
78
        
79
                isGet = False
80
                while self._arguments.read("get"):
81
                        isGet = True
82
                
83
                if not isGet:
84
                        return
85

    
86
                args=[""]
87
                if self._arguments.read("--url",args):
88
                        self._url = args[0]
89

    
90
                args=[""]
91
                if self._arguments.read("--group",args):
92
                        self._group = args[0]
93

    
94
                args=[""]
95
                if self._arguments.read("--artifact",args):
96
                        self._artifact = args[0]
97

    
98
                args=[""]
99
                if self._arguments.read("--version",args):
100
                        self._version = args[0]
101

    
102
                args=[""]
103
                if self._arguments.read("--platform",args):
104
                        self._platform = args[0]
105

    
106
                args=[""]
107
                if self._arguments.read("--distribution",args):
108
                        self._distribution = args[0]
109

    
110
                args=[""]
111
                if self._arguments.read("--compiler",args):
112
                        self._compiler = args[0]
113

    
114
                args=[""]
115
                if self._arguments.read("--arch",args):
116
                        self._arch = args[0]
117

    
118
                args=[""]
119
                if self._arguments.read("--ltype",args):
120
                        self._ltype = args[0]
121

    
122
                if self._arguments.read("--cache"):
123
                        self._forceCache = True
124
                        self._isInteractive = False
125

    
126
                if self._arguments.read("--remote"):
127
                        self._forceCache = False
128
                        self._isInteractive = False
129
        
130
                self.setExecute(True)
131
        
132

    
133
        def initFromXML(self,node):
134
                pass
135
                #TODO: . . .
136

    
137
        def execute(self):
138
                print "Executing Plugin:" + str(self.__class__)
139
                if self._url == "":
140
                        self.reportError("Missing url option")
141
                        return
142
                if self._artifact == "":
143
                        self.reportError("Missing artifact option")
144
                        return
145
                if self._group == "":
146
                        self.reportError("Missing group option")
147
                        return
148
                if self._version == "":
149
                        self.reportError("Missing version option")
150
                        return
151
                if self._platform == "":
152
                        self.reportError("Missing platform option")
153
                        return
154
                if self._platform!="all":
155
                        if self._distribution == "":
156
                                self.reportError("Missing distribution option")
157
                                return
158
                        if self._compiler == "":
159
                                self.reportError("Missing compiler option")
160
                                return
161
                        if self._arch == "":
162
                                self.reportError("Missing artifact option")
163
                                return
164
                        if self._ltype == "":
165
                                self.reportError("Missing library type option")
166
                                return
167

    
168
        
169
                if self._platform not in self._dmplugin.getSupportedPlatforms():
170
                        self.reportError("* Platform not supported: " + self._platform)
171
                        return
172
                
173
                if self._platform!="all":
174
        
175
                        if self._compiler not in self._dmplugin.getSupportedCompilers():
176
                                self.reportError("* Compiler not supported: "+ self._compiler)
177
                                return
178
        
179
                        if self._arch not in self._dmplugin.getSupportedArchs():
180
                                self.reportError("* Architecture not supported: "+ self._arch)
181
                                return
182
        
183
                        if self._ltype not in self._dmplugin.getSupportedLibraryTypes():
184
                                self.reportError("* Library type not supported: " + self._ltype)
185
                                return
186
        
187
                if self._platform!=self._dmplugin.getOSPlatform() and self._platform!="all":
188
                        print "* Warning: Forced platform ",self._platform
189
                return self.get()
190

    
191
        def get(self, unPackList = None):
192
                #transform namespaces org.foo to org/foo
193
                group=self._group.replace(".","/")
194
        
195
                print "[",self._artifact,"]"
196

    
197
                file_name=self._artifact+"-"+self._version+"-"+self._platform
198
                if self._platform!="all":
199
                        file_name=file_name+"-"+self._distribution+"-"+self._compiler+"-"+self._arch+"-"+self._ltype
200
                tarname=file_name+".tar.gz"
201
                md5name=tarname+".md5"
202
        
203
                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
204
                if self._platform!="all":
205
                        download_path = download_path+os.path.sep+self._distribution+os.path.sep+self._compiler+os.path.sep+self._arch+os.path.sep+self._ltype
206
                
207
                download_dir = group+"/"+self._artifact+"/"+self._version+"/"+self._platform
208
                if self._platform!="all":        
209
                        download_dir = download_dir+"/"+self._distribution+"/"+self._compiler+"/"+self._arch+"/"+self._ltype
210

    
211
                cache_path = self._default_repository+os.path.sep+".cache"+os.path.sep+download_path
212
        
213
        
214
                tstr=self._version.lower()
215
                if tstr.find("snapshot")!=-1:
216
                        is_snapshot=True
217
                else:
218
                        is_snapshot=False
219
        
220
                dmutil = BMUtil()
221

    
222
                is_tar=True
223
                is_md5=True
224
                if not dmutil.checkUrl(self._url+"/"+download_dir+"/"+md5name):
225
                        #print "Error: File ",baseurl+"/"+download_dir+"/"+md5name, " not found in the repository"
226
                        is_md5=False
227
        
228
                if not dmutil.checkUrl(self._url+"/"+download_dir+"/"+tarname):
229
                        #print "Error: File ",baseurl+"/"+download_dir+"/"+tarname, " not found in the repository"
230
                        is_tar=False
231
        
232
                dmutil.mkdir(cache_path)
233
                
234
        
235
                if not os.path.isfile(cache_path+os.path.sep+md5name):
236
                        is_cache=False
237
                else:
238
                        is_cache=True
239

    
240
                #Once all variables have been collected, lets decide what to do with the artifact
241
                must_download=False
242
        
243
                if (not is_md5 or not is_tar) and not is_cache:
244
                        print "Error: Artifact ",tarname," not found"
245
                        return False
246
        
247
                if not is_md5 and not is_tar and is_cache:
248
                        print "* file not found in repository, using cache..."
249
                        must_download=False
250
        
251
                if is_md5 and is_tar  and not is_cache:
252
                        print "* file is not in cache, downloading..."
253
                        must_download=True
254
        
255
                if is_md5 and is_tar and is_cache:
256
                        if is_snapshot:
257
                                if self._isInteractive:
258
                                        repo=raw_input("What snapshot do you want to use? (cache/remote): ")
259
                                else:
260
                                        if self._forceCache:
261
                                                repo="cache"
262
                                        else:
263
                                                repo="remote"
264
                                        
265
                                must_download=False
266
                        
267
                                #in case of misspeling, using cache by default
268
                                if repo!="cache" and repo!="remote":
269
                                        repo="cache"
270
                        else:
271
                                repo="remote"
272
                
273
                        if repo=="remote":
274
                                print "* file cached, checking md5..."
275
                                dmutil.download(self._url+"/"+download_dir+"/"+md5name,cache_path+os.path.sep+md5name+".new")
276
                        
277
                                if dmutil.diff(cache_path+os.path.sep+md5name,cache_path+os.path.sep+md5name+".new"):
278
                                        print "* no md5 matching, re-downloading..."
279
                                        must_download=True
280
                                else:
281
                                        print "* md5 matching succesful"
282
                                        must_download=False
283
                                os.remove(cache_path+os.path.sep+md5name+".new")
284
        
285
                if must_download==True:
286
                        print "URL :", self._url
287
                        dmutil.download(self._url+"/"+download_dir+"/"+md5name,cache_path+os.path.sep+md5name)
288
                        #print "* downloaded [",md5name,"]"
289
                        dmutil.download(self._url+"/"+download_dir+"/"+tarname,cache_path+os.path.sep+tarname)
290
                        #print "* downloaded[",tarname,"]"
291
                if unPackList != None:
292
                        if (cache_path+os.path.sep+tarname) not in unPackList:
293
                                unPackList.append(cache_path+os.path.sep+tarname)
294
                
295
                return True
296

    
297
PlugInManager().registerPlugIn("DepManGetPlugIn",DepManGetPlugIn())
298

    
299