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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Mar 28 03:08:16 CEST 2011


Revision: 13967
          http://gar.svn.sourceforge.net/gar/?rev=13967&view=rev
Author:   wahwah
Date:     2011-03-28 01:08:16 +0000 (Mon, 28 Mar 2011)

Log Message:
-----------
csw-upload-pkg: Add --rest-url

This way, it's possible to work outside the OpenCSW buildfarm, using
different URLs for REST access.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/csw_upload_pkg.py
    csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py
    csw/mgar/gar/v2/lib/python/rest.py

Modified: csw/mgar/gar/v2/lib/python/csw_upload_pkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/csw_upload_pkg.py	2011-03-28 01:06:25 UTC (rev 13966)
+++ csw/mgar/gar/v2/lib/python/csw_upload_pkg.py	2011-03-28 01:08:16 UTC (rev 13967)
@@ -20,7 +20,8 @@
 import struct_util
 
 
-BASE_URL = "http://buildfarm.opencsw.org/releases/"
+BASE_URL = "http://buildfarm.opencsw.org"
+RELEASES_APP = "/releases"
 DEFAULT_CATREL = "unstable"
 USAGE = """%prog [ options ] <pkg1> [ <pkg2> [ ... ] ]
 
@@ -61,12 +62,14 @@
 
 class Srv4Uploader(object):
 
-  def __init__(self, filenames, os_release=None, debug=False):
+  def __init__(self, filenames, rest_url, os_release=None, debug=False):
+    super(Srv4Uploader, self).__init__()
     self.filenames = filenames
     self.md5_by_filename = {}
     self.debug = debug
-    self._rest_client = rest.RestClient()
     self.os_release = os_release
+    self.rest_url = rest_url
+    self._rest_client = rest.RestClient(self.rest_url)
 
   def Upload(self):
     for filename in self.filenames:
@@ -106,8 +109,8 @@
     parsed_basename = opencsw.ParsePackageFileName(basename)
     # TODO: Move this bit to a separate class (RestClient)
     url = (
-        "%scatalogs/unstable/%s/%s/%s/"
-        % (BASE_URL, arch, osrel, md5_sum))
+        "%s%s/catalogs/unstable/%s/%s/%s/"
+        % (self.rest_url, RELEASES_APP, arch, osrel, md5_sum))
     logging.debug("DELETE @ URL: %s %s", type(url), url)
     c = pycurl.Curl()
     d = StringIO()
@@ -257,8 +260,8 @@
     parsed_basename = opencsw.ParsePackageFileName(basename)
     logging.debug("parsed_basename: %s", parsed_basename)
     url = (
-        "%scatalogs/unstable/%s/%s/%s/"
-        % (BASE_URL, arch, osrel, md5_sum))
+        "%s%s/catalogs/unstable/%s/%s/%s/"
+        % (self.rest_url, RELEASES_APP, arch, osrel, md5_sum))
     logging.debug("URL: %s %s", type(url), url)
     c = pycurl.Curl()
     d = StringIO()
@@ -299,7 +302,7 @@
 
   def _GetSrv4FileMetadata(self, md5_sum):
     logging.debug("_GetSrv4FileMetadata(%s)", repr(md5_sum))
-    url = BASE_URL + "srv4/" + md5_sum + "/"
+    url = self.rest_url + RELEASES_APP + "/srv4/" + md5_sum + "/"
     c = pycurl.Curl()
     d = StringIO()
     h = StringIO()
@@ -330,7 +333,7 @@
     c = pycurl.Curl()
     d = StringIO()
     h = StringIO()
-    url = BASE_URL + "srv4/"
+    url = self.rest_url + RELEASES_APP + "/srv4/"
     c.setopt(pycurl.URL, url)
     c.setopt(pycurl.POST, 1)
     post_data = [
@@ -370,6 +373,10 @@
   parser.add_option("--os-release",
       dest="os_release",
       help="If specified, only uploads to the specified OS release.")
+  parser.add_option("--rest-url",
+      dest="rest_url",
+      default=BASE_URL,
+      help="Base URL for REST, e.g. %s" % BASE_URL)
   options, args = parser.parse_args()
   if options.debug:
     logging.basicConfig(level=logging.DEBUG)
@@ -383,6 +390,7 @@
   if os_release:
     os_release = struct_util.OsReleaseToLong(os_release)
   uploader = Srv4Uploader(args,
+                          options.rest_url,
                           os_release=os_release,
                           debug=options.debug)
   if options.remove:

Modified: csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py	2011-03-28 01:06:25 UTC (rev 13966)
+++ csw/mgar/gar/v2/lib/python/csw_upload_pkg_test.py	2011-03-28 01:08:16 UTC (rev 13967)
@@ -58,7 +58,7 @@
   def test_MatchSrv4ToCatalogsSame(self):
     rest_client_mock = self.mox.CreateMock(rest.RestClient)
     self.mox.StubOutWithMock(rest, "RestClient")
-    rest.RestClient().AndReturn(rest_client_mock)
+    rest.RestClient(None).AndReturn(rest_client_mock)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.9', 'gdb').AndReturn(GDB_STRUCT_9)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
@@ -66,7 +66,7 @@
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.11', 'gdb').AndReturn(GDB_STRUCT_9)
     self.mox.ReplayAll()
-    su = csw_upload_pkg.Srv4Uploader(None)
+    su = csw_upload_pkg.Srv4Uploader(None, None)
     result = su._MatchSrv4ToCatalogs(
         "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
         "unstable", "sparc", "SunOS5.9",
@@ -81,7 +81,7 @@
   def test_MatchSrv4ToCatalogsDifferent(self):
     rest_client_mock = self.mox.CreateMock(rest.RestClient)
     self.mox.StubOutWithMock(rest, "RestClient")
-    rest.RestClient().AndReturn(rest_client_mock)
+    rest.RestClient(None).AndReturn(rest_client_mock)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.9', 'gdb').AndReturn(GDB_STRUCT_9)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
@@ -89,7 +89,7 @@
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.11', 'gdb').AndReturn(GDB_STRUCT_10)
     self.mox.ReplayAll()
-    su = csw_upload_pkg.Srv4Uploader(None)
+    su = csw_upload_pkg.Srv4Uploader(None, None)
     result = su._MatchSrv4ToCatalogs(
         "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
         "unstable", "sparc", "SunOS5.9",
@@ -104,13 +104,13 @@
     # uploading a 5.10 package.
     rest_client_mock = self.mox.CreateMock(rest.RestClient)
     self.mox.StubOutWithMock(rest, "RestClient")
-    rest.RestClient().AndReturn(rest_client_mock)
+    rest.RestClient(None).AndReturn(rest_client_mock)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.10', 'gdb').AndReturn(GDB_STRUCT_9)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.11', 'gdb').AndReturn(GDB_STRUCT_9)
     self.mox.ReplayAll()
-    su = csw_upload_pkg.Srv4Uploader(None)
+    su = csw_upload_pkg.Srv4Uploader(None, None)
     result = su._MatchSrv4ToCatalogs(
         "gdb-7.2,REV=2011.01.21-SunOS5.10-sparc-CSW.pkg.gz",
         "unstable", "sparc", "SunOS5.10",
@@ -124,7 +124,7 @@
   def test_MatchSrv4ToCatalogsSameSpecificOsrel(self):
     rest_client_mock = self.mox.CreateMock(rest.RestClient)
     self.mox.StubOutWithMock(rest, "RestClient")
-    rest.RestClient().AndReturn(rest_client_mock)
+    rest.RestClient(None).AndReturn(rest_client_mock)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.9', 'gdb').AndReturn(GDB_STRUCT_9)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
@@ -132,7 +132,7 @@
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.11', 'gdb').AndReturn(GDB_STRUCT_9)
     self.mox.ReplayAll()
-    su = csw_upload_pkg.Srv4Uploader(None, os_release="SunOS5.10")
+    su = csw_upload_pkg.Srv4Uploader(None, None, os_release="SunOS5.10")
     result = su._MatchSrv4ToCatalogs(
         "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
         "unstable", "sparc", "SunOS5.9",
@@ -145,7 +145,7 @@
   def test_MatchSrv4ToCatalogsAbsentFromAll(self):
     rest_client_mock = self.mox.CreateMock(rest.RestClient)
     self.mox.StubOutWithMock(rest, "RestClient")
-    rest.RestClient().AndReturn(rest_client_mock)
+    rest.RestClient(None).AndReturn(rest_client_mock)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.9', 'gdb').AndReturn(None)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
@@ -153,7 +153,7 @@
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.11', 'gdb').AndReturn(None)
     self.mox.ReplayAll()
-    su = csw_upload_pkg.Srv4Uploader(None)
+    su = csw_upload_pkg.Srv4Uploader(None, None)
     result = su._MatchSrv4ToCatalogs(
         "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
         "unstable", "sparc", "SunOS5.9",
@@ -168,7 +168,7 @@
   def test_MatchSrv4ToCatalogsSameSpecificOsrelAlreadyPresent(self):
     rest_client_mock = self.mox.CreateMock(rest.RestClient)
     self.mox.StubOutWithMock(rest, "RestClient")
-    rest.RestClient().AndReturn(rest_client_mock)
+    rest.RestClient(None).AndReturn(rest_client_mock)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.9', 'gdb').AndReturn(GDB_STRUCT_9)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
@@ -176,7 +176,7 @@
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.11', 'gdb').AndReturn(GDB_STRUCT_10)
     self.mox.ReplayAll()
-    su = csw_upload_pkg.Srv4Uploader(None, os_release="SunOS5.10")
+    su = csw_upload_pkg.Srv4Uploader(None, None, os_release="SunOS5.10")
     result = su._MatchSrv4ToCatalogs(
         "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
         "unstable", "sparc", "SunOS5.9",
@@ -189,7 +189,7 @@
   def test_MatchSrv4ToCatalogsNotPresent(self):
     rest_client_mock = self.mox.CreateMock(rest.RestClient)
     self.mox.StubOutWithMock(rest, "RestClient")
-    rest.RestClient().AndReturn(rest_client_mock)
+    rest.RestClient(None).AndReturn(rest_client_mock)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.9', 'gdb').AndReturn(GDB_STRUCT_9)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
@@ -197,7 +197,7 @@
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.11', 'gdb').AndReturn(None)
     self.mox.ReplayAll()
-    su = csw_upload_pkg.Srv4Uploader(None, os_release="SunOS5.10")
+    su = csw_upload_pkg.Srv4Uploader(None, None, os_release="SunOS5.10")
     result = su._MatchSrv4ToCatalogs(
         "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
         "unstable", "sparc", "SunOS5.9",
@@ -210,7 +210,7 @@
   def test_MatchSrv4ToCatalogsFirstNotPresent(self):
     rest_client_mock = self.mox.CreateMock(rest.RestClient)
     self.mox.StubOutWithMock(rest, "RestClient")
-    rest.RestClient().AndReturn(rest_client_mock)
+    rest.RestClient(None).AndReturn(rest_client_mock)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.9', 'gdb').AndReturn(None)
     rest_client_mock.Srv4ByCatalogAndCatalogname(
@@ -218,7 +218,7 @@
     rest_client_mock.Srv4ByCatalogAndCatalogname(
         'unstable', 'sparc', u'SunOS5.11', 'gdb').AndReturn(GDB_STRUCT_10)
     self.mox.ReplayAll()
-    su = csw_upload_pkg.Srv4Uploader(None)
+    su = csw_upload_pkg.Srv4Uploader(None, None)
     result = su._MatchSrv4ToCatalogs(
         "gdb-7.2,REV=2011.01.21-SunOS5.9-sparc-CSW.pkg.gz",
         "unstable", "sparc", "SunOS5.9",
@@ -275,7 +275,7 @@
     }
     rest_client_mock = self.mox.CreateMock(rest.RestClient)
     self.mox.StubOutWithMock(rest, "RestClient")
-    rest.RestClient().AndReturn(rest_client_mock)
+    rest.RestClient(None).AndReturn(rest_client_mock)
     for i, os_n in enumerate(in_catalog, 3 - len(in_catalog)):
       pkg_struct = pkg_struct_map[os_n]
       rest_client_mock.Srv4ByCatalogAndCatalogname(
@@ -284,7 +284,7 @@
           u'SunOS5.%s' % (i + 9), 'gdb').AndReturn(pkg_struct)
     self.mox.ReplayAll()
     os_release_to_specify = "SunOS5.%s" % osrel_spec if osrel_spec else None
-    su = csw_upload_pkg.Srv4Uploader(None, os_release=os_release_to_specify)
+    su = csw_upload_pkg.Srv4Uploader(None, None, os_release=os_release_to_specify)
     result = su._MatchSrv4ToCatalogs(
         self.BASENAME,
         "unstable", "sparc", "SunOS5.%s" % pkg_osrel,

Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	2011-03-28 01:06:25 UTC (rev 13966)
+++ csw/mgar/gar/v2/lib/python/rest.py	2011-03-28 01:08:16 UTC (rev 13967)
@@ -4,7 +4,7 @@
 import urllib2
 import json
 
-BASE_URL = "http://buildfarm.opencsw.org/pkgdb/rest"
+DEFAULT_URL = "http://buildfarm.opencsw.org"
 
 
 class Error(Exception):
@@ -17,8 +17,13 @@
 
 class RestClient(object):
 
+  PKGDB_APP = "/pkgdb/rest"
+
+  def __init__(self, rest_url=DEFAULT_URL):
+    self.rest_url = rest_url
+
   def GetPkgByMd5(self, md5_sum):
-    url = BASE_URL + "/srv4/%s/" % md5_sum
+    url = self.rest_url + self.PKGDB_APP + "/srv4/%s/" % md5_sum
     logging.debug("GetPkgByMd5(): GET %s", url)
     try:
       data = urllib2.urlopen(url).read()
@@ -38,7 +43,7 @@
   def GetCatalog(self, catrel, arch, osrel):
     if not catrel:
       raise ArgumentError("Missing catalog release.")
-    url = BASE_URL + "/catalogs/%s/%s/%s/" % (catrel, arch, osrel)
+    url = self.rest_url + self.PKGDB_APP + "/catalogs/%s/%s/%s/" % (catrel, arch, osrel)
     logging.debug("GetCatalog(): GET %s", url)
     try:
       data = urllib2.urlopen(url).read()
@@ -49,7 +54,7 @@
 
   def Srv4ByCatalogAndCatalogname(self, catrel, arch, osrel, catalogname):
     """Returns a srv4 data structure or None if not found."""
-    url = BASE_URL + (
+    url = self.rest_url + self.PKGDB_APP + (
         "/catalogs/%s/%s/%s/catalognames/%s/"
         % (catrel, arch, osrel, catalogname))
     logging.debug("Srv4ByCatalogAndCatalogname(): GET %s", url)


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