[csw-devel] SF.net SVN: gar:[12035] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Dec 20 12:58:12 CET 2010


Revision: 12035
          http://gar.svn.sourceforge.net/gar/?rev=12035&view=rev
Author:   wahwah
Date:     2010-12-20 11:58:12 +0000 (Mon, 20 Dec 2010)

Log Message:
-----------
checkpkg: Bugfix for removing pkg from a catalog

When removing a package from a catalog, don't delete its files, as another
catalog might still contain this package.

Also fixes arguments checking and adds a Catalog object creation.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/checkpkg_lib.py
    csw/mgar/gar/v2/lib/python/package_stats_test.py
    csw/mgar/gar/v2/lib/python/pkgdb.py

Modified: csw/mgar/gar/v2/lib/python/checkpkg_lib.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2010-12-20 11:57:34 UTC (rev 12034)
+++ csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2010-12-20 11:58:12 UTC (rev 12035)
@@ -666,6 +666,7 @@
       raise CatalogDatabaseError(
           "Package %s (%s) is not registered for releases."
           % (sqo_srv4.basename, sqo_srv4.md5_sum))
+    # TODO(maciej): Make sure the package's files are present in the database.
     # Checking for presence of a different srv4 with the same pkginst in the
     # same catalog
     pkginst = sqo_srv4.pkginst
@@ -706,10 +707,9 @@
           m.Srv4FileInCatalog.q.osrel==sqo_osrel,
           m.Srv4FileInCatalog.q.catrel==sqo_catrel,
           m.Srv4FileInCatalog.q.srv4file==sqo_srv4)).getOne()
-    sqo_srv4_in_cat.registered = False
-    # TODO(maciej): Remove all files belonging to that one
-    for cat_file in sqo_srv4_in_cat.srv4file.files:
-      cat_file.destroySelf()
+    # Files belonging to this package should not be removed from the catalog
+    # as the package might be still present in another catalog.
+    sqo_srv4_in_cat.destroySelf()
 
 
 class Catalog(CatalogMixin):

Modified: csw/mgar/gar/v2/lib/python/package_stats_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_stats_test.py	2010-12-20 11:57:34 UTC (rev 12034)
+++ csw/mgar/gar/v2/lib/python/package_stats_test.py	2010-12-20 11:58:12 UTC (rev 12035)
@@ -375,16 +375,22 @@
                     m.Srv4FileInCatalog.q.srv4file==stats)).getOne()
     # At this point, we know that the record is in the db.
     c.RemoveSrv4(stats, 'SunOS5.9', 'i386', 'unstable')
-    # Retrieved record from the db should now not have the registered flag.
-    # We could also test that the object should not have any files attached to
-    # it.
-    updated_stats = m.Srv4FileInCatalog.select(
+    # Make sure that the Srv4FileInCatalog object is now gone.
+    res = m.Srv4FileInCatalog.select(
         sqlobject.AND(
           m.Srv4FileInCatalog.q.arch==sqo_arch,
           m.Srv4FileInCatalog.q.osrel==sqo_osrel,
           m.Srv4FileInCatalog.q.catrel==sqo_catrel,
-          m.Srv4FileInCatalog.q.srv4file==stats)).getOne()
-    self.assertFalse(updated_stats.registered)
+          m.Srv4FileInCatalog.q.srv4file==stats))
+    self.assertRaises(sqlobject.SQLObjectNotFound, res.getOne)
+    # Retrieved record from the db should now not have the registered flag.
+    updated_stats = m.Srv4FileStats.select(
+        m.Srv4FileStats.q.id==stats.id).getOne()
+    self.assertTrue(updated_stats.registered)
+    # Make sure that files of this package are still in the database.
+    res = m.CswFile.select(
+        m.CswFile.q.srv4_file==updated_stats)
+    self.assertEquals(22, res.count())
 
 
   def testRetrievePathsMatchCatalog(self):

Modified: csw/mgar/gar/v2/lib/python/pkgdb.py
===================================================================
--- csw/mgar/gar/v2/lib/python/pkgdb.py	2010-12-20 11:57:34 UTC (rev 12034)
+++ csw/mgar/gar/v2/lib/python/pkgdb.py	2010-12-20 11:58:12 UTC (rev 12035)
@@ -381,13 +381,16 @@
         logging.warning("Srv4 file %s was not found in the database.",
                         md5_sum)
   elif command == 'del-from-cat':
-    if len(args) <= 4:
+    if len(args) < 4:
       raise UsageError("Not enough arguments, see usage.")
     osrel, arch, catrel= args[:3]
     md5_sums = args[3:]
+    c = checkpkg_lib.Catalog()
     for md5_sum in md5_sums:
       sqo_srv4 = m.Srv4FileStats.select(
           m.Srv4FileStats.q.md5_sum==md5_sum).getOne()
+      logging.debug("Removing %s from %s %s %s",
+                    sqo_srv4, osrel, arch, catrel)
       c.RemoveSrv4(sqo_srv4, osrel, arch, catrel)
   elif command == 'system-files-to-file':
     logging.debug("Args: %s", args)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list