SF.net SVN: gar:[23038] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue Feb 18 10:40:17 CET 2014


Revision: 23038
          http://sourceforge.net/p/gar/code/23038
Author:   wahwah
Date:     2014-02-18 09:40:16 +0000 (Tue, 18 Feb 2014)
Log Message:
-----------
pkgdb: User username and password for the rel app

The releases app requires user authentication.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/checkpkg2.py
    csw/mgar/gar/v2/lib/python/checkpkg_lib.py
    csw/mgar/gar/v2/lib/python/collect_binary_elfinfo.py
    csw/mgar/gar/v2/lib/python/collect_pkg_metadata.py
    csw/mgar/gar/v2/lib/python/rest.py

Modified: csw/mgar/gar/v2/lib/python/checkpkg2.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg2.py	2014-02-17 23:25:58 UTC (rev 23037)
+++ csw/mgar/gar/v2/lib/python/checkpkg2.py	2014-02-18 09:40:16 UTC (rev 23038)
@@ -146,9 +146,11 @@
       file_list.append(arg)
 
   config = configuration.GetConfig()
+  username, password = rest.GetUsernameAndPassword()
   rest_client = rest.RestClient(
       pkgdb_url=config.get('rest', 'pkgdb'),
-      releases_url=config.get('rest', 'releases'))
+      releases_url=config.get('rest', 'releases'),
+      username=username, password=password)
 
   if file_list:
     def MakeEntry(file_name):

Modified: csw/mgar/gar/v2/lib/python/checkpkg_lib.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2014-02-17 23:25:58 UTC (rev 23037)
+++ csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2014-02-18 09:40:16 UTC (rev 23038)
@@ -197,9 +197,12 @@
     self.individual_checks = []
     self.set_checks = []
     config = configuration.GetConfig()
+    username, password = rest.GetUsernameAndPassword()
     self.rest_client = rest.RestClient(
         pkgdb_url=config.get('rest', 'pkgdb'),
-        releases_url=config.get('rest', 'releases'))
+        releases_url=config.get('rest', 'releases'),
+        username=username,
+        password=password)
 
   def _ResetState(self):
     self.errors = []

Modified: csw/mgar/gar/v2/lib/python/collect_binary_elfinfo.py
===================================================================
--- csw/mgar/gar/v2/lib/python/collect_binary_elfinfo.py	2014-02-17 23:25:58 UTC (rev 23037)
+++ csw/mgar/gar/v2/lib/python/collect_binary_elfinfo.py	2014-02-18 09:40:16 UTC (rev 23038)
@@ -35,9 +35,12 @@
     self.debug = debug
     self._binary_path = binary_path
     self.config = configuration.GetConfig()
+    username, password = rest.GetUsernameAndPassword()
     self.rest_client = rest.RestClient(
         pkgdb_url=self.config.get('rest', 'pkgdb'),
-        releases_url=self.config.get('rest', 'releases'))
+        releases_url=self.config.get('rest', 'releases'),
+        username=username,
+        password=password)
     fd = open(self._binary_path, 'rb')
     self._mmap = mmap.mmap(fd.fileno(), 0, access=mmap.PROT_READ)
     self._elffile = ELFFile(self._mmap)

Modified: csw/mgar/gar/v2/lib/python/collect_pkg_metadata.py
===================================================================
--- csw/mgar/gar/v2/lib/python/collect_pkg_metadata.py	2014-02-17 23:25:58 UTC (rev 23037)
+++ csw/mgar/gar/v2/lib/python/collect_pkg_metadata.py	2014-02-18 09:40:16 UTC (rev 23038)
@@ -86,9 +86,12 @@
     self._binaries = None
     self._file_paths = None
     self.config = configuration.GetConfig()
+    username, password = rest.GetUsernameAndPassword()
     self.rest_client = rest.RestClient(
         pkgdb_url=self.config.get('rest', 'pkgdb'),
-        releases_url=self.config.get('rest', 'releases'))
+        releases_url=self.config.get('rest', 'releases'),
+        username=username,
+        password=password)
 
   def __del__(self):
     self.Cleanup()

Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	2014-02-17 23:25:58 UTC (rev 23037)
+++ csw/mgar/gar/v2/lib/python/rest.py	2014-02-18 09:40:16 UTC (rev 23038)
@@ -237,12 +237,39 @@
       ('md5_sum', md5_sum),
     ])
 
-  @retry_decorator.Retry(tries=4, delay=5,
+  @retry_decorator.Retry(tries=DEFAULT_TRIES, delay=DEFAULT_RETRY_DELAY,
                          exceptions=(RestCommunicationError, pycurl.error))
   def GetBlob(self, tag, md5_sum):
     url = self.releases_url + "/blob/%s/%s/" % (tag, md5_sum)
-    data = urllib2.urlopen(url).read()
-    return cjson.decode(data)
+    logging.warning('GetBlob() url=%r', url)
+    c = pycurl.Curl()
+    d = StringIO()
+    h = StringIO()
+    c.setopt(pycurl.URL, str(url))
+    c.setopt(pycurl.WRITEFUNCTION, d.write)
+    c.setopt(pycurl.HEADERFUNCTION, h.write)
+    c = self._SetAuth(c)
+    if self.debug:
+      c.setopt(c.VERBOSE, 1)
+    c.perform()
+    http_code = c.getinfo(pycurl.HTTP_CODE)
+    logging.warning(
+        "curl getinfo: %s %s %s",
+        type(http_code),
+        http_code,
+        c.getinfo(pycurl.EFFECTIVE_URL))
+    c.close()
+    logging.warning("HTTP code: %s", http_code)
+    if http_code == 401:
+      raise RestCommunicationError("Received HTTP code {0}".format(http_code))
+    successful = (http_code >= 200 and http_code <= 299)
+    metadata = None
+    if successful:
+      metadata = cjson.decode(d.getvalue())
+    else:
+      logging.warning("Blob %r for %r was not found in the database"
+                      % (tag, md5_sum))
+    return metadata
 
   def _HttpHeadRequest(self, url):
     """Make a HTTP HEAD request and return the http code."""
@@ -253,6 +280,7 @@
     c.setopt(pycurl.NOPROGRESS, 1)
     c.setopt(pycurl.NOBODY, 1)
     c.setopt(pycurl.HEADER, 1)
+    c = self._SetAuth(c)
     if self.debug:
       c.setopt(c.VERBOSE, 1)
     c.setopt(pycurl.WRITEFUNCTION, d.write)

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