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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Nov 12 16:55:20 CET 2012


Revision: 19674
          http://gar.svn.sourceforge.net/gar/?rev=19674&view=rev
Author:   wahwah
Date:     2012-11-12 15:55:20 +0000 (Mon, 12 Nov 2012)
Log Message:
-----------
csw-upload-pkg: Code refactoring

Moving a more generally useful function into rest.py, to be used with the
catalog integration script (potentially).

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/csw_upload_pkg.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	2012-11-12 15:39:38 UTC (rev 19673)
+++ csw/mgar/gar/v2/lib/python/csw_upload_pkg.py	2012-11-12 15:55:20 UTC (rev 19674)
@@ -285,52 +285,7 @@
     basename = os.path.basename(filename)
     parsed_basename = opencsw.ParsePackageFileName(basename)
     logging.debug("parsed_basename: %s", parsed_basename)
-    url = (
-        "%s%s/catalogs/%s/%s/%s/%s/"
-        % (self.rest_url,
-           RELEASES_APP,
-           DEFAULT_CATREL,
-           arch,
-           osrel,
-           md5_sum))
-    logging.debug("URL: %s %s", type(url), url)
-    c = pycurl.Curl()
-    d = StringIO()
-    h = StringIO()
-    # Bogus data to upload
-    s = StringIO()
-    c.setopt(pycurl.URL, str(url))
-    c.setopt(pycurl.PUT, 1)
-    c.setopt(pycurl.UPLOAD, 1)
-    c.setopt(pycurl.INFILESIZE_LARGE, s.len)
-    c.setopt(pycurl.READFUNCTION, s.read)
-    c.setopt(pycurl.WRITEFUNCTION, d.write)
-    c.setopt(pycurl.HEADERFUNCTION, h.write)
-    c.setopt(pycurl.HTTPHEADER, ["Expect:"]) # Fixes the HTTP 417 error
-    c = self._SetAuth(c)
-    if self.debug:
-      c.setopt(c.VERBOSE, 1)
-    c.perform()
-    http_code = c.getinfo(pycurl.HTTP_CODE)
-    logging.debug(
-        "curl getinfo: %s %s %s",
-        type(http_code),
-        http_code,
-        c.getinfo(pycurl.EFFECTIVE_URL))
-    c.close()
-    # if self.debug:
-    #   logging.debug("*** Headers")
-    #   logging.debug(h.getvalue())
-    #   logging.debug("*** Data")
-    if http_code >= 400 and http_code <= 599:
-      if not self.debug:
-        # In debug mode, all headers are printed to screen, and we aren't
-        # interested in the response body.
-        logging.fatal("Response: %s %s", http_code, d.getvalue())
-      raise RestCommunicationError("%s - HTTP code: %s" % (url, http_code))
-    else:
-      logging.debug("Response: %s %s", http_code, d.getvalue())
-    return http_code
+    return rest_client.AddSvr4ToCatalog(catrel, arch, osrel, md5_sum)
 
   def _GetSrv4FileMetadata(self, md5_sum):
     logging.debug("_GetSrv4FileMetadata(%s)", repr(md5_sum))

Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	2012-11-12 15:39:38 UTC (rev 19673)
+++ csw/mgar/gar/v2/lib/python/rest.py	2012-11-12 15:55:20 UTC (rev 19674)
@@ -150,7 +150,55 @@
           "%s - HTTP code: %s, content: %s"
           % (url, http_code, d.getvalue()))
 
+  def AddSvr4ToCatalog(self, catrel, arch, osrel, md5_sum):
+    url = (
+        "%s%s/catalogs/%s/%s/%s/%s/"
+        % (self.rest_url,
+           RELEASES_APP,
+           DEFAULT_CATREL,
+           arch,
+           osrel,
+           md5_sum))
+    logging.debug("URL: %s %s", type(url), url)
+    c = pycurl.Curl()
+    d = StringIO()
+    h = StringIO()
+    # Bogus data to upload
+    s = StringIO()
+    c.setopt(pycurl.URL, str(url))
+    c.setopt(pycurl.PUT, 1)
+    c.setopt(pycurl.UPLOAD, 1)
+    c.setopt(pycurl.INFILESIZE_LARGE, s.len)
+    c.setopt(pycurl.READFUNCTION, s.read)
+    c.setopt(pycurl.WRITEFUNCTION, d.write)
+    c.setopt(pycurl.HEADERFUNCTION, h.write)
+    c.setopt(pycurl.HTTPHEADER, ["Expect:"]) # Fixes the HTTP 417 error
+    c = self._SetAuth(c)
+    if self.debug:
+      c.setopt(c.VERBOSE, 1)
+    c.perform()
+    http_code = c.getinfo(pycurl.HTTP_CODE)
+    logging.debug(
+        "curl getinfo: %s %s %s",
+        type(http_code),
+        http_code,
+        c.getinfo(pycurl.EFFECTIVE_URL))
+    c.close()
+    # if self.debug:
+    #   logging.debug("*** Headers")
+    #   logging.debug(h.getvalue())
+    #   logging.debug("*** Data")
+    if http_code >= 400 and http_code <= 599:
+      if not self.debug:
+        # In debug mode, all headers are printed to screen, and we aren't
+        # interested in the response body.
+        logging.fatal("Response: %s %s", http_code, d.getvalue())
+      raise RestCommunicationError("%s - HTTP code: %s" % (url, http_code))
+    else:
+      logging.debug("Response: %s %s", http_code, d.getvalue())
+    return http_code
 
+
 class CachedPkgstats(object):
   """Class responsible for holding and caching package stats.
 

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