Statistics
| Revision:

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

History | View | Annotate | Download (8.08 KB)

1
#depman update plugin
2

    
3
from bmbase.IPlugIn import IPlugIn
4
from bmbase.PlugInManager import PlugInManager
5
from bmcore.BMUtil import BMUtil
6
import os
7

    
8

    
9
class DepManUpdatePlugIn(IPlugIn):
10
        
11
        def __init__(self):
12
                IPlugIn.__init__(self)
13
                
14
                self._must_Clean=True
15
                self._isFromCache=False
16
                self._isInteractive=True
17
                self._xmlfile="depman.xml"
18
                self._depmanNode = None
19
                
20
                self._defurl="http://lemonvm-ai2.ai2.upv.es/depman"
21
                
22
        def init(self):
23
                self.addGoal("update", "Update current project")
24
                self.addGoalOption("update","--no-clean", "Do not perform a repository clean before update")
25
                self.addGoalOption("update","--cache", "Cache is preferred")
26
                self.addGoalOption("update","--remote", "Remote repository is preferred")
27
                self.addGoalOption("update","--file", "Specifies a dependency xml file")
28
                                
29
                isUpdate = False
30
                if self._arguments.read("update"):
31
                        self.setExecute(True)
32
                        isUpdate = True
33

    
34
                if not isUpdate:
35
                        return
36

    
37
                if self._arguments.read("--no-clean"):
38
                        self._must_Clean = False
39
                        
40
                if self._arguments.read("--cache"):
41
                        self._isInteractive=False
42
                        self._isFromCache = True
43
                
44
                if self._arguments.read("--remote"):
45
                        self._isInteractive=False
46
                        self._isFromCache = False
47
                
48
                args=[""]
49
                if self._arguments.read("--file",args):
50
                        self._xmlfile=args[0]
51
                
52
        def initFromXML(self,node):
53
                if node.localName == "update":
54
                        if node.hasAttributes():
55
                                if node.attributes.has_key("file"):
56
                                        self.loadXMLFile(node.attributes.get("file").value)
57
                                if node.attributes.has_key("no-clean"):
58
                                        value = node.attributes.get("no-clean").value
59
                                        if value == "True" or value == "true":
60
                                                self._must_Clean = True
61
                                foundCache = False
62
                                if node.attributes.has_key("cache"):
63
                                        value = node.attributes.get("cache").value
64
                                        if value == "True" or value == "true":
65
                                                self._isFromCache = True
66
                                if node.attributes.has_key("remote") and not foundCache:
67
                                        value = node.attributes.get("remote").value
68
                                        if value == "True" or value == "true":
69
                                                self._isFromCache = False
70
                        self._isInteractive = False
71
                else:        
72
                        self._depmanNode = node
73
                
74
        def execute(self):
75
                print "Executing Plugin:" + str(self.__class__)
76
                return self.update()
77

    
78

    
79

    
80
        def update(self):
81
                
82
                if self._must_Clean:
83
                        self._dmclean = PlugInManager().getPlugInInstance("DepManCleanPlugIn")
84
                        if self._dmclean == None:
85
                                self.reportError("PlugIn `depman clean` not found")
86
                                return
87
                        delete_cache = self._dmclean.getDeleteCache()
88
                        self._dmclean.setDeleteCache(False)
89
                        self._dmclean.clean()        
90
                        self._dmclean.setDeleteCache(delete_cache)
91

    
92
                if self._depmanNode == None:
93
                        self.loadXMLFile(self._xmlfile)
94
                unPackList = self.getDependencies(self._depmanNode)
95

    
96
                
97
                #once the xml is parsed and files downloaded, lets unpack them
98
                self.unpack(unPackList)
99
        
100
        def getDependencies(self,node):
101
                self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn")
102
                if self._dmplugin == None:
103
                        self.reportError("PlugIn `depman` not found")
104
                        return
105
                
106
                self._dmget = PlugInManager().getPlugInInstance("DepManGetPlugIn")
107
                if self._dmget == None:
108
                        self.reportError("PlugIn `depman get` not found")
109
                        return
110
                
111
                group="none"
112
                artifact="none"
113
                version="0"
114
                platform="none"
115
                distribution="none"
116
                compiler="none"
117
                arch="none"
118
                ltype="none"
119
                
120
                #os default values
121
                defplatform=self._dmplugin.getOSPlatform()
122
                defdistribution=self._dmplugin.getOSDistribution()
123
                defarch=self._dmplugin.getOSArch()
124
                defcompiler=self._dmplugin.getOSCompiler()
125
                
126
                #hardcoded default url
127
                #defurl=default_url
128
                
129
                defurl=self._defurl
130
                
131
                unPackList = []
132
                if node.hasAttributes():
133
                    if node.attributes.has_key("url"):
134
                        defurl=node.attributes.get("url").value
135
                
136
                for i in node.childNodes:
137
                    if i.localName=="dependencies":
138
                        url=defurl
139
                        #os default values
140
                        defplatform=self._dmplugin._osplatform
141
                        defdistribution=self._dmplugin._osdistribution
142
                        defarch=self._dmplugin._osarch
143
                        defcompiler=self._dmplugin._oscompiler
144
                        
145
                        if i.hasAttributes():
146
                            if i.attributes.has_key("platform"):
147
                                defplatform=i.attributes.get("platform").value
148
                            if i.attributes.has_key("distribution"):
149
                                defdistribution=i.attributes.get("distribution").value
150
                            if i.attributes.has_key("architecture"):
151
                                defarch=i.attributes.get("architecture").value
152
                            if i.attributes.has_key("compiler"):
153
                                defcompiler=i.attributes.get("compiler").value
154
                            if i.attributes.has_key("url"):
155
                                url=i.attributes.get("url").value
156
                        
157
                        list_of_platforms=defplatform.split(",")
158
                        #depedencies platform checking
159
                        #we just go on whenever host os or all matches
160
                        
161
                        if len(list_of_platforms)>0 and self._dmplugin.getOSPlatform() not in list_of_platforms and "all" not in list_of_platforms:
162
                            invalid_platform=True
163
                        else:
164
                            invalid_platform=False
165
                            defplatform=self._dmplugin.getOSPlatform()
166
                        
167
                        del list_of_platforms[:]
168
                        
169
                        #print "Url: ",url
170
                        if not invalid_platform:
171
                            for j in i.childNodes:
172
                                
173
                                if j.localName=="dependency":
174
                                    #set default values
175
                                    platform=defplatform
176
                                    distribution=defdistribution
177
                                    arch=defarch
178
                                    compiler=defcompiler
179
                                    group="none"
180
                                    artifact="none"
181
                                    version="0"
182
                                    ltype="none"
183
                                    durl = url
184
                                    if j.hasAttributes():
185
                                        if j.attributes.has_key("url"):
186
                                            durl=j.attributes.get("url").value
187
                                    
188
                                    for h in j.childNodes:
189
                                        if h.localName=="group":
190
                                            group=h.childNodes[0].nodeValue
191
                                        if h.localName=="artifact":
192
                                            artifact=h.childNodes[0].nodeValue
193
                                        if h.localName=="version":
194
                                            version=h.childNodes[0].nodeValue
195
                                        if h.localName=="platform":
196
                                            platform=h.childNodes[0].nodeValue
197
                                        if h.localName=="distribution":
198
                                            distribution=h.childNodes[0].nodeValue
199
                                        if h.localName=="compiler":
200
                                            compiler=h.childNodes[0].nodeValue
201
                                        if h.localName=="architecture":
202
                                            arch=h.childNodes[0].nodeValue
203
                                        if h.localName=="type":
204
                                            ltype=h.childNodes[0].nodeValue
205
                                    self._dmget.setURL(durl)
206
                                    self._dmget.setGroup(group)
207
                                    self._dmget.setArtifact(artifact)
208
                                    self._dmget.setVersion(version)
209
                                    self._dmget.setPlatform(platform)
210
                                    self._dmget.setDistribution(distribution)
211
                                    self._dmget.setCompiler(compiler)
212
                                    self._dmget.setArch(arch)
213
                                    self._dmget.setLibraryType(ltype)
214
                                    #prevents downloading of not matching platforms but overrided
215
                                    if not self._isInteractive:
216
                                        if self._isFromCache:
217
                                            self._dmget.setForceCache()
218
                                        else:
219
                                            self._dmget.setForceRemote()
220
                                    self._dmget.get(unPackList)
221
                return unPackList
222
        
223
        def unpack(self,unPackList):
224
                sep=os.path.sep
225
                dmutil = BMUtil()
226
                for file in unPackList:
227
                        tmpstr=file[file.rfind(sep)+1:]
228
                        print "* unpacking ",tmpstr
229
                        dmutil.untargz(file,self._dmplugin.getDepManPath())
230
                        
231
        def setForceCache(self):
232
                self._isFromCache = True
233
                self._isInteractive = False
234
                
235
        def setForceRemote(self):
236
                self._isFromCache = False
237
                self._isInteractive = False
238

    
239
                #after unpacking, the unpack list is freed
240
                
241
PlugInManager().registerPlugIn("DepManUpdatePlugIn",DepManUpdatePlugIn())