Statistics
| Revision:

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

History | View | Annotate | Download (5.08 KB)

1
#depman update plugin
2

    
3
from bmbase.IPlugIn import IPlugIn
4
from bmbase.PlugInManager import PlugInManager
5
from bmcore.BMUtil import *
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
                
18
                self._defurl="http://downloads.gvsig.org/pub/gvSIG-desktop/buildman-repository"
19
                self._dependencyList = []
20
                
21
        def init(self):
22
                self.addGoal("update", "Update current project")
23
                self.addGoalOption("update","--cache", "Cache is preferred")
24
                self.addGoalOption("update","--remote", "Remote repository is preferred")
25
                self.addPreGoal("update","depman")
26
                self.addPreGoal("update","clean")
27
                                
28
                if self._arguments.read("update"):
29
                        self.setExecute(True)
30
                        
31
                if self._arguments.read("--cache"):
32
                        self._isInteractive=False
33
                        self._isFromCache = True
34
                
35
                if self._arguments.read("--remote"):
36
                        self._isInteractive=False
37
                        self._isFromCache = False
38

    
39
                self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn")
40
                if self._dmplugin == None:
41
                        self.reportError("PlugIn `depman` not found")
42
                        return
43
                
44
        def initFromXML(self,node):
45
                
46
                defurl=self._defurl
47
                
48
                if node.hasAttributes():
49
                        if node.attributes.has_key("url"):
50
                                defurl=node.attributes.get("url").value
51
                
52
                for i in node.childNodes:
53
                        if i.localName=="dependencies":
54
                                url=defurl
55
                                #os default values
56
                                defplatform=self._dmplugin.getOSPlatform()
57
                                defdistribution=self._dmplugin.getOSDistribution()
58
                                defarch=self._dmplugin.getOSArch()
59
                                defcompiler=self._dmplugin.getOSCompiler()
60
                            
61
                                if i.hasAttributes():
62
                                        if i.attributes.has_key("platform"):
63
                                                defplatform=i.attributes.get("platform").value
64
                                        if i.attributes.has_key("distribution"):
65
                                                defdistribution=i.attributes.get("distribution").value
66
                                        if i.attributes.has_key("architecture"):
67
                                                defarch=i.attributes.get("architecture").value
68
                                        if i.attributes.has_key("compiler"):
69
                                                defcompiler=i.attributes.get("compiler").value
70
                                        if i.attributes.has_key("url"):
71
                                                url=i.attributes.get("url").value
72
                        
73
                                list_of_platforms=defplatform.split(",")
74
                               #depedencies platform checking
75
                        #we just go on whenever host os or all matches
76
                        
77
                                if len(list_of_platforms)>0 and self._dmplugin.getOSPlatform() not in list_of_platforms and "all" not in list_of_platforms:
78
                                        invalid_platform=True
79
                                else:
80
                                        invalid_platform=False
81
                                        defplatform=self._dmplugin.getOSPlatform()
82

    
83
                                del list_of_platforms[:]
84
                        
85
                                if not invalid_platform:
86
                                        for j in i.childNodes:
87
                                                if j.localName=="dependency":
88
                                                        dependency = DepManDependency()                
89
                                                        #set default values
90
                                                        dependency.platform=defplatform
91
                                                        dependency.distribution=defdistribution
92
                                                        dependency.arch=defarch
93
                                                        dependency.compiler=defcompiler
94
                                                        dependency.url = url
95
                                                        if j.hasAttributes():
96
                                                                if j.attributes.has_key("url"):
97
                                                                        dependency.url=j.attributes.get("url").value
98
                                                        for h in j.childNodes:
99
                                                                if h.localName=="group":
100
                                                                        dependency.group=h.childNodes[0].nodeValue
101
                                                                if h.localName=="artifact":
102
                                                                        dependency.artifact=h.childNodes[0].nodeValue
103
                                                                if h.localName=="version":
104
                                                                        dependency.version=h.childNodes[0].nodeValue
105
                                                                if h.localName=="platform":
106
                                                                        dependency.platform=h.childNodes[0].nodeValue
107
                                                                if h.localName=="distribution":
108
                                                                        dependency.distribution=h.childNodes[0].nodeValue
109
                                                                if h.localName=="compiler":
110
                                                                        dependency.compiler=h.childNodes[0].nodeValue
111
                                                                if h.localName=="architecture":
112
                                                                        dependency.arch=h.childNodes[0].nodeValue
113
                                                                if h.localName=="type":
114
                                                                        dependency.libraryType=h.childNodes[0].nodeValue
115
                                                        self._dependencyList.append(dependency)
116
                
117
        def execute(self):
118
                print "Executing Plugin:" + str(self.__class__)
119
                return self.update()
120

    
121
        def update(self):
122
                self.initFromXML(self._dmplugin.getNode())
123
                for i in self._dependencyList:
124
                        print i
125
                unPackList = self.getDependencies()
126
                
127
                #once the xml is parsed and files downloaded, lets unpack them
128
                self.unpack(unPackList)
129
        
130
        def getDependencies(self):
131
                        
132
                self._dmget = PlugInManager().getPlugInInstance("DepManGetPlugIn")
133
                if self._dmget == None:
134
                        self.reportError("PlugIn `depman get` not found")
135
                        return
136
                unPackList = []
137
                for dep in self._dependencyList:
138
                        self._dmget.setDependency(dep)
139
                        #prevents downloading of not matching platforms but overrided
140
                        if not self._isInteractive:
141
                                if self._isFromCache:
142
                                        self._dmget.setForceCache()
143
                                else:
144
                                        self._dmget.setForceRemote()
145
                        self._dmget.get(unPackList)
146
                return unPackList
147
        
148
        def unpack(self,unPackList):
149
                sep=os.path.sep
150
                dmutil = BMUtil()
151
                for file in unPackList:
152
                        tmpstr=file[file.rfind(sep)+1:]
153
                        print "* unpacking ",tmpstr
154
                        dmutil.untargz(file,self._dmplugin.getDepManPath())
155
                        
156
        def setForceCache(self):
157
                self._isFromCache = True
158
                self._isInteractive = False
159
                
160
        def setForceRemote(self):
161
                self._isFromCache = False
162
                self._isInteractive = False
163

    
164
                #after unpacking, the unpack list is freed
165
                
166
PlugInManager().registerPlugIn("DepManUpdatePlugIn",DepManUpdatePlugIn())
167