diff options
author | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-12-08 09:45:25 (GMT) |
---|---|---|
committer | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-12-08 09:45:25 (GMT) |
commit | b88a49607a6e36489a41003a66b673f573f32069 (patch) | |
tree | 397cb44893ec683ae459905d4b3d2f022a462410 /Lib/distutils/dist.py | |
parent | 0b9293f28bcfc05cb67b2b3f9c6c1fec3194ea28 (diff) | |
download | cpython-b88a49607a6e36489a41003a66b673f573f32069.zip cpython-b88a49607a6e36489a41003a66b673f573f32069.tar.gz cpython-b88a49607a6e36489a41003a66b673f573f32069.tar.bz2 |
Merged revisions 76702,76704 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76702 | tarek.ziade | 2009-12-08 09:56:49 +0100 (Tue, 08 Dec 2009) | 1 line
Issue #7457: added a read_pkg_file method to distutils.dist.DistributionMetadata so we can read back PKG-INFO files
........
r76704 | tarek.ziade | 2009-12-08 10:39:51 +0100 (Tue, 08 Dec 2009) | 1 line
removed the usage of rfc822 in favor of email.message.Message
........
Diffstat (limited to 'Lib/distutils/dist.py')
-rw-r--r-- | Lib/distutils/dist.py | 90 |
1 files changed, 73 insertions, 17 deletions
diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index 90af6e2..353525e 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -7,6 +7,7 @@ being built/installed/distributed. __revision__ = "$Id$" import sys, os, re +from email import message_from_file try: import warnings @@ -1014,25 +1015,80 @@ class DistributionMetadata: "provides", "requires", "obsoletes", ) - def __init__ (self): - self.name = None - self.version = None - self.author = None - self.author_email = None + def __init__(self, path=None): + if path is not None: + self.read_pkg_file(open(path)) + else: + self.name = None + self.version = None + self.author = None + self.author_email = None + self.maintainer = None + self.maintainer_email = None + self.url = None + self.license = None + self.description = None + self.long_description = None + self.keywords = None + self.platforms = None + self.classifiers = None + self.download_url = None + # PEP 314 + self.provides = None + self.requires = None + self.obsoletes = None + + def read_pkg_file(self, file): + """Reads the metadata values from a file object.""" + msg = message_from_file(file) + + def _read_field(name): + value = msg[name] + if value == 'UNKNOWN': + return None + return value + + def _read_list(name): + values = msg.get_all(name, None) + if values == []: + return None + return values + + metadata_version = msg['metadata-version'] + self.name = _read_field('name') + self.version = _read_field('version') + self.description = _read_field('summary') + # we are filling author only. + self.author = _read_field('author') self.maintainer = None + self.author_email = _read_field('author-email') self.maintainer_email = None - self.url = None - self.license = None - self.description = None - self.long_description = None - self.keywords = None - self.platforms = None - self.classifiers = None - self.download_url = None - # PEP 314 - self.provides = None - self.requires = None - self.obsoletes = None + self.url = _read_field('home-page') + self.license = _read_field('license') + + if 'download-url' in msg: + self.download_url = _read_field('download-url') + else: + self.download_url = None + + self.long_description = _read_field('description') + self.description = _read_field('summary') + + if 'keywords' in msg: + self.keywords = _read_field('keywords').split(',') + + self.platforms = _read_list('platform') + self.classifiers = _read_list('classifier') + + # PEP 314 - these fields only exist in 1.1 + if metadata_version == '1.1': + self.requires = _read_list('requires') + self.provides = _read_list('provides') + self.obsoletes = _read_list('obsoletes') + else: + self.requires = None + self.provides = None + self.obsoletes = None def write_pkg_info(self, base_dir): """Write the PKG-INFO file into the release tree. |