[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/ Make getProfileImportDate handle situations where one object's id is a prefix of another id.

Wichert Akkerman wichert at wiggy.net
Wed Mar 12 16:43:34 EDT 2008


Log message for revision 84622:
  Make getProfileImportDate handle situations where one object's id is a prefix of another id.

Changed:
  U   Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
  U   Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py
  U   Products.GenericSetup/trunk/Products/GenericSetup/tool.py

-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt	2008-03-12 18:17:31 UTC (rev 84621)
+++ Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt	2008-03-12 20:43:34 UTC (rev 84622)
@@ -5,6 +5,9 @@
 
   GenericSetup 1.4.0 (unreleased)
 
+    - Make getProfileImportDate handle situations where one object's id
+      is a prefix of another id.
+
     - During object manager imports do not throw an error when
       trying to remove an object that was already removed.
 

Modified: Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py	2008-03-12 18:17:31 UTC (rev 84621)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/test_tool.py	2008-03-12 20:43:34 UTC (rev 84622)
@@ -851,6 +851,21 @@
         self.assertEqual(tool.getProfileImportDate('foo:bar'),
                          '2007-03-15T12:34:56Z')
 
+    def test_getProfileImportDate_id_with_prefix(self):
+        # Test if getProfileImportDate does not fail if there is another
+        # item id with id with a longer id which starts with the same
+        # prefix
+        from OFS.Image import File
+        site = self._makeSite()
+        site.setup_tool = self._makeOne('setup_tool')
+        tool = site.setup_tool
+        filename = 'import-all-foo_bar-20070315123456.log'
+        tool._setObject(filename, File(filename, '', ''))
+        filename2 = 'import-all-foo_bar-boo-20070315123456.log'
+        tool._setObject(filename2, File(filename2, '', ''))
+        self.assertEqual(tool.getProfileImportDate('foo:bar'),
+                         '2007-03-15T12:34:56Z')
+
     def test_profileVersioning(self):
         site = self._makeSite()
         site.setup_tool = self._makeOne('setup_tool')

Modified: Products.GenericSetup/trunk/Products/GenericSetup/tool.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tool.py	2008-03-12 18:17:31 UTC (rev 84621)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tool.py	2008-03-12 20:43:34 UTC (rev 84622)
@@ -764,13 +764,12 @@
         """
         prefix = ('import-all-%s-' % profile_id).replace(':', '_')
         candidates = [x for x in self.objectIds('File')
-                        if x.startswith(prefix)]
+                        if x[:-18]==prefix and x.endswith('.log')]
         if len(candidates) == 0:
             return None
         candidates.sort()
         last = candidates[-1]
-        stamp = last[len(prefix):-4]
-        assert(len(stamp) == 14)
+        stamp = last[-18:-4]
         return '%s-%s-%sT%s:%s:%sZ' % (stamp[0:4],
                                        stamp[4:6],
                                        stamp[6:8],



More information about the Checkins mailing list