40 print 'loading localenv' |
42 print 'loading localenv' |
41 return DBRLocalEnv(location) |
43 return DBRLocalEnv(location) |
42 |
44 |
43 return DBREnv(location) |
45 return DBREnv(location) |
44 |
46 |
45 #Start simple with the filtering... |
47 #Basic DBREnv definition |
46 def CreateFilter(arg): |
|
47 if(os.path.isfile(arg)): |
|
48 return DBRFileFilter(arg) |
|
49 return DBRFilter() |
|
50 |
|
51 class DBREnv: |
48 class DBREnv: |
52 db = dict() |
49 db = dict() |
53 location = '' |
50 location = '' |
54 name = '' |
51 name = '' |
55 def __init__(self, location): |
52 def __init__(self, location): |
89 # print '%s %s %s' % (file, self.db[file]['md5'], other.db[file]['md5'] ) |
86 # print '%s %s %s' % (file, self.db[file]['md5'], other.db[file]['md5'] ) |
90 changed.add(file) |
87 changed.add(file) |
91 touched = touched - unknown |
88 touched = touched - unknown |
92 touched = touched - changed |
89 touched = touched - changed |
93 |
90 |
94 results = DBRCompResults(added, removed, touched, changed, unknown) |
91 results = dbrresults.DBRResults(added, removed, touched, changed, unknown) |
95 return results |
92 return results |
96 |
93 |
97 def verify(self, files): |
94 def verify(self, files): |
98 print 'this is a pure virtual...' |
95 print 'this is a pure virtual...' |
|
96 |
99 def save(self): |
97 def save(self): |
100 print 'this is a pure virtual...' |
98 print 'this is a pure virtual...' |
101 |
99 |
102 def remove(self, files): |
100 def remove(self, files): |
103 for file in files: |
101 for file in files: |
140 if(localfiles.issuperset(files)): |
138 if(localfiles.issuperset(files)): |
141 md5s = dbrutils.generateMD5s(files) |
139 md5s = dbrutils.generateMD5s(files) |
142 for file in files: |
140 for file in files: |
143 self.db[file]['md5'] = md5s[file]['md5'] |
141 self.db[file]['md5'] = md5s[file]['md5'] |
144 |
142 |
|
143 #Creating a DBREnv from scratch... |
145 class DBRNewLocalEnv (DBRLocalEnv): |
144 class DBRNewLocalEnv (DBRLocalEnv): |
146 def __init__(self, location): |
145 def __init__(self, location): |
147 DBRLocalEnv.__init__(self, location) |
146 DBRLocalEnv.__init__(self, location) |
148 #load up local files... |
147 #load up local files... |
149 hashes = glob.glob(os.path.join(dbrutils.patchpath(),'*.md5')) |
148 hashes = glob.glob(os.path.join(dbrutils.patchpath(),'*.md5')) |
154 def save(self): |
153 def save(self): |
155 filename = os.path.join(self.location,dbrutils.defaultdb()) |
154 filename = os.path.join(self.location,dbrutils.defaultdb()) |
156 print 'Saving %s' % filename |
155 print 'Saving %s' % filename |
157 dbrbaseline.writedb(self.db,filename) |
156 dbrbaseline.writedb(self.db,filename) |
158 |
157 |
159 |
|
160 |
|
161 |
158 |
162 #zipped files, contains MD5s. |
159 #zipped files, contains MD5s. |
163 class DBRZippedEnv (DBREnv): |
160 class DBRZippedEnv (DBREnv): |
164 def __init__(self, location): |
161 def __init__(self, location): |
165 DBREnv.__init__(self, location) |
162 DBREnv.__init__(self, location) |
166 #load up zip MD5 and stuff |
163 #load up zip MD5 and stuff |
167 self.db = dbrutils.getzippedDB(self.location) |
164 self.db = dbrutils.getzippedDB(self.location) |
|
165 |
168 |
166 |
169 #Database, but no filesystem access |
167 #Database, but no filesystem access |
170 class DBRBaselineEnv (DBREnv): |
168 class DBRBaselineEnv (DBREnv): |
171 def __init__(self, location): |
169 def __init__(self, location): |
172 DBREnv.__init__(self, location) |
170 DBREnv.__init__(self, location) |
177 |
175 |
178 def save(self): |
176 def save(self): |
179 filename = os.path.join(self.location,dbrutils.defaultdb()) |
177 filename = os.path.join(self.location,dbrutils.defaultdb()) |
180 print 'Saving %s' % filename |
178 print 'Saving %s' % filename |
181 dbrbaseline.writedb(self.db,filename) |
179 dbrbaseline.writedb(self.db,filename) |
|
180 |
182 |
181 |
183 class DBRPatchedBaselineEnv (DBRBaselineEnv): |
182 class DBRPatchedBaselineEnv (DBRBaselineEnv): |
184 patches = [] |
183 patches = [] |
185 baseline = [] |
184 baseline = [] |
186 def __init__(self, location): |
185 def __init__(self, location): |
200 |
199 |
201 |
200 |
202 class CBREnv (DBREnv): # placeholder for handling CBR components... |
201 class CBREnv (DBREnv): # placeholder for handling CBR components... |
203 def __init__(self, location): |
202 def __init__(self, location): |
204 DBREnv.__init__(self, location) |
203 DBREnv.__init__(self, location) |
205 |
|
206 |
|
207 #comparison results... |
|
208 class DBRCompResults: |
|
209 added = set() |
|
210 removed = set() |
|
211 touched = set() |
|
212 changed = set() |
|
213 unknown = set() |
|
214 def __init__(self, added, removed, touched, changed, unknown): |
|
215 #Should probably assert that these are disjoint. |
|
216 self.added = added |
|
217 self.removed = removed |
|
218 self.touched = touched |
|
219 self.changed = changed |
|
220 self.unknown = unknown |
|
221 |
|
222 def printdetail(self): |
|
223 for file in sorted(self.added): |
|
224 print 'added:', file |
|
225 for file in sorted(self.removed): |
|
226 print 'removed:', file |
|
227 for file in sorted(self.changed): |
|
228 print 'changed:', file |
|
229 for file in sorted(self.unknown): |
|
230 print 'unknown:', file |
|
231 |
|
232 def printsummary(self): |
|
233 if(len(self.added | self.removed | self.changed | self.unknown)): |
|
234 print 'status: dirty' |
|
235 else: |
|
236 print 'status: clean' |
|
237 |
|
238 |
|
239 |
|
240 class DBRFilter: |
|
241 info = '' |
|
242 def __init__(self): |
|
243 self.info = 'null filter' |
|
244 def filter(self, results): |
|
245 return results |
|
246 |
|
247 class DBRFileFilter (DBRFilter): |
|
248 filename = '' |
|
249 def __init__(self, filename): |
|
250 DBRFilter.__init__(self) |
|
251 self.info = 'file filter' |
|
252 self.filename = filename |
|
253 self.files = dbrutils.readfilenamesfromfile(self.filename) |
|
254 # for file in sorted(self.files): |
|
255 # print file |
|
256 |
|
257 def filter(self, results): |
|
258 return DBRCompResults(results.added & self.files, results.removed & self.files, results.touched & self.files, results.changed & self.files, results.unknown & self.files) |
|
259 |
|