author | raptorbot <raptorbot@systemstesthead.symbian.intra> |
Mon, 18 Jan 2010 17:03:32 +0000 | |
branch | wip |
changeset 132 | 2022a4abb126 |
parent 20 | d1f6767eec1a |
permissions | -rw-r--r-- |
3 | 1 |
# |
2 |
# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
# All rights reserved. |
|
4 |
# This component and the accompanying materials are made available |
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
|
6 |
# which accompanies this distribution, and is available |
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
# |
|
9 |
# Initial Contributors: |
|
10 |
# Nokia Corporation - initial contribution. |
|
11 |
# |
|
12 |
# Contributors: |
|
13 |
# |
|
14 |
# Description: |
|
15 |
# Filter class for doing CLEAN, CLEANEXPORT and REALLYCLEAN efficiently. |
|
16 |
# |
|
17 |
||
18 |
import os |
|
19 |
import sys |
|
20 |
import tempfile |
|
21 |
import filter_interface |
|
22 |
||
23 |
class FilterClean(filter_interface.Filter): |
|
24 |
||
25 |
def open(self, params): |
|
26 |
"initialise" |
|
27 |
||
28 |
targets = [x.lower() for x in params.targets] |
|
29 |
||
30 |
self.removeExports = ("cleanexport" in targets or "reallyclean" in targets) |
|
31 |
self.removeTargets = ("clean" in targets or "reallyclean" in targets) |
|
32 |
||
33 |
self.ok = True |
|
34 |
||
35 |
# create a temporary file to record all the exports and directories |
|
36 |
# in. We can only remove those after "make" has finished running all |
|
37 |
# the CLEAN targets. |
|
38 |
try: |
|
39 |
self.tmp = tempfile.TemporaryFile() |
|
40 |
except: |
|
41 |
sys.stderr.write("sbs: could not create temporary file for FilterClean\n") |
|
42 |
self.ok = False |
|
43 |
||
44 |
return self.ok |
|
45 |
||
46 |
||
47 |
def write(self, text): |
|
48 |
"process some log text" |
|
49 |
||
50 |
for line in text.splitlines(): |
|
51 |
||
52 |
if self.removeTargets: |
|
53 |
if line.startswith("<file>"): |
|
5 | 54 |
self.doFile(line, "file") |
55 |
elif line.startswith("<build>"): |
|
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") |
|
3 | 63 |
|
64 |
if self.removeExports: |
|
65 |
if line.startswith("<export "): |
|
66 |
self.doExport(line) |
|
67 |
elif line.startswith("<member>"): |
|
5 | 68 |
self.doFile(line, "member") |
3 | 69 |
elif line.startswith("<zipmarker>"): |
5 | 70 |
self.doFile(line, "zipmarker") |
3 | 71 |
|
72 |
return self.ok |
|
73 |
||
74 |
||
75 |
def summary(self): |
|
76 |
"finish off" |
|
77 |
||
78 |
# remove files, remembering directories |
|
79 |
dirs = set() |
|
80 |
||
81 |
try: |
|
82 |
self.tmp.flush() # write what is left in the buffer |
|
83 |
self.tmp.seek(0) # rewind to the beginning |
|
84 |
||
85 |
for line in self.tmp.readlines(): |
|
86 |
path = line.strip() |
|
87 |
||
88 |
if os.path.isfile(path): |
|
89 |
self.removeFile(path) |
|
5 | 90 |
|
91 |
directory = os.path.dirname(path) |
|
92 |
if os.path.isdir(directory): |
|
93 |
dirs.add(directory) |
|
3 | 94 |
|
95 |
self.tmp.close() # this also deletes the temporary file |
|
20
d1f6767eec1a
Tests working with separate test-epocroot.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
5
diff
changeset
|
96 |
except Exception,e: |
d1f6767eec1a
Tests working with separate test-epocroot.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
5
diff
changeset
|
97 |
sys.stderr.write("sbs: problem reading temporary file for FilterClean: %s\n" % str(e)) |
3 | 98 |
self.ok = False |
99 |
||
100 |
# finally remove (empty) directories |
|
101 |
for dir in dirs: |
|
102 |
try: |
|
103 |
os.removedirs(dir) # may fail if the directory has files in |
|
104 |
except: |
|
105 |
pass # silently ignore all errors |
|
106 |
||
107 |
return self.ok |
|
108 |
||
109 |
||
110 |
def close(self): |
|
111 |
"nop" |
|
112 |
||
113 |
return self.ok |
|
114 |
||
115 |
||
116 |
def removeFile(self, path): |
|
117 |
try: |
|
118 |
os.unlink(path) |
|
119 |
except Exception, e: |
|
120 |
sys.stderr.write("sbs: could not remove " + path + "\n") |
|
121 |
sys.stderr.write(str(e) + "\n") |
|
122 |
||
123 |
||
124 |
def saveItem(self, path): |
|
125 |
"put path into a temporary file." |
|
126 |
try: |
|
127 |
self.tmp.write(path + "\n") |
|
128 |
except: |
|
129 |
sys.stderr.write("sbs: could not write temporary file in FilterClean\n") |
|
130 |
self.ok = False |
|
131 |
||
132 |
||
5 | 133 |
def doFile(self, line, tagname): |
134 |
"deal with <tagname>X</tagname>" |
|
3 | 135 |
|
5 | 136 |
first = len(tagname) + 2 # line is "<tagname>filename</tagname> |
137 |
last = -(first + 1) |
|
138 |
filename = line[first:last] |
|
139 |
filename = filename.strip("\"\'") # some names are quoted |
|
140 |
self.saveItem(filename) |
|
141 |
||
3 | 142 |
|
143 |
def doExport(self, line): |
|
5 | 144 |
"deal with <export destination='X' source='Y'/>" |
3 | 145 |
filename = line[21:line.find("'", 21)] |
146 |
self.saveItem(filename) |
|
147 |
||
148 |
||
149 |
# the end |
|
150 |