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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sat Feb 5 20:36:20 CET 2011


Revision: 13198
          http://gar.svn.sourceforge.net/gar/?rev=13198&view=rev
Author:   wahwah
Date:     2011-02-05 19:36:20 +0000 (Sat, 05 Feb 2011)

Log Message:
-----------
pkgdb: Special REST client class

Different parts of code can reuse REST interaction.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/catalog_notifier.py

Added Paths:
-----------
    csw/mgar/gar/v2/lib/python/rest.py

Modified: csw/mgar/gar/v2/lib/python/catalog_notifier.py
===================================================================
--- csw/mgar/gar/v2/lib/python/catalog_notifier.py	2011-02-05 19:34:52 UTC (rev 13197)
+++ csw/mgar/gar/v2/lib/python/catalog_notifier.py	2011-02-05 19:36:20 UTC (rev 13198)
@@ -16,6 +16,7 @@
 import os.path
 import smtplib
 from email.mime.text import MIMEText
+import rest
 
 REPORT_TMPL = u"""Catalog update report for $email
 Catalog URL: $url
@@ -81,21 +82,6 @@
 #end if
 """
 
-class RestClient(object):
-
-  def GetPkgByMd5(self, md5_sum):
-    url = "http://buildfarm.opencsw.org/pkgdb/rest/srv4/%s/" % md5_sum
-    logging.debug("GetPkgByMd5(): calling %s", url)
-    data = urllib2.urlopen(url).read()
-    return json.loads(data)
-
-  def GetMaintainerByMd5(self, md5_sum):
-    pkg = self.GetPkgByMd5(md5_sum)
-    return {
-        "maintainer_email": pkg["maintainer_email"],
-    }
-
-
 class NotificationFormatter(object):
 
   def _GetPkgsByMaintainer(self, catalogs, rest_client):
@@ -247,7 +233,7 @@
     else:
       logging.debug("%s not found in previous_catalogs_by_triad", key)
   formatter = NotificationFormatter()
-  rest_client = RestClient()
+  rest_client = rest.RestClient()
   notifications = formatter.FormatNotifications(
       cat_tree_url, catalogs, rest_client)
   whitelist = frozenset()

Added: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/rest.py	2011-02-05 19:36:20 UTC (rev 13198)
@@ -0,0 +1,33 @@
+#!/usr/bin/env python2.6
+
+import logging
+import urllib2
+import json
+
+BASE_URL = "http://buildfarm.opencsw.org/pkgdb/rest"
+
+class RestClient(object):
+
+  def GetPkgByMd5(self, md5_sum):
+    url = BASE_URL + "/srv4/%s/" % md5_sum
+    logging.debug("GetPkgByMd5(): GET %s", url)
+    try:
+      data = urllib2.urlopen(url).read()
+      return json.loads(data)
+    except urllib2.HTTPError, e:
+      logging.warning(e)
+      return {
+          "maintainer_email": "Unknown",
+      }
+
+  def GetMaintainerByMd5(self, md5_sum):
+    pkg = self.GetPkgByMd5(md5_sum)
+    return {
+        "maintainer_email": pkg["maintainer_email"],
+    }
+
+  def GetCatalog(self, catrel, arch, osrel):
+    url = BASE_URL + "/catalogs/%s/%s/%s/" % (catrel, arch, osrel)
+    logging.debug("GetCatalog(): GET %s", url)
+    data = urllib2.urlopen(url).read()
+    return json.loads(data)


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