Statistics
| Revision:

root / trunk / extensions / ext3Dgui / buildman / bin / bmplugins / DepManUpdatePlugIn.py @ 26254

History | View | Annotate | Download (7.58 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://murray.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
                compiler="none"
116
                arch="none"
117
                ltype="none"
118
                
119
                #os default values
120
                defplatform=self._dmplugin.getOSPlatform()
121
                defarch=self._dmplugin.getOSArch()
122
                defcompiler=self._dmplugin.getOSCompiler()
123
                
124
                #hardcoded default url
125
                #defurl=default_url
126
                
127
                defurl=self._defurl
128
                
129
                unPackList = []
130
                if node.hasAttributes():
131
                    if node.attributes.has_key("url"):
132
                        defurl=node.attributes.get("url").value
133
                
134
                for i in node.childNodes:
135
                    if i.localName=="dependencies":
136
                        url=defurl
137
                        #os default values
138
                        defplatform=self._dmplugin._osplatform
139
                        defarch=self._dmplugin._osarch
140
                        defcompiler=self._dmplugin._oscompiler
141
                        
142
                        if i.hasAttributes():
143
                            if i.attributes.has_key("platform"):
144
                                defplatform=i.attributes.get("platform").value
145
                            if i.attributes.has_key("architecture"):
146
                                defarch=i.attributes.get("architecture").value
147
                            if i.attributes.has_key("compiler"):
148
                                defcompiler=i.attributes.get("compiler").value
149
                            if i.attributes.has_key("url"):
150
                                url=i.attributes.get("url").value
151
                        
152
                        list_of_platforms=defplatform.split(",")
153
                        #depedencies platform checking
154
                        #we just go on whenever host os or all matches
155
                        
156
                        if len(list_of_platforms)>0 and self._dmplugin.getOSPlatform() not in list_of_platforms and "all" not in list_of_platforms:
157
                            invalid_platform=True
158
                        else:
159
                            invalid_platform=False
160
                            defplatform=self._dmplugin.getOSPlatform()
161
                        
162
                        del list_of_platforms[:]
163
                        
164
                        #print "Url: ",url
165
                        if not invalid_platform:
166
                            for j in i.childNodes:
167
                                
168
                                if j.localName=="dependency":
169
                                    #set default values
170
                                    platform=defplatform
171
                                    arch=defarch
172
                                    compiler=defcompiler
173
                                    group="none"
174
                                    artifact="none"
175
                                    version="0"
176
                                    ltype="none"
177
                                    durl = url
178
                                    if j.hasAttributes():
179
                                        if j.attributes.has_key("url"):
180
                                            durl=j.attributes.get("url").value
181
                                    
182
                                    for h in j.childNodes:
183
                                        if h.localName=="group":
184
                                            group=h.childNodes[0].nodeValue
185
                                        if h.localName=="artifact":
186
                                            artifact=h.childNodes[0].nodeValue
187
                                        if h.localName=="version":
188
                                            version=h.childNodes[0].nodeValue
189
                                        if h.localName=="platform":
190
                                            platform=h.childNodes[0].nodeValue
191
                                        if h.localName=="compiler":
192
                                            compiler=h.childNodes[0].nodeValue
193
                                        if h.localName=="architecture":
194
                                            arch=h.childNodes[0].nodeValue
195
                                        if h.localName=="type":
196
                                            ltype=h.childNodes[0].nodeValue
197
                                    self._dmget.setURL(durl)
198
                                    self._dmget.setGroup(group)
199
                                    self._dmget.setArtifact(artifact)
200
                                    self._dmget.setVersion(version)
201
                                    self._dmget.setPlatform(platform)
202
                                    self._dmget.setCompiler(compiler)
203
                                    self._dmget.setArch(arch)
204
                                    self._dmget.setLibraryType(ltype)
205
                                    #prevents downloading of not matching platforms but overrided
206
                                    if not self._isInteractive:
207
                                        if self._isFromCache:
208
                                            self._dmget.setForceCache()
209
                                        else:
210
                                            self._dmget.setForceRemote()
211
                                    self._dmget.get(unPackList)
212
                return unPackList
213
        
214
        def unpack(self,unPackList):
215
                sep=os.path.sep
216
                dmutil = BMUtil()
217
                for file in unPackList:
218
                        tmpstr=file[file.rfind(sep)+1:]
219
                        print "* unpacking ",tmpstr
220
                        dmutil.untargz(file,self._dmplugin.getDepManPath())
221
                        
222
        def setForceCache(self):
223
                self._isFromCache = True
224
                self._isInteractive = False
225
                
226
        def setForceRemote(self):
227
                self._isFromCache = False
228
                self._isInteractive = False
229

    
230
                #after unpacking, the unpack list is freed
231
                
232
PlugInManager().registerPlugIn("DepManUpdatePlugIn",DepManUpdatePlugIn())