Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups. DBRToolsDev
authorMattD <mattd@symbian.org>
Sun, 13 Jun 2010 15:29:20 +0100
branchDBRToolsDev
changeset 283 398d483e91bb
parent 245 fd0a8d235c70
child 284 0792141abac7
Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups.
dbrtools/dbr.py
dbrtools/dbr/checkenv.py
dbrtools/dbr/cleanenv.py
dbrtools/dbr/dbrfilter.py
dbrtools/dbr/dbrresults.py
dbrtools/dbr/diffenv.py
dbrtools/dbr/help.py
dbrtools/dbr/intro.py
dbrtools/dbr/smoketest.py
--- a/dbrtools/dbr.py	Wed Apr 21 22:28:52 2010 +0100
+++ b/dbrtools/dbr.py	Sun Jun 13 15:29:20 2010 +0100
@@ -17,19 +17,21 @@
 import os.path
 
 def main():
-    print 'MattD: Need to fix the import path properly!'
+#    print 'MattD: Need to fix the import path properly!'
     dbrpath = os.path.join(os.path.dirname(sys.argv[0]),'dbr')
     sys.path.append(dbrpath)
-    args = sys.argv
+    args = sys.argv[1:]
     if(len(sys.argv)>1):
       cmd = sys.argv[1]
-      args.pop(0)
-      args.pop(0)
+      args = sys.argv[2:]
+#      print sys.argv
   
       if(cmd):
         try:
-            command = __import__ (cmd)
-            command.run(args)        
+#          print cmd
+#          print args
+          command = __import__ (cmd)
+          command.run(args)
         except ImportError:
           help(args)
     else:
@@ -42,5 +44,7 @@
   except ImportError:
     print "error: Cannot find DBR tools help in %s" % dbrpath
                     
+
+
 main()
   
--- a/dbrtools/dbr/checkenv.py	Wed Apr 21 22:28:52 2010 +0100
+++ b/dbrtools/dbr/checkenv.py	Sun Jun 13 15:29:20 2010 +0100
@@ -38,5 +38,6 @@
   print "Usage:"
   print "\tdbr checkenv"
     
-  
+def summary():
+  return "Checks the status of the current environment"
 
--- a/dbrtools/dbr/cleanenv.py	Wed Apr 21 22:28:52 2010 +0100
+++ b/dbrtools/dbr/cleanenv.py	Sun Jun 13 15:29:20 2010 +0100
@@ -60,4 +60,6 @@
   print "Cleans the current environment"
   print "Usage\n\tdbr cleanenv (<baseline_zip_path>)"
   print "\nDefault behaviour presumes baselie zips exist at the root"
-  
\ No newline at end of file
+
+def summary():
+  return "Cleans the current environment"  
\ No newline at end of file
--- a/dbrtools/dbr/dbrfilter.py	Wed Apr 21 22:28:52 2010 +0100
+++ b/dbrtools/dbr/dbrfilter.py	Sun Jun 13 15:29:20 2010 +0100
@@ -151,17 +151,16 @@
       res = dbrresults.DBRResults(set(),set(),set(),set(),set())
       for filter in self.inc:  
         res |= filter.include(results)
-    else:
-      res = results     
-    return res
+        print 'including...'
+      return res
+    return results
     
   def exclude(self, results):
     res = dbrresults.DBRResults(set(),set(),set(),set(),set())
-    if self.exc:
-      res = results
-      for filter in self.exc:
-        res &= filter.exclude(results)
-    return res
+    for filter in self.exc:
+      print 'excluding...'
+      res |= filter.include(results)
+    return results - res
   
   def filter(self, results):
     return self.include(results) & self.exclude(results)
--- a/dbrtools/dbr/dbrresults.py	Wed Apr 21 22:28:52 2010 +0100
+++ b/dbrtools/dbr/dbrresults.py	Sun Jun 13 15:29:20 2010 +0100
@@ -52,6 +52,8 @@
     self.unknown |= other.unknown
     return self
   
+  def __sub__(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 printdetail(self):
     for file in sorted(self.added):
--- a/dbrtools/dbr/diffenv.py	Wed Apr 21 22:28:52 2010 +0100
+++ b/dbrtools/dbr/diffenv.py	Sun Jun 13 15:29:20 2010 +0100
@@ -28,6 +28,7 @@
       db1=dbrenv.CreateDB(first)
       db2=dbrenv.CreateDB(second)
       results = db1.compare(db2)
+#      results.printdetail()
       filteredresults = filter.filter(results)
       filteredresults.printdetail()
       filteredresults.printsummary()
@@ -40,4 +41,5 @@
   print "\tdbr diffenv <drive1> (<drive2>)"
     
   
-
+def summary():
+  return "Compares two baselines"
--- a/dbrtools/dbr/help.py	Wed Apr 21 22:28:52 2010 +0100
+++ b/dbrtools/dbr/help.py	Sun Jun 13 15:29:20 2010 +0100
@@ -14,6 +14,8 @@
 # DBR help - displays the DBR help
 
 import sys
+import os
+import re
 
 def main():
   args = sys.argv
@@ -26,11 +28,42 @@
         tool.help()
       except ImportError:
         print "No help on %s\n" % args[0]
-        usage()
+        getsummary()
     else:
-      usage()
+      getsummary()
+
+def getsummary():
+  debug = 0
+
+  print "Usage:"
+  modules = os.listdir(os.path.join(os.path.dirname(sys.argv[0]),'dbr'))
+  for module in sorted(modules):
+    modname = re.match('(.+)\.py$',module)
+    if(modname):
+      module = modname.group(1)
+      try:
+        tool = __import__(module)
+        str = tool.summary()
+        print "\tdbr %s\t- %s" %(module, str)
+      except ImportError:
+        if(debug):
+          print "Couldn't import %s" % module
+      except AttributeError:
+        if(debug):
+          print "Couldn't find summary in %s" % module
+      except NameError: #if it doesn't work...
+        if(debug):
+          print "%s looks broken" % module
+      except SyntaxError: #if it doesn't work...
+        if(debug):
+          print "%s looks broken" % module
+
+      
+
+
+
+def oldusage():
     
-def usage():    
     print "Usage:"
     print "\tdbr intro\t- basic introduction\n"
 
@@ -47,5 +80,9 @@
     print ""
     print "\tdbr help - help"
     
+
+def summary():
+  return "Displays the help"
+
 def help():
-  print "No help available!"    
\ No newline at end of file
+  getsummary()
\ No newline at end of file
--- a/dbrtools/dbr/intro.py	Wed Apr 21 22:28:52 2010 +0100
+++ b/dbrtools/dbr/intro.py	Sun Jun 13 15:29:20 2010 +0100
@@ -44,3 +44,10 @@
   
   print s1,s2,s3,s4,s5,s6,s7,s8,s9, s10
   
+
+def summary():
+  return "Brief introduction"
+
+def smoketest():
+  print 'OK'
+  
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dbrtools/dbr/smoketest.py	Sun Jun 13 15:29:20 2010 +0100
@@ -0,0 +1,59 @@
+# Copyright (c) 2009 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:
+# DBR help - displays the DBR help
+
+import sys
+import os
+import re
+
+
+def main():
+  args = sys.argv
+  run(args)
+
+def run(args):
+  if(len(args)):
+    for module in args:
+      dosmoketest(module)
+  else:
+    print sys.argv[0]
+    modules = os.listdir(os.path.join(os.path.dirname(sys.argv[0]),'dbr'))
+    for module in sorted(modules):
+      modname = re.match('(.+)\.py$',module)
+      if(modname):
+        module = modname.group(1)
+        dosmoketest(module)
+    
+
+def dosmoketest(module):
+  print "\nTesting %s:" % module
+  try:
+    tool = __import__(module)
+    tool.smoketest()
+  except ImportError:
+    print "Error: Could not load %s" % module
+  except AttributeError:
+    print "Warning: No Smoketest found in %s" % module
+  except SyntaxError:
+    print "Error: Syntax error in %s" % module
+  except NameError:
+    print "Error: Name error in %s" % module
+  
+
+def help():
+  print "Usage:"
+  print "\tdbr smoketest\t- runs the smoketests"
+
+def summary():
+  return "Runs smoketests"
\ No newline at end of file