DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
--- a/dbrtools/dbr/checkenv.py Wed Mar 24 16:43:43 2010 +0000
+++ b/dbrtools/dbr/checkenv.py Mon Apr 19 22:50:19 2010 +0100
@@ -14,19 +14,19 @@
# new checkenv - uses OO interface.
import dbrenv
+import dbrfilter
def run(args):
location = '/'
filtertype = ''
#using arg for filter...not for other env
- if(len(args)):
- filtertype = args[0]
+
db = dbrenv.CreateDB(location)
local = dbrenv.DBRLocalEnv(location)
results = db.compare(local)
local.verify(results.unknown)
results2 = db.compare(local)
- filter = dbrenv.CreateFilter(filtertype)
+ filter = dbrfilter.CreateFilter(args)
filteredresults = filter.filter(results2)
filteredresults.printdetail()
filteredresults.printsummary()
--- a/dbrtools/dbr/dbrenv.py Wed Mar 24 16:43:43 2010 +0000
+++ b/dbrtools/dbr/dbrenv.py Mon Apr 19 22:50:19 2010 +0100
@@ -21,6 +21,8 @@
import dbrbaseline
import dbrpatch
+import dbrresults
+import dbrfilter
def CreateDB(location): #virtual constructor
print location
@@ -42,12 +44,7 @@
return DBREnv(location)
-#Start simple with the filtering...
-def CreateFilter(arg):
- if(os.path.isfile(arg)):
- return DBRFileFilter(arg)
- return DBRFilter()
-
+#Basic DBREnv definition
class DBREnv:
db = dict()
location = ''
@@ -91,11 +88,12 @@
touched = touched - unknown
touched = touched - changed
- results = DBRCompResults(added, removed, touched, changed, unknown)
+ results = dbrresults.DBRResults(added, removed, touched, changed, unknown)
return results
def verify(self, files):
print 'this is a pure virtual...'
+
def save(self):
print 'this is a pure virtual...'
@@ -142,6 +140,7 @@
for file in files:
self.db[file]['md5'] = md5s[file]['md5']
+#Creating a DBREnv from scratch...
class DBRNewLocalEnv (DBRLocalEnv):
def __init__(self, location):
DBRLocalEnv.__init__(self, location)
@@ -156,8 +155,6 @@
print 'Saving %s' % filename
dbrbaseline.writedb(self.db,filename)
-
-
#zipped files, contains MD5s.
class DBRZippedEnv (DBREnv):
@@ -165,6 +162,7 @@
DBREnv.__init__(self, location)
#load up zip MD5 and stuff
self.db = dbrutils.getzippedDB(self.location)
+
#Database, but no filesystem access
class DBRBaselineEnv (DBREnv):
@@ -180,6 +178,7 @@
print 'Saving %s' % filename
dbrbaseline.writedb(self.db,filename)
+
class DBRPatchedBaselineEnv (DBRBaselineEnv):
patches = []
baseline = []
@@ -202,58 +201,3 @@
class CBREnv (DBREnv): # placeholder for handling CBR components...
def __init__(self, location):
DBREnv.__init__(self, location)
-
-
-#comparison results...
-class DBRCompResults:
- added = set()
- removed = set()
- touched = set()
- changed = set()
- unknown = set()
- def __init__(self, added, removed, touched, changed, unknown):
- #Should probably assert that these are disjoint.
- self.added = added
- self.removed = removed
- self.touched = touched
- self.changed = changed
- self.unknown = unknown
-
- def printdetail(self):
- for file in sorted(self.added):
- print 'added:', file
- for file in sorted(self.removed):
- print 'removed:', file
- for file in sorted(self.changed):
- print 'changed:', file
- for file in sorted(self.unknown):
- print 'unknown:', file
-
- def printsummary(self):
- if(len(self.added | self.removed | self.changed | self.unknown)):
- print 'status: dirty'
- else:
- print 'status: clean'
-
-
-
-class DBRFilter:
- info = ''
- def __init__(self):
- self.info = 'null filter'
- def filter(self, results):
- return results
-
-class DBRFileFilter (DBRFilter):
- filename = ''
- def __init__(self, filename):
- DBRFilter.__init__(self)
- self.info = 'file filter'
- self.filename = filename
- self.files = dbrutils.readfilenamesfromfile(self.filename)
-# for file in sorted(self.files):
-# print file
-
- def filter(self, results):
- return DBRCompResults(results.added & self.files, results.removed & self.files, results.touched & self.files, results.changed & self.files, results.unknown & self.files)
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dbrtools/dbr/dbrfilter.py Mon Apr 19 22:50:19 2010 +0100
@@ -0,0 +1,166 @@
+# Copyright (c) 2010 Symbian Foundation Ltd
+# This component and the accompanying materials are made available
+# under the terms of the License "Eclipse Public License v1.0"
+# which accompanies this distribution, and is available
+# at the URL "http://www.eclipse.org/legal/epl-v10.html".
+#
+# Initial Contributors:
+# Symbian Foundation Ltd - initial contribution.
+#
+# Contributors:
+# mattd <mattd@symbian.org>
+#
+# Description:
+# DBRFilter - DBR Filtering classes
+
+import dbrresults
+import dbrutils
+import re
+
+from optparse import OptionParser
+
+def CreateFilter(args):
+# print args
+
+ parser = OptionParser()
+ parser.add_option('-i', '--iregex', dest='iregex', action='append')
+ parser.add_option('-x', '--xregex', dest='xregex', action='append')
+ parser.add_option('-@', '--ifile', dest='ifile', action='append')
+ parser.add_option('-!', '--xfile', dest='xfile', action='append')
+
+# if(os.path.isfile(arg)):
+# return DBRFileFilterInclude(args)
+# return DBRRegexFileFilterExclude(args)
+ (options, args) = parser.parse_args(args)
+# print options
+ filter = DBRComplexFilter()
+ if options.iregex:
+ for include in options.iregex:
+ filter.addInclude(DBRRegexFileFilter(include))
+ if options.ifile:
+ for include in options.ifile:
+ filter.addInclude(DBRFileFilter(include))
+ if options.xregex:
+ for exclude in options.xregex:
+ filter.addExclude(DBRRegexFileFilter(exclude))
+ if options.xfile:
+ for exclude in options.xfile:
+ filter.addExclude(DBRFileFilter(exclude))
+
+ return filter
+
+
+class DBRFilter:
+ info = ''
+ def __init__(self):
+ self.info = 'Null Filter'
+ def filter(self, results):
+ return results
+ def include(self, results):
+ return set()
+ def exclude(self, results):
+ return results
+
+
+class DBRFileFilter (DBRFilter):
+ filename = ''
+ def __init__(self, filename):
+ DBRFilter.__init__(self)
+ self.filename = filename
+ self.files = dbrutils.readfilenamesfromfile(self.filename)
+# for file in sorted(self.files):
+# print file
+
+ def include(self, results):
+ return dbrresults.DBRResults(results.added & self.files, results.removed & self.files, results.touched & self.files, results.changed & self.files, results.unknown & self.files)
+ def exclude(self, results):
+ return dbrresults.DBRResults(results.added - self.files, results.removed - self.files, results.touched - self.files, results.changed - self.files, results.unknown - self.files)
+
+class DBRFileFilterInclude (DBRFileFilter):
+ def __init__(self, filename):
+ DBRFileFilter.__init__(self, filename)
+ def filter(self, results):
+ return self.include(results)
+
+class DBRFileFilterExclude (DBRFileFilter):
+ def __init__(self, filename):
+ DBRFileFilter.__init__(self, filename)
+ def filter(self, results):
+ return self.exclude(results)
+
+class DBRRegexFileFilter (DBRFilter):
+ regex = ''
+ def __init__(self, regex):
+ DBRFilter.__init__(self)
+ #This can throw a compiler error. It would be nicer to have this display help.
+ try:
+ self.regex = re.compile(regex, re.IGNORECASE) # doing case-insensitive regexes at the moment
+ except re.error:
+ print 'WARNING: Bad Regular Expression:%s', regex
+ self.regex = re.compile('')
+
+ #might be able to do this nicer using 'itertools'
+ def inc(self, files):
+ results = set()
+ for candidate in files:
+ if self.regex.search(candidate):
+ results.add(candidate)
+ return results
+
+ def exc(self, files):
+ results = set()
+ for candidate in files:
+ if not self.regex.search(candidate):
+ results.add(candidate)
+ return results
+
+ def include(self, results):
+ return dbrresults.DBRResults(self.inc(results.added), self.inc(results.removed), self.inc(results.touched), self.inc(results.changed), self.inc(results.unknown))
+
+ def exclude(self, results):
+ return dbrresults.DBRResults(self.exc(results.added), self.exc(results.removed), self.exc(results.touched), self.exc(results.changed), self.exc(results.unknown))
+
+class DBRRegexFileFilterInclude (DBRRegexFileFilter):
+ def __init__(self, regex):
+ DBRRegexFileFilter.__init__(self, regex)
+ def filter(self, results):
+ return self.include(results)
+
+class DBRRegexFileFilterExclude (DBRRegexFileFilter):
+ def __init__(self, regex):
+ DBRRegexFileFilter.__init__(self, regex)
+ def filter(self, results):
+ return self.exclude(results)
+
+class DBRComplexFilter (DBRFilter):
+ exc = set()
+ inc = set()
+ def __init__(self):
+ DBRFilter.__init__(self)
+ self.exc = set()
+ self.inc = set()
+
+ def addInclude(self, filter):
+ self.inc.add(filter)
+
+ def addExclude(self, filter):
+ self.exc.add(filter)
+
+ def include(self, results):
+ res = dbrresults.DBRResults(set(),set(),set(),set(),set())
+ if self.inc:
+ for filter in self.inc:
+ res |= filter.include(results)
+ return res
+
+ def exclude(self, results):
+ res = results
+ if self.exc:
+ for filter in self.exc:
+ res &= filter.exclude(results)
+ return res
+
+ def filter(self, results):
+ return self.include(results) | self.exclude(results)
+
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dbrtools/dbr/dbrresults.py Mon Apr 19 22:50:19 2010 +0100
@@ -0,0 +1,70 @@
+# Copyright (c) 2010 Symbian Foundation Ltd
+# This component and the accompanying materials are made available
+# under the terms of the License "Eclipse Public License v1.0"
+# which accompanies this distribution, and is available
+# at the URL "http://www.eclipse.org/legal/epl-v10.html".
+#
+# Initial Contributors:
+# Symbian Foundation Ltd - initial contribution.
+#
+# Contributors:
+# mattd <mattd@symbian.org>
+#
+# Description:
+# DBRResults - DBR Comparison results classes
+
+
+
+class DBRResults:
+ added = set()
+ removed = set()
+ touched = set()
+ changed = set()
+ unknown = set()
+
+ def __init__(self, added, removed, touched, changed, unknown):
+ #Should probably assert that these are disjoint.
+ self.added = added
+ self.removed = removed
+ self.touched = touched
+ self.changed = changed
+ self.unknown = unknown
+
+ def __rand__(self, other):
+ return DBRResults(self.added & other.added, self.removed & other.removed, self.touched & other.touched, self.changed & other.changed, self.unknown & other.unknown)
+
+ def __iand__(self, other):
+ self.added &= other.added
+ self.removed &= other.removed
+ self.touched &= other.touched
+ self.changed &= other.changed
+ self.unknown &= other.unknown
+ return self
+
+ def __ror__(self, other):
+ return DBRResults(self.added | other.added, self.removed | other.removed, self.touched | other.touched, self.changed | other.changed, self.unknown | other.unknown)
+
+ def __ior__(self, other):
+ self.added |= other.added
+ self.removed |= other.removed
+ self.touched |= other.touched
+ self.changed |= other.changed
+ self.unknown |= other.unknown
+ return self
+
+
+ def printdetail(self):
+ for file in sorted(self.added):
+ print 'added:', file
+ for file in sorted(self.removed):
+ print 'removed:', file
+ for file in sorted(self.changed):
+ print 'changed:', file
+ for file in sorted(self.unknown):
+ print 'unknown:', file
+
+ def printsummary(self):
+ if(len(self.added | self.removed | self.changed | self.unknown)):
+ print 'status: dirty'
+ else:
+ print 'status: clean'
--- a/dbrtools/dbr/diffenv.py Wed Mar 24 16:43:43 2010 +0000
+++ b/dbrtools/dbr/diffenv.py Mon Apr 19 22:50:19 2010 +0100
@@ -14,22 +14,20 @@
# new diffenv - uses OO interface and can have
import dbrenv
+import dbrfilter
def run(args):
if(len(args)):
- filtertype = ''
if(len(args) == 1):
first = '/'
- second = args[0]
+ second = args.pop(0)
else:
- first = args[0]
- second = args[1]
- if(len(args) == 3):
- filtertype = args[2]
+ first = args.pop(0)
+ second = args.pop(0)
+ filter = dbrfilter.CreateFilter(args)
db1=dbrenv.CreateDB(first)
db2=dbrenv.CreateDB(second)
results = db1.compare(db2)
- filter = dbrenv.CreateFilter(filtertype)
filteredresults = filter.filter(results)
filteredresults.printdetail()
filteredresults.printsummary()