[csw-devel] SF.net SVN: gar:[14008] csw/mgar/gar/v2/lib/python
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Tue Mar 29 10:29:51 CEST 2011
Revision: 14008
http://gar.svn.sourceforge.net/gar/?rev=14008&view=rev
Author: wahwah
Date: 2011-03-29 08:29:51 +0000 (Tue, 29 Mar 2011)
Log Message:
-----------
csw-upload-pkg: Import package if necessary
This change makes it easier to add packages not built with GAR: If a package
is has not been previously imported to the database, pkgdb is automatically
invoked to import the metadata.
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 2011-03-29 08:29:08 UTC (rev 14007)
+++ csw/mgar/gar/v2/lib/python/csw_upload_pkg.py 2011-03-29 08:29:51 UTC (rev 14008)
@@ -61,6 +61,10 @@
"""Unexpected data found."""
+class WorkflowError(Error):
+ """Unexpected state of workflow, e.g. expected element not found."""
+
+
class Srv4Uploader(object):
def __init__(self, filenames, rest_url, os_release=None, debug=False):
@@ -72,11 +76,37 @@
self.rest_url = rest_url
self._rest_client = rest.RestClient(self.rest_url)
+ def _ImportMetadata(self, filename):
+ md5_sum = self._GetFileMd5sum(filename)
+ metadata = self._rest_client.GetPkgByMd5(md5_sum)
+ if metadata:
+ # Metadata are already in the database.
+ return
+ logging.warning("%s (%s) is not known to the database.", filename, md5_sum)
+ bin_dir = os.path.dirname(__file__)
+ pkgdb_executable = os.path.join(bin_dir, "pkgdb")
+ assert os.path.exists(pkgdb_executable), (
+ "Could not find %s. Make sure that the pkgdb executable is "
+ "available \n"
+ "from the same directory as csw-upload-pkg." % pkgdb_executable)
+ args = [pkgdb_executable, "importpkg", filename]
+ ret = subprocess.call(args)
+ if ret:
+ raise OSError("An error occurred when running %s." % args)
+ # Verify that the import succeeded
+ metadata = self._rest_client.GetPkgByMd5(md5_sum)
+ if not metadata:
+ raise WorkflowError(
+ "Metadata of %s could not be imported into the database."
+ % filename)
+
+
def Upload(self):
do_upload = True
planned_modifications = []
metadata_by_md5 = {}
for filename in self.filenames:
+ self._ImportMetadata(filename)
md5_sum = self._GetFileMd5sum(filename)
file_in_allpkgs, file_metadata = self._GetSrv4FileMetadata(md5_sum)
if file_in_allpkgs:
Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py 2011-03-29 08:29:08 UTC (rev 14007)
+++ csw/mgar/gar/v2/lib/python/rest.py 2011-03-29 08:29:51 UTC (rev 14008)
@@ -30,12 +30,18 @@
return json.loads(data)
except urllib2.HTTPError, e:
logging.warning("%s -- %s", url, e)
- return {
- "maintainer_email": "Unknown",
- }
+ if e.code == 404:
+ # Code 404 is fine, it means that the package with given md5 does not
+ # exist.
+ return None
+ else:
+ # Other HTTP errors are should be thrown.
+ raise
def GetMaintainerByMd5(self, md5_sum):
pkg = self.GetPkgByMd5(md5_sum)
+ if not pkg:
+ pkg = {"maintainer_email": "Unknown"}
return {
"maintainer_email": pkg["maintainer_email"],
}
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