[Python-checkins] distutils2: Add a way to get the metadatas by downloading and opening archives.

tarek.ziade python-checkins at python.org
Sun Aug 8 11:50:46 CEST 2010


tarek.ziade pushed f314cf0ce672 to distutils2:

http://hg.python.org/distutils2/rev/f314cf0ce672
changeset:   464:f314cf0ce672
user:        Alexis Metaireau <ametaireau at gmail.com>
date:        Tue Jul 27 18:08:46 2010 +0200
summary:     Add a way to get the metadatas by downloading and opening archives.
files:       src/distutils2/index/dist.py, src/distutils2/index/simple.py

diff --git a/src/distutils2/index/dist.py b/src/distutils2/index/dist.py
--- a/src/distutils2/index/dist.py
+++ b/src/distutils2/index/dist.py
@@ -17,6 +17,7 @@
 import urllib
 import urlparse
 import zipfile
+import os
 
 try:
     import hashlib
@@ -39,7 +40,7 @@
 
 class ReleaseInfo(object):
     """Represent a release of a project (a project with a specific version).
-    The release contain the metadata informations related to this specific
+    The release contain the _metadata informations related to this specific
     version, and is also a container for distribution related informations.
 
     See the DistInfo class for more information about distributions.
@@ -56,7 +57,10 @@
         self.name = name
         self._version = None
         self.version = version
-        self.metadata = DistributionMetadata(mapping=metadata)
+        if metadata:
+            self._metadata = DistributionMetadata(mapping=metadata)
+        else:
+            self._metadata = None
         self.dists = {}
         self.hidden = hidden
 
@@ -79,6 +83,18 @@
 
     version = property(get_version, set_version)
 
+    def _set_metadata(self, unpack=True):
+        """Set the metadatas, using the archive if needed"""
+        location = self.get_distribution().unpack()
+        pkg_info = os.path.join(location, 'PKG-INFO')
+        self._metadata = DistributionMetadata(pkg_info)
+
+    @property
+    def metadata(self):
+        if not self._metadata:
+            self._set_metadata()
+        return self._metadata
+
     @property
     def is_final(self):
         """proxy to version.is_final"""
@@ -137,7 +153,7 @@
                    .download(path=temp_path)
 
     def set_metadata(self, metadata):
-        self.metadata.update(metadata)
+        self._metadata.update(metadata)
 
     def __getitem__(self, item):
         """distributions are available using release["sdist"]"""
@@ -326,8 +342,7 @@
         """Filter and return a subset of releases matching the given predicate.
         """
         return ReleasesList(self.name, [release for release in self
-                                        if release.name == predicate.name
-                                        and predicate.match(release.version)])
+                                        if predicate.match(release.version)])
 
     def get_last(self, predicate, prefer_final=None):
         """Return the "last" release, that satisfy the given predicates.
diff --git a/src/distutils2/index/simple.py b/src/distutils2/index/simple.py
--- a/src/distutils2/index/simple.py
+++ b/src/distutils2/index/simple.py
@@ -160,7 +160,7 @@
 
         if not self._projects.has_key(predicate.name.lower()):
             raise ProjectNotFound()
-
+        
         releases = self._projects.get(predicate.name.lower())
         releases.sort_releases(prefer_final=prefer_final)
         return releases

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list