Embryonic support for filtering. Can now use a file list with diffenv to filter the results.
authorMattD <mattd@symbian.org>
Mon, 22 Mar 2010 11:35:04 +0000
changeset 208 01c2b1268053
parent 206 2fd92922bf5c
child 209 97a2261627a2
Embryonic support for filtering. Can now use a file list with diffenv to filter the results.
dbrtools/dbr/dbrenv.py
dbrtools/dbr/dbrutils.py
dbrtools/dbr/diffenv.py
--- a/dbrtools/dbr/dbrenv.py	Wed Mar 17 13:34:22 2010 +0000
+++ b/dbrtools/dbr/dbrenv.py	Mon Mar 22 11:35:04 2010 +0000
@@ -25,7 +25,7 @@
 def CreateDB(location): #virtual constructor
   print location
 #  print dbrutils.patch_path_internal()
-  if(os.path.exists(os.path.join(location,dbrutils.defaultdb()))):
+  if(os.path.isfile(os.path.join(location,dbrutils.defaultdb()))):
 #    print 'loading baseline environment'
 #    return DBRBaselineEnv(location)
     print 'loading patched baseline environment'
@@ -42,7 +42,11 @@
 
   return DBREnv(location)
 
-
+#Start simple with the filtering...
+def CreateFilter(arg):
+  if(os.path.isfile(arg)):
+    return DBRFileFilter(arg)
+  return DBRFilter()     
 
 class DBREnv:
   db = dict()
@@ -230,4 +234,26 @@
       print 'status: dirty'
     else:
       print 'status: clean' 
-                     
\ No newline at end of file
+
+
+
+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)
+    
--- a/dbrtools/dbr/dbrutils.py	Wed Mar 17 13:34:22 2010 +0000
+++ b/dbrtools/dbr/dbrutils.py	Mon Mar 22 11:35:04 2010 +0000
@@ -258,3 +258,18 @@
   #            env[fn] = data
     print '\n'
     return env
+
+def readfilenamesfromfile(filename):
+  files = set()
+  f = open(filename, 'r')
+
+  fixpath = re.compile('\\\\')
+  leadingslash = re.compile('^%s' % fixpath.sub('/',epocroot()))
+  newline = re.compile('\n')
+  for line in f:
+    line = newline.sub('',line)
+    name = string.lower(leadingslash.sub('',fixpath.sub('/',line)))  
+    files.add(name)
+  f.close()  
+  return files
+
--- a/dbrtools/dbr/diffenv.py	Wed Mar 17 13:34:22 2010 +0000
+++ b/dbrtools/dbr/diffenv.py	Mon Mar 22 11:35:04 2010 +0000
@@ -17,17 +17,22 @@
 
 def run(args):
     if(len(args)):
+      filtertype = ''
       if(len(args) == 1):
         first = '/'
         second = args[0]
       else:
         first = args[0]
-        second = args[1]    
+        second = args[1]
+      if(len(args) == 3):
+        filtertype = args[2]    
       db1=dbrenv.CreateDB(first)
       db2=dbrenv.CreateDB(second)
       results = db1.compare(db2)
-      results.printdetail()
-      results.printsummary()
+      filter = dbrenv.CreateFilter(filtertype)
+      filteredresults = filter.filter(results)
+      filteredresults.printdetail()
+      filteredresults.printsummary()
     else:
       help()