svn-gvsig-desktop / branches / v2_0_0_prep / build / buildman / bin / bmplugins / DepManExtractPlugIn.py @ 27642
History | View | Annotate | Download (4.08 KB)
1 | 27363 | rgaitan | 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 DepManExtractPlugIn(IPlugIn): |
||
8 | def __init__(self): |
||
9 | IPlugIn.__init__(self)
|
||
10 | self._xmlFile = "depman.xml" |
||
11 | self._destDir = "." |
||
12 | self._filter = "*"
|
||
13 | self._isFromCache=False |
||
14 | self._isInteractive=True |
||
15 | self._depmanNode = None |
||
16 | |||
17 | def init(self): |
||
18 | self.addGoal("extract", "Extract the files of dependencies and package sections of a depman xml file.") |
||
19 | self.addGoalOption("extract","--file", "Sets an alternate xml file. Default: depman.xml") |
||
20 | self.addGoalOption("extract","--destdir", "Sets the destination directory of the extraction. Default: `.`") |
||
21 | self.addGoalOption("extract","--filter", "Sets the the filter of the files to extract. Default: `*`") |
||
22 | self.addGoalOption("extract","--cache", "Cache is preferred") |
||
23 | self.addGoalOption("extract","--remote", "Remote repository is preferred") |
||
24 | |||
25 | isExtract = False
|
||
26 | if self._arguments.read("extract"): |
||
27 | self.setExecute(True) |
||
28 | isExtract = True
|
||
29 | |||
30 | if not isExtract: |
||
31 | return
|
||
32 | |||
33 | args = [""]
|
||
34 | if self._arguments.read("--file", args): |
||
35 | self._xmlFile = args[0] |
||
36 | |||
37 | args = [""]
|
||
38 | if self._arguments.read("--destdir", args): |
||
39 | self._destDir = args[0] |
||
40 | |||
41 | args = [""]
|
||
42 | if self._arguments.read("--filter", args): |
||
43 | self._filter = args[0] |
||
44 | |||
45 | if self._arguments.read("--cache"): |
||
46 | self._isFromCache = True |
||
47 | self._isInteractive = False |
||
48 | |||
49 | if self._arguments.read("--remote"): |
||
50 | self._isFromCache = False |
||
51 | self._isInteractive = False |
||
52 | |||
53 | def initFromXML(self,node): |
||
54 | if node.localName=="extract": |
||
55 | if node.hasAttributes():
|
||
56 | if node.attributes.has_key("file"): |
||
57 | elf._xmlFile = node.attributes.get("file").value
|
||
58 | if node.attributes.has_key("destdir"): |
||
59 | elf._destDir = node.attributes.get("destdir").value
|
||
60 | if node.attributes.has_key("filter"): |
||
61 | elf._filter = node.attributes.get("filter").value
|
||
62 | foundCache = False
|
||
63 | if node.attributes.has_key("cache"): |
||
64 | value = node.attributes.get("cache").value
|
||
65 | if value == "True" or value == "true": |
||
66 | self._isFromCache = True |
||
67 | self._isInteractive = False |
||
68 | if node.attributes.has_key("remote") and not foundCache: |
||
69 | value = node.attributes.get("remote").value
|
||
70 | if value == "True" or value == "true": |
||
71 | self._isFromCache = False |
||
72 | self._isInteractive = False |
||
73 | else:
|
||
74 | self._depmanNode = node
|
||
75 | |||
76 | def execute(self): |
||
77 | print "Executing Plugin:" + str(self.__class__) |
||
78 | return self.extract() |
||
79 | |||
80 | def extract(self): |
||
81 | self._dmupdate = PlugInManager().getPlugInInstance("DepManUpdatePlugIn") |
||
82 | if self._dmupdate == None: |
||
83 | self.reportError("PlugIn `depman update` not found") |
||
84 | return
|
||
85 | |||
86 | if self._depmanNode == None: |
||
87 | self.loadXMLFile(self._xmlFile) |
||
88 | |||
89 | if not self._isInteractive: |
||
90 | if self._isFromCache: |
||
91 | self._dmupdate.setForceCache()
|
||
92 | else:
|
||
93 | self._dmupdate.setForceRemote()
|
||
94 | |||
95 | dependency_filenamepaths = self._dmupdate.getDependencies(self._depmanNode) |
||
96 | package_namepath = self.parsePackage(self._depmanNode) |
||
97 | print dependency_filenamepaths, self._destDir, self._filter |
||
98 | |||
99 | bmutil = BMUtil() |
||
100 | for file in dependency_filenamepaths: |
||
101 | bmutil.untargzFiltered(file, self._destDir, self._filter) |
||
102 | |||
103 | |||
104 | def parsePackage(self,node): |
||
105 | return "" |
||
106 | |||
107 | |||
108 | PlugInManager().registerPlugIn("DepManExtractPlugIn",DepManExtractPlugIn())
|
||
109 |