[csw-devel] SF.net SVN: gar:[14117] csw/mgar/gar/v2/lib/python
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Sun Apr 10 12:23:31 CEST 2011
Revision: 14117
http://gar.svn.sourceforge.net/gar/?rev=14117&view=rev
Author: wahwah
Date: 2011-04-10 10:23:30 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
csw-upload-pkg: Sort filenames according to OS rel
When a bulk of files is uploaded, e.g. SunOS5.9 and SunOS5.10 files are
uploaded together, SunOS5.9 files are lexicographically last. In
certain operation it's better to have them sorted according to the OS
release. The typical usage scenario is when there are only 5.9 packages
in the database, and we're uploading a mix of 5.9 and 5.10 packages.
Without this sorting, only 5.9 would be in the catalog in result. The
5.10 packages would be initially inserted into the database, but then
they would be overwritten by 5.9 packages.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/csw_upload_pkg.py
csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py
Modified: csw/mgar/gar/v2/lib/python/csw_upload_pkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/csw_upload_pkg.py 2011-04-10 10:22:54 UTC (rev 14116)
+++ csw/mgar/gar/v2/lib/python/csw_upload_pkg.py 2011-04-10 10:23:30 UTC (rev 14117)
@@ -466,7 +466,28 @@
by_catalog[key].append((filename, md5_sum))
return by_catalog
+ def SortFilenames(self, filenames):
+ """Sorts filenames according to OS release.
+ The idea is that in lexicographic sorting, SunOS5.9 is after
+ SunOS5.10, while we want 5.9 to be first.
+ """
+ by_osrel = {}
+ sorted_filenames = []
+ for filename in filenames:
+ basename = os.path.basename(filename)
+ parsed_basename = opencsw.ParsePackageFileName(basename)
+ by_osrel.setdefault(parsed_basename["osrel"], []).append(filename)
+ for osrel in common_constants.OS_RELS:
+ if osrel in by_osrel:
+ for filename in by_osrel.pop(osrel):
+ sorted_filenames.append(filename)
+ if by_osrel:
+ raise DataError("Unexpected architecture found in file list: %s."
+ % (repr(by_osrel),))
+ return sorted_filenames
+
+
if __name__ == '__main__':
parser = optparse.OptionParser(USAGE)
parser.add_option("-d", "--debug",
Modified: csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py 2011-04-10 10:22:54 UTC (rev 14116)
+++ csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py 2011-04-10 10:23:30 UTC (rev 14117)
@@ -327,6 +327,35 @@
('bar.pkg', '84b409eb7c2faf87e22ee0423e55b888')]}
self.assertEqual(expected, su._CheckpkgSets(TEST_PLANNED_MODIFICATIONS_1))
+ def testSortFilenames(self):
+ su = csw_upload_pkg.Srv4Uploader(None, None)
+ wrong_order = [
+ "gdb-7.2,REV=2011.01.21-SunOS5.9-i386-CSW.pkg.gz",
+ "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
+ "gdb-7.2,REV=2011.01.21-SunOS5.10-i386-CSW.pkg.gz",
+ "gdb-7.2,REV=2011.01.21-SunOS5.10-sparc-CSW.pkg.gz",
+ ]
+ good_order = [
+ "gdb-7.2,REV=2011.01.21-SunOS5.9-i386-CSW.pkg.gz",
+ "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
+ "gdb-7.2,REV=2011.01.21-SunOS5.10-i386-CSW.pkg.gz",
+ "gdb-7.2,REV=2011.01.21-SunOS5.10-sparc-CSW.pkg.gz",
+ ]
+ self.assertEqual(good_order, su.SortFilenames(wrong_order))
+ def testSortFilenamesThrowsDataError(self):
+ su = csw_upload_pkg.Srv4Uploader(None, None)
+ wrong_order = [
+ "gdb-7.2,REV=2011.01.21-kittens-i386-CSW.pkg.gz",
+ "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
+ "gdb-7.2,REV=2011.01.21-SunOS5.10-i386-CSW.pkg.gz",
+ "gdb-7.2,REV=2011.01.21-SunOS5.10-sparc-CSW.pkg.gz",
+ ]
+ self.assertRaises(
+ csw_upload_pkg.DataError,
+ su.SortFilenames,
+ wrong_order)
+
+
if __name__ == '__main__':
unittest.main()
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