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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Thu Sep 22 10:36:40 CEST 2011


Revision: 15708
          http://gar.svn.sourceforge.net/gar/?rev=15708&view=rev
Author:   wahwah
Date:     2011-09-22 08:36:40 +0000 (Thu, 22 Sep 2011)
Log Message:
-----------
releases-web: Thou shalt not fsck with obsolete OS

Package deletions from obsolete OS releases (e.g. 5.8) are no longer allowed,
as they are invariably unintentional and undesired.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/common_constants.py
    csw/mgar/gar/v2/lib/python/csw_upload_pkg.py
    csw/mgar/gar/v2/lib/web/releases_web.py

Modified: csw/mgar/gar/v2/lib/python/common_constants.py
===================================================================
--- csw/mgar/gar/v2/lib/python/common_constants.py	2011-09-22 07:34:20 UTC (rev 15707)
+++ csw/mgar/gar/v2/lib/python/common_constants.py	2011-09-22 08:36:40 UTC (rev 15708)
@@ -9,6 +9,9 @@
     u"SunOS5.10",
     u"SunOS5.11",
 )
+OBSOLETE_OS_RELS = (
+    u"SunOS5.8",
+)
 
 SYSTEM_SYMLINKS = (
     ("/opt/csw/bdb4",     ("/opt/csw/bdb42",)),

Modified: csw/mgar/gar/v2/lib/python/csw_upload_pkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/csw_upload_pkg.py	2011-09-22 07:34:20 UTC (rev 15707)
+++ csw/mgar/gar/v2/lib/python/csw_upload_pkg.py	2011-09-22 08:36:40 UTC (rev 15708)
@@ -229,8 +229,10 @@
         http_code,
         c.getinfo(pycurl.EFFECTIVE_URL))
     c.close()
-    if http_code >= 400 and http_code <= 499:
-      raise RestCommunicationError("%s - HTTP code: %s" % (url, http_code))
+    if not (http_code >= 200 and http_code <= 299):
+      raise RestCommunicationError(
+          "%s - HTTP code: %s, content: %s"
+          % (url, http_code, d.getvalue()))
 
   def _GetFileMd5sum(self, filename):
     if filename not in self.md5_by_filename:

Modified: csw/mgar/gar/v2/lib/web/releases_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/releases_web.py	2011-09-22 07:34:20 UTC (rev 15707)
+++ csw/mgar/gar/v2/lib/web/releases_web.py	2011-09-22 08:36:40 UTC (rev 15708)
@@ -11,6 +11,7 @@
 from lib.python import checkpkg_lib
 from lib.python import package_stats
 from lib.python import opencsw
+from lib.python import common_constants
 import datetime
 import os
 import os.path
@@ -210,16 +211,33 @@
   def DELETE(self, catrel_name, arch_name, osrel_name, md5_sum):
     configuration.SetUpSqlobjectConnection()
     try:
+      if osrel_name not in common_constants.OS_RELS:
+        self.ReturnError(
+            "%s is not one of %s (OS releases)"
+            % (osrel_name, common_constants.OS_RELS))
+      if osrel_name in common_constants.OBSOLETE_OS_RELS:
+        self.ReturnError(
+            "package deletions from an obsolete OS release such as %s "
+            "are not allowed" % osrel_name)
       srv4_to_remove = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
       c = checkpkg_lib.Catalog()
       c.RemoveSrv4(srv4_to_remove, osrel_name, arch_name, catrel_name)
     except (
         sqlobject.main.SQLObjectNotFound,
         sqlobject.dberrors.OperationalError), e:
-      # Some better error reporting would be good here.
-      raise web.internalerror()
+      self.ReturnError("An error occurred: %s" % e)
 
+  def ReturnError(self, message):
+    web.header(
+        'Content-type',
+        'application/x-vnd.opencsw.pkg;type=error-message')
+    response = json.dumps({
+      "error_message": unicode(message),
+    })
+    web.header('Content-Length', len(response))
+    raise web.notacceptable(data=response)
 
+
 def SaveToAllpkgs(basename, data):
   """Saves a file to allpkgs."""
   target_path = os.path.join(ALLPKGS_DIR, basename)

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