Actions

icon Post
text/html Subscribe
text/html Unsubscribe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch: Enhance MountDatabase


  • To: qmtest@xxxxxxxxxxxxxxxx
  • Subject: patch: Enhance MountDatabase
  • From: Stefan Seefeld <stefan@xxxxxxxxxxxxxxxx>
  • Date: Wed, 19 Sep 2007 13:25:35 -0400

The attached patch enhances the MountDatabase by allowing to
specify sub-databases not directly stored as sub-directories
of the database directory.

The field used to represent the mount points is a DictionaryField.
As DictionaryFields can't be represented as text yet, there is
no way to create MountDatabases with that parameter on the
command line. Instead, the extension (XML) file for it needs to
be edited manually.

In addition to this new feature, the patch fixes the MountDatabase.GetIds()
method.

Thanks,
		Stefan

-- 
Stefan Seefeld
CodeSourcery
stefan@xxxxxxxxxxxxxxxx
(650) 331-3385 x718
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 1009)
+++ ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2007-09-19  Stefan Seefeld  <stefan@xxxxxxxxxxxxxxxx>
+
+	* qm/test/classes/mount_database.py: Add support for 'mounts' parameter,
+	  fix GetIds() method.
+	* tests/QMTest/configuration: Adjust.
+	* qm/fields.py: Fix various issues with DictionaryField and SetField.
+
 2007-08-17  Stefan Seefeld  <stefan@xxxxxxxxxxxxxxxx>
 
 	* qm/test/classes/python.py: Expect new-style exceptions (python 2.5).
Index: qm/test/classes/mount_database.py
===================================================================
--- qm/test/classes/mount_database.py	(revision 1004)
+++ qm/test/classes/mount_database.py	(working copy)
@@ -19,6 +19,7 @@
 import os.path
 from   qm.test.database import *
 from   qm.test.suite import Suite
+from   qm.fields import *
 import qm.test.database
 
 ########################################################################
@@ -66,26 +67,46 @@
             return map(self.__joiner, self.__suite.GetSuiteIds())
 
 
+    mounts = DictionaryField(key_field = TextField(),
+                             value_field = TextField(),
+                             description=\
+                """Dictionary mapping mount points to (sub-)database paths.
+                If empty, the database directory is scanned for subdirectories.""")
 
+
     def __init__(self, path, arguments):
 
         # The label class used by the MountDatabase is the label class
         # used by the databases it contains.  They must all use the
         # same label class.
         label_class = None
-        
+        implicit = False
         # Find the contained databases.
+        self.mounts = arguments.pop('mounts', {})
         self._mounts = {}
-        for d in dircache.listdir(path):
-            mounted_db_path = os.path.join(path, d)
-            if is_database(mounted_db_path):
-                db = load_database(mounted_db_path)
-                self._mounts[d] = db
+        if not self.mounts:
+            # Scan local directory.
+            implicit = True
+            self.mounts = dict([(d, os.path.join(path, d))
+                                for d in dircache.listdir(path)])
+        else:
+            # Translate relative paths into absolute paths.
+            tmp = {}
+            for k,v in self.mounts.iteritems():
+                tmp[k] = os.path.join(path, v)
+            self.mounts = tmp
+        # Now translate the value from path to database
+        for k,v in self.mounts.iteritems():
+            if is_database(v):
+                db = load_database(v)
+                self._mounts[k] = db
                 if not label_class:
                     label_class = db.label_class
                 elif label_class != db.label_class:
                     raise QMException, \
                           "mounted databases use differing label classes"
+            elif not implicit:
+                raise QMException, "%s does not contain a test database"%v
                                    
         # Initialize the base class.
         arguments["modifiable"] = "false"
@@ -98,17 +119,16 @@
         
     def GetIds(self, kind, directory="", scan_subdirs=1):
 
-        if directory == "":
-            if kind == Database.SUITE:
-                return self._mounts.keys()
-            else:
-                return []
-        
-        database, joiner, directory = self._SelectDatabase(directory)
-        return map(joiner,
-                   database.GetIds(kind, directory, scan_subdirs))
+        ids = []
+        if directory == "" and kind == Database.SUITE:
+                ids.extend(self._mounts.keys())
+        if scan_subdirs:
+            dirs = directory and [directory] or self._mounts.keys()
+            for d in dirs:
+                database, joiner, subdir = self._SelectDatabase(d)
+                ids += [joiner(i) for i in database.GetIds(kind, subdir, 1)]
+        return ids
 
-
     def GetTest(self, test_id):
 
         joiner, contained_test \
Index: tests/QMTest/configuration
===================================================================
--- tests/QMTest/configuration	(revision 1004)
+++ tests/QMTest/configuration	(working copy)
@@ -1,2 +1,10 @@
 <?xml version="1.0" ?>
-<tdb-configuration><class-name>mount_database.MountDatabase</class-name></tdb-configuration>
+<extension class="mount_database.MountDatabase" kind="database">
+  <argument name="mounts">
+    <dictionary>
+      <item><text>xmldb</text><text>/home/stefan/work/qmtest/tests/xmldb</text></item>
+      <item><text>regress</text><text>regress</text></item>
+      <item><text>results_files</text><text>results_files</text></item>
+    </dictionary>
+  </argument>
+</extension>
Index: qm/fields.py
===================================================================
--- qm/fields.py	(revision 1004)
+++ qm/fields.py	(working copy)
@@ -840,6 +840,9 @@
         %s"""%(self.__key_field.GetHelp(), self.__value_field.GetHelp())
         return help
 
+    
+    def GetKeyField(self): return self.__key_field
+    def GetValueField(self): return self.__value_field
 
     ### Output methods.
 
@@ -988,10 +991,11 @@
 
         values = {}
         for item in node.childNodes:
-            values[self.__key_field.GetValueFromDomNode(item.childNodes[0],
-                                                        attachment_store)] =\
-            self.__value_field.GetValueFromDomNode(item.childNodes[1],
-                                                   attachment_store)
+            if item.nodeType == xml.dom.Node.ELEMENT_NODE:
+                values[self.__key_field.GetValueFromDomNode
+                       (item.childNodes[0], attachment_store)] =\
+                       self.__value_field.GetValueFromDomNode(item.childNodes[1],
+                                                              attachment_store)
         return self.Validate(values)
     
 
@@ -1021,11 +1025,13 @@
 
         raises -- 'TypeError' if 'contained' is not a 'Field'."""
 
+        if not properties.has_key('description'):
+            properties['description'] = contained.GetDescription()
+
         super(SetField, self).__init__(
             contained.GetName(),
             default_value or [],
             title = contained.GetTitle(),
-            description = contained.GetDescription(),
             **properties)
 
         # A set field may not contain a set field.