[csw-devel] SF.net SVN: gar:[17413] csw/mgar/gar/v2/lib/python
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Thu Mar 15 11:52:02 CET 2012
Revision: 17413
http://gar.svn.sourceforge.net/gar/?rev=17413&view=rev
Author: wahwah
Date: 2012-03-15 10:52:02 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
integrate-catalogs: Discern vers and REV changes
When stabilizing a catalog, we want to push new package revision, but no
version changes. When comparing catalogs, discern between version and revision
upgrades. When generating the shell script, do annotate which one it is in the
comments, to that it's easy to grep through the file and find all the revision
updates.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/catalog.py
csw/mgar/gar/v2/lib/python/catalog_test.py
csw/mgar/gar/v2/lib/python/integrate_catalogs.py
Modified: csw/mgar/gar/v2/lib/python/catalog.py
===================================================================
--- csw/mgar/gar/v2/lib/python/catalog.py 2012-03-15 10:51:29 UTC (rev 17412)
+++ csw/mgar/gar/v2/lib/python/catalog.py 2012-03-15 10:52:02 UTC (rev 17413)
@@ -3,6 +3,7 @@
import os
import re
import logging
+import opencsw
class Error(Exception):
@@ -202,5 +203,29 @@
updated_catalognames.add(catalogname)
new_pkgs = [bc_b[x] for x in new_catalognames]
removed_pkgs = [bc_a[x] for x in removed_catalognames]
- updated_pkgs = [{"from": bc_a[x], "to": bc_b[x]} for x in updated_catalognames]
+ def UpdateData(_bc_a, _bc_b, catalogname):
+ a = bc_a[x]
+ b = bc_b[x]
+ cmp_result = opencsw.CompareVersions(
+ a["version"],
+ b["version"])
+ if cmp_result < 0:
+ direction = "upgrade"
+ else:
+ direction = "downgrade"
+ return {
+ "from": a,
+ "to": b,
+ "type": self.DiffType(a, b),
+ "direction": direction,
+ }
+ updated_pkgs = [UpdateData(bc_a, bc_b, x) for x in updated_catalognames]
return new_pkgs, removed_pkgs, updated_pkgs
+
+ def DiffType(self, a, b):
+ va = opencsw.ParseVersionString(a["version"])
+ vb = opencsw.ParseVersionString(b["version"])
+ if va[0] == vb[0]:
+ return "revision"
+ else:
+ return "version"
Modified: csw/mgar/gar/v2/lib/python/catalog_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/catalog_test.py 2012-03-15 10:51:29 UTC (rev 17412)
+++ csw/mgar/gar/v2/lib/python/catalog_test.py 2012-03-15 10:52:02 UTC (rev 17413)
@@ -106,6 +106,15 @@
self.assertFalse(updated_pkgs)
self.assertEqual(1, len(removed_pkgs))
+ def testUpdateOnly(self):
+ oc1 = catalog.OpencswCatalog(StringIO(CATALOG_LINE_1))
+ oc2 = catalog.OpencswCatalog(StringIO(CATALOG_LINE_2))
+ c = catalog.CatalogComparator()
+ new_pkgs, removed_pkgs, updated_pkgs = c.GetCatalogDiff(oc1, oc2)
+ self.assertFalse(new_pkgs)
+ self.assertFalse(removed_pkgs)
+ self.assertEquals("revision", updated_pkgs[0]["type"])
+
if __name__ == '__main__':
unittest.main()
Modified: csw/mgar/gar/v2/lib/python/integrate_catalogs.py
===================================================================
--- csw/mgar/gar/v2/lib/python/integrate_catalogs.py 2012-03-15 10:51:29 UTC (rev 17412)
+++ csw/mgar/gar/v2/lib/python/integrate_catalogs.py 2012-03-15 10:52:02 UTC (rev 17413)
@@ -81,7 +81,8 @@
#else
upgrade_#
#end if
-$catalogname
+$catalogname#
+ # $diffs_by_catalogname[$catalogname]["updated_pkgs"][0][2]["type"]
#end if
#end for
"""
@@ -98,7 +99,8 @@
return dict((x["catalogname"], x) for x in catalog)
-def GetDiffsByCatalogname(catrel_from, catrel_to, include_downgrades):
+def GetDiffsByCatalogname(catrel_from, catrel_to, include_downgrades,
+ include_version_changes):
rest_client = rest.RestClient()
diffs_by_catalogname = {}
def GetCatalog(rest_client, r_catrel, r_arch, r_osrel):
@@ -139,17 +141,13 @@
catalogname_d = diffs_by_catalogname.setdefault(pkg["catalogname"], {})
catalogname_d.setdefault("removed_pkgs", []).append((arch, osrel, pkg))
for pkg_pair in updated_pkgs:
- # Upgrade or downgrade?
- cmp_result = opencsw.CompareVersions(
- pkg_pair["from"]["version"],
- pkg_pair["to"]["version"])
- if cmp_result < 0:
- direction = "upgrade"
- else:
- direction = "downgrade"
- pkg_pair["direction"] = direction
- pkg = pkg_pair["from"]
- if direction == "upgrade" or include_downgrades:
+ update_decision_by_type = {
+ "revision": True,
+ "version": include_version_changes
+ }
+ if (update_decision_by_type[pkg_pair["type"]]
+ and (pkg_pair["direction"] == "upgrade" or include_downgrades)):
+ pkg = pkg_pair["from"]
catalogname_d = diffs_by_catalogname.setdefault(pkg["catalogname"], {})
catalogname_d.setdefault("updated_pkgs", []).append((arch, osrel, pkg_pair))
return diffs_by_catalogname
@@ -175,6 +173,10 @@
parser.add_option("--no-include-downgrades", dest="include_downgrades",
default=True, action="store_false",
help="Skip package downgrades.")
+ parser.add_option("--no-include-version-changes",
+ dest="include_version_changes",
+ default=True, action="store_false",
+ help="Skip version upgrades (only accept revision upgrades).")
options, args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG)
if not options.output_file:
@@ -186,7 +188,8 @@
diffs_by_catalogname = json.load(fd)
else:
diffs_by_catalogname = GetDiffsByCatalogname(
- catrel_from, catrel_to, options.include_downgrades)
+ catrel_from, catrel_to, options.include_downgrades,
+ options.include_version_changes)
namespace = {
"diffs_by_catalogname": diffs_by_catalogname,
"catrel_to": catrel_to,
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