Statistics
| Revision:

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

History | View | Annotate | Download (2.34 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 BuildManPlugIn(IPlugIn):
8
        def __init__(self):
9
                IPlugIn.__init__(self)
10
                self.reset()
11
        
12
        def getFile(self):
13
                return self._file
14
        
15
        def getGoalList(self):
16
                return self._goalList
17
        
18
        def reset(self):
19
                self._goalList = []
20
                self._file = "buildman.xml"
21

    
22
        def init(self):
23
                self.addGoal("buildman", "executes goals from a buildman file")
24
                self.addGoalOption("buildman","--file", "Sets the file to execute, otherwise search for buildman.xml")
25
                
26
                self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn")
27
                if self._dmplugin == None:
28
                        self.reportError("PlugIn `depman` not found")
29
                        return
30
                isBuildMan = False
31
                while self._arguments.read("buildman"):
32
                        self.setExecute(True)
33
                        isBuildMan = True
34

    
35
                if not isBuildMan:
36
                        return        
37
                
38
                args=[""]
39
                while self._arguments.read("--file",args):
40
                        self._file = args[0]        
41

    
42
        def initFromXML(self,node):        
43
                if node.localName=="buildman":
44
                                for g in node.childNodes:
45
                                        if g.localName == "goals":
46
                                                addGoals = False
47
                                                if g.hasAttributes():
48
                                                        if g.attributes.has_key("platform"):
49
                                                                value = g.attributes.get("platform").value
50
                                                                platforms = value.split(",")
51
                                                                for platform in platforms:
52
                                                                        if platform == self._dmplugin.getOSPlatform():
53
                                                                                addGoals = True
54
                                                else:
55
                                                        addGoals = True
56
                                                if addGoals:
57
                                                        for goalNode in g.childNodes:
58
                                                                #print goalNode.localName, " in ", PlugInManager().supportedGoals(), "?"
59
                                                                if goalNode.localName=="buildman":
60
                                                                        if goalNode.hasAttributes():
61
                                                                                if goalNode.attributes.has_key("file"):
62
                                                                                        self.loadXMLFile(goalNode.attributes.get("file").value)
63
                                                                else:
64
                                                                        if goalNode.localName in PlugInManager().supportedGoals():
65
                                                                                self._goalList.append(goalNode)
66

    
67
        def execute(self):
68
                print "Executing Plugin:" + str(self.__class__)
69
                return self.buildman()
70

    
71
        def buildman(self):
72
                self.loadXMLFile(self._file)
73
                for goal in self._goalList:
74
                        plugin = PlugInManager().getPlugInInstanceByGoal(goal.localName)
75
                        plugin.initFromXML(goal)
76
                        plugin.execute()
77
                        if plugin.error():
78
                                for error in plugin.getErrorMessages():
79
                                        self.reportError(error)
80
                                return False
81
                return True
82

    
83

    
84
PlugInManager().registerPlugIn("BuildManPlugIn",BuildManPlugIn())        
85