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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Aug 15 09:13:23 CEST 2011


Revision: 15341
          http://gar.svn.sourceforge.net/gar/?rev=15341&view=rev
Author:   wahwah
Date:     2011-08-15 07:13:23 +0000 (Mon, 15 Aug 2011)

Log Message:
-----------
pkgdb: Export more data via REST

http://lists.opencsw.org/pipermail/maintainers/2011-August/015175.html

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

Modified: csw/mgar/gar/v2/lib/python/models.py
===================================================================
--- csw/mgar/gar/v2/lib/python/models.py	2011-08-15 07:13:00 UTC (rev 15340)
+++ csw/mgar/gar/v2/lib/python/models.py	2011-08-15 07:13:23 UTC (rev 15341)
@@ -3,6 +3,7 @@
 # Defines models for package database.
 
 import logging
+import re
 import sqlobject
 import os.path
 from sqlobject import sqlbuilder
@@ -143,6 +144,10 @@
   files = sqlobject.MultipleJoin('CswFile',
           joinColumn='id')
 
+  def __init__(self, *args, **kwargs):
+    super(Srv4FileStats, self).__init__(*args, **kwargs)
+    self._cached_pkgstats = None
+
   def DeleteAllDependentObjects(self):
     data_obj = self.data_obj
     self.data_obj = None
@@ -207,8 +212,41 @@
         % (self.catalogname, self.version_string, self.arch.name))
 
   def GetStatsStruct(self):
-    return cPickle.loads(str(self.data_obj.pickle))
+    if not self._cached_pkgstats:
+      self._cached_pkgstats = cPickle.loads(str(self.data_obj.pickle))
+    return self._cached_pkgstats
 
+  def _GetBuildSource(self):
+    data = self.GetStatsStruct()
+    build_src = None
+    if "OPENCSW_REPOSITORY" in data["pkginfo"]:
+      build_src = data["pkginfo"]["OPENCSW_REPOSITORY"]
+    return build_src
+
+  def GetSvnUrl(self):
+    build_src = self._GetBuildSource()
+    svn_url = None
+    if build_src:
+      svn_url = re.sub(r'([^@]*).*', r'\1/Makefile', build_src)
+    return svn_url
+
+  def GetTracUrl(self):
+    build_src = self._GetBuildSource()
+    trac_url = None
+    if build_src:
+      trac_url = re.sub(
+            r'https://gar.svn.(sf|sourceforge).net/svnroot/gar/([^@]+)@(.*)',
+            r'http://sourceforge.net/apps/trac/gar/browser/\2/Makefile?rev=\3',
+            build_src)
+    return trac_url
+
+  def GetVendorUrl(self):
+    data = self.GetStatsStruct()
+    vendor_url = None
+    if "VENDOR" in data["pkginfo"]:
+      vendor_url = re.split(r"\s+", data["pkginfo"]["VENDOR"])[0]
+    return vendor_url
+
   def GetRestRepr(self):
     mimetype = "application/x-vnd.opencsw.pkg;type=srv4-detail"
     data = {
@@ -230,6 +268,8 @@
         # For compatibility with the catalog parser from catalog.py
         'version': self.version_string,
         # 'in_catalogs': unicode([unicode(x) for x in self.in_catalogs]),
+        'vendor_url': self.GetVendorUrl(),
+        'repository_url': self.GetSvnUrl(),
     }
     return mimetype, data
 

Modified: csw/mgar/gar/v2/lib/python/pkgdb.py
===================================================================
--- csw/mgar/gar/v2/lib/python/pkgdb.py	2011-08-15 07:13:00 UTC (rev 15340)
+++ csw/mgar/gar/v2/lib/python/pkgdb.py	2011-08-15 07:13:23 UTC (rev 15341)
@@ -126,18 +126,9 @@
     for identifier in self.identifiers:
       srv4 = GetPkg(identifier)
       data = srv4.GetStatsStruct()
-      if "OPENCSW_REPOSITORY" in data["pkginfo"]:
-        build_src = data["pkginfo"]["OPENCSW_REPOSITORY"]
-        build_src_url_svn = re.sub(r'([^@]*).*', r'\1/Makefile', build_src)
-        build_src_url_trac = re.sub(
-            r'https://gar.svn.(sf|sourceforge).net/svnroot/gar/([^@]+)@(.*)',
-            r'http://sourceforge.net/apps/trac/gar/browser/\2/Makefile?rev=\3',
-            build_src)
-      else:
-        build_src = None
-        build_src_url_svn = None
-        build_src_url_trac = None
-      data["build_src"] = build_src
+      build_src_url_svn = srv4.GetSvnUrl()
+      build_src_url_trac = srv4.GetTracUrl()
+      data["build_src"] = data["pkginfo"]["OPENCSW_REPOSITORY"]
       data["build_src_url_svn"] = build_src_url_svn
       data["build_src_url_trac"] = build_src_url_trac
       data["error_tags"] = list(self.GetErrorTagsResult(srv4))


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