49 |
49 |
50 for line in text.splitlines(): |
50 for line in text.splitlines(): |
51 |
51 |
52 if self.removeTargets: |
52 if self.removeTargets: |
53 if line.startswith("<file>"): |
53 if line.startswith("<file>"): |
54 self.doFile(line) |
54 self.doFile(line, "file") |
55 elif line.startswith("<dir>"): |
55 elif line.startswith("<build>"): |
56 self.doDirectory(line) |
56 self.doFile(line, "build") |
|
57 elif line.startswith("<resource>"): |
|
58 self.doFile(line, "resource") |
|
59 elif line.startswith("<bitmap>"): |
|
60 self.doFile(line, "bitmap") |
|
61 elif line.startswith("<stringtable>"): |
|
62 self.doFile(line, "stringtable") |
57 |
63 |
58 if self.removeExports: |
64 if self.removeExports: |
59 if line.startswith("<export "): |
65 if line.startswith("<export "): |
60 self.doExport(line) |
66 self.doExport(line) |
61 elif line.startswith("<member>"): |
67 elif line.startswith("<member>"): |
62 self.doMember(line) |
68 self.doFile(line, "member") |
63 elif line.startswith("<zipmarker>"): |
69 elif line.startswith("<zipmarker>"): |
64 self.doZipMarker(line) |
70 self.doFile(line, "zipmarker") |
65 |
71 |
66 return self.ok |
72 return self.ok |
67 |
73 |
68 |
74 |
69 def summary(self): |
75 def summary(self): |
79 for line in self.tmp.readlines(): |
85 for line in self.tmp.readlines(): |
80 path = line.strip() |
86 path = line.strip() |
81 |
87 |
82 if os.path.isfile(path): |
88 if os.path.isfile(path): |
83 self.removeFile(path) |
89 self.removeFile(path) |
84 |
90 |
85 elif os.path.isdir(path): |
91 directory = os.path.dirname(path) |
86 dirs.add(path) |
92 if os.path.isdir(directory): |
|
93 dirs.add(directory) |
87 |
94 |
88 self.tmp.close() # this also deletes the temporary file |
95 self.tmp.close() # this also deletes the temporary file |
89 except: |
96 except: |
90 sys.stderr.write("sbs: could not access temporary file for FilterClean\n") |
97 sys.stderr.write("sbs: could not access temporary file for FilterClean\n") |
91 self.ok = False |
98 self.ok = False |
121 except: |
128 except: |
122 sys.stderr.write("sbs: could not write temporary file in FilterClean\n") |
129 sys.stderr.write("sbs: could not write temporary file in FilterClean\n") |
123 self.ok = False |
130 self.ok = False |
124 |
131 |
125 |
132 |
126 def doFile(self, line): |
133 def doFile(self, line, tagname): |
127 "remove filenames in <file> tags immediately (not .d or .dep)." |
134 "deal with <tagname>X</tagname>" |
128 filename = line[6:-7] # line is "<file>filename</file> |
135 |
|
136 first = len(tagname) + 2 # line is "<tagname>filename</tagname> |
|
137 last = -(first + 1) |
|
138 filename = line[first:last] |
129 filename = filename.strip("\"\'") # some names are quoted |
139 filename = filename.strip("\"\'") # some names are quoted |
130 |
140 self.saveItem(filename) |
131 # dependency files must be deleted at the end, |
141 |
132 # everything else can be deleted straight away. |
|
133 if filename.endswith(".d") or filename.endswith(".dep"): |
|
134 self.saveItem(filename) |
|
135 else: |
|
136 if os.path.isfile(filename): |
|
137 self.removeFile(filename) |
|
138 |
142 |
139 |
|
140 def doDirectory(self, line): |
|
141 "save directories in <dir> tags for the end." |
|
142 # assuming <dir>X</dir> |
|
143 dirname = line[5:-6] |
|
144 self.saveItem(dirname.strip("\"\'")) |
|
145 |
|
146 |
|
147 def doExport(self, line): |
143 def doExport(self, line): |
148 "save exported files in <export> tags for the end." |
144 "deal with <export destination='X' source='Y'/>" |
149 # assuming <export destination='X' source='Y' /> |
|
150 filename = line[21:line.find("'", 21)] |
145 filename = line[21:line.find("'", 21)] |
151 self.saveItem(filename) |
146 self.saveItem(filename) |
152 |
|
153 |
|
154 def doMember(self, line): |
|
155 "save zip exports in <member> tags for the end." |
|
156 # assuming <member>X</member> |
|
157 filename = line[8:-9] |
|
158 self.saveItem(filename) |
|
159 |
|
160 |
|
161 def doZipMarker(self, line): |
|
162 "Remove file in <zipmarker> tags" |
|
163 # assuming <zipmarker>X</zipmarker> |
|
164 filename = line[11:-12] |
|
165 if os.path.isfile(filename): |
|
166 self.removeFile(filename) |
|
167 |
147 |
168 |
148 |
169 # the end |
149 # the end |
170 |
150 |