Index: distutils/dist.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/dist.py,v
retrieving revision 1.43
diff -c -r1.43 dist.py
*** distutils/dist.py 2001/01/15 16:09:35 1.43
--- distutils/dist.py 2001/03/10 01:09:19
***************
*** 16,21 ****
--- 16,22 ----
from distutils import sysconfig
from distutils.fancy_getopt import FancyGetopt, translate_longopt
from distutils.util import check_environ, strtobool
+ from xmllib import XMLParser
# Regex to define acceptable Distutils command names. This is not *quite*
***************
*** 931,1000 ****
class DistributionMetadata:
- """Dummy class to hold the distribution meta-data: name, version,
- author, and so forth.
"""
!
! def __init__ (self):
! self.name = None
! self.version = None
! self.author = None
! self.author_email = None
! self.maintainer = None
! self.maintainer_email = None
! self.url = None
! self.licence = None
! self.description = None
! self.long_description = None
!
! # -- Metadata query methods ----------------------------------------
!
! def get_name (self):
! return self.name or "UNKNOWN"
!
! def get_version(self):
! return self.version or "???"
! def get_fullname (self):
! return "%s-%s" % (self.get_name(), self.get_version())
! def get_author(self):
! return self.author or "UNKNOWN"
! def get_author_email(self):
! return self.author_email or "UNKNOWN"
! def get_maintainer(self):
! return self.maintainer or "UNKNOWN"
! def get_maintainer_email(self):
! return self.maintainer_email or "UNKNOWN"
! def get_contact(self):
! return (self.maintainer or
! self.author or
! "UNKNOWN")
! def get_contact_email(self):
! return (self.maintainer_email or
! self.author_email or
! "UNKNOWN")
- def get_url(self):
- return self.url or "UNKNOWN"
! def get_licence(self):
! return self.licence or "UNKNOWN"
! def get_description(self):
! return self.description or "UNKNOWN"
! def get_long_description(self):
! return self.long_description or "UNKNOWN"
! # class DistributionMetadata
def fix_help_options (options):
"""Convert a 4-tuple 'help_options' list as found in various command
classes to the 3-tuple form required by FancyGetopt.
--- 932,1121 ----
class DistributionMetadata:
"""
! Holds a distribution's meta-data such as author, title, version,
! etc. Metadata instances work like dictionaries mapping meta-data
! names to values.
! """
! # common meta-data names
! common_names=('name', 'version', 'author', 'author_email',
! 'maintainer', 'maintainer_email', 'url', 'license',
! 'description', 'long_description')
!
! # these meta-data are derived from other meta-data
! derived_names=('fullname', 'contact', 'contact_email')
!
! # value for null meta-data items
! null_value='UNKNOWN'
!
! def __init__(self):
! self.data={}
! for name in self.common_names:
! self[name]=None
! # Mapping methods
! # ---------------
!
! def __getitem__(self, key):
! # Handles some special meta-data names, and returns a UNKNOWN
! # for null values
! if key=='fullname':
! return '%s-%s' % (self.data['name'], self.data['version'])
! elif key=='contact':
! return (self.data['maintainer']
! or self.data['author']
! or self.null_value)
! elif key=='contact_email':
! return (self.data['maintainer_email']
! or self.data['author_email']
! or self.null_value)
! # It's license not licence, Greg ;-)
! elif key=='licence':
! return self.data['license'] or self.null_value
! return self.data[key] or self.null_value
!
! def get(self, key, default=None):
! # Does not differentiate between non-existent and null
! # meta-data items.
! try:
! v=self[key]
! if v==self.null_value:
! return default
! return v
! except KeyError:
! return default
!
! def __setitem__(self, key, value):
! # It's license not licence, Greg ;-)
! if key=='licence':
! key='license'
! self.data[key]=value
!
! def keys(self):
! return self.data.keys() + list(self.derived_names)
!
! def items(self):
! result=[]
! for key in self.keys():
! result.append((key, self[key]))
! return result
!
! def values(self):
! result=[]
! for key in self.keys():
! result.append(self[key])
! return result
! # Backward compatiblity
! # ---------------------
! def __getattr__(self, key):
! """
! Allow getitem access via get_XXX methods. This is what the
! Distribution class expects. Note, this will only work for
! meta-data names that are legal Python identifiers.
! """
! if key[0:4]=='get_':
! return lambda s=self, k=key[4:]: s[k]
!
! # Serialization methods
! # ---------------------
!
! def write_data(self, file):
! """
! Write meta-data to an open file object. The meta-data is
! written in XML format. All each meta-data item is enclosed in
! an 'item' element, with a contained 'name' and 'value'
! element. All meta-data items are contained in a 'metadata'
! element. For example:
!
!
! -
! name
! Distutils
!
! -
! version
! 1.0.1
!
! ...
!
! The value 'None' is encoded as an empty 'value' element.
! """
! file.write('\n')
! for key, value in self.items():
! file.write('- \n')
! file.write('%s\n' % escape(key))
! if value is None:
! file.write('')
! else:
! file.write('%s\n' % escape(value))
! file.write('
\n')
! file.write('')
! def read_data(self, file):
! """
! Read meta-data from an open file object. Updates the meta-data
! of this instance.
! """
! parser=MetadataParser()
! parser.feed(file.read())
! parser.close()
! for key, value in parser.metadata.items():
! if key not in self.derived_names:
! self[key]=value
! # class DistributionMetadata
! class MetadataParser(XMLParser):
! """
! Parses meta-data xml files. After parsing the meta-data is stored
! in the instance attribute dictionary 'metadata'.
! """
! in_name=in_value=0
! def unknown_starttag(self, tag, attributes):
! if tag=='metadata':
! self.metadata={}
! elif tag=='item':
! self.name=''
! self.value=''
! elif tag=='name':
! self.in_name=1
! elif tag=='value':
! self.in_value=1
!
! def unknown_endtag(self, tag):
! if tag=='item':
! self.metadata[self.name]=self.value
! elif tag=='name':
! self.in_name=0
! elif tag=='value':
! self.in_value=0
!
! def handle_data(self, data):
! if self.in_name:
! self.name=self.name + data
! elif self.in_value:
! self.value=self.value + data
! def handle_cdata(self, data):
! self.handle_data(data)
+ def escape(text):
+ """
+ XML escape text.
+ """
+ text=string.replace(text, '&', '&')
+ text=string.replace(text, '<', '<')
+ text=string.replace(text, '>', '<')
+ return text
+
def fix_help_options (options):
"""Convert a 4-tuple 'help_options' list as found in various command
classes to the 3-tuple form required by FancyGetopt.
Index: distutils/command/bdist_wininst.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/command/bdist_wininst.py,v
retrieving revision 1.19
diff -c -r1.19 bdist_wininst.py
*** distutils/command/bdist_wininst.py 2001/02/19 09:20:30 1.19
--- distutils/command/bdist_wininst.py 2001/03/10 01:09:20
***************
*** 143,153 ****
# 'info' will be displayed in the installer's dialog box,
# describing the items to be installed.
! info = (metadata.long_description or '') + '\n'
! for name in dir(metadata):
! if (name != 'long_description'):
! data = getattr(metadata, name)
if data:
info = info + ("\n %s: %s" % \
(string.capitalize(name), data))
--- 143,153 ----
# 'info' will be displayed in the installer's dialog box,
# describing the items to be installed.
! info = metadata.get('long_description', '') + '\n'
! for name in metadata.keys():
! if name != 'long_description':
! data = metadata.get(name)
if data:
info = info + ("\n %s: %s" % \
(string.capitalize(name), data))
Index: distutils/command/sdist.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/command/sdist.py,v
retrieving revision 1.51
diff -c -r1.51 sdist.py
*** distutils/command/sdist.py 2000/10/14 04:06:40 1.51
--- distutils/command/sdist.py 2001/03/10 01:09:21
***************
*** 161,179 ****
missing = []
for attr in ('name', 'version', 'url'):
! if not (hasattr(metadata, attr) and getattr(metadata, attr)):
missing.append(attr)
if missing:
self.warn("missing required meta-data: " +
string.join(missing, ", "))
! if metadata.author:
! if not metadata.author_email:
self.warn("missing meta-data: if 'author' supplied, " +
"'author_email' must be supplied too")
! elif metadata.maintainer:
! if not metadata.maintainer_email:
self.warn("missing meta-data: if 'maintainer' supplied, " +
"'maintainer_email' must be supplied too")
else:
--- 161,179 ----
missing = []
for attr in ('name', 'version', 'url'):
! if not metadata.get(attr):
missing.append(attr)
if missing:
self.warn("missing required meta-data: " +
string.join(missing, ", "))
! if metadata.get('author'):
! if not metadata.get('author_email'):
self.warn("missing meta-data: if 'author' supplied, " +
"'author_email' must be supplied too")
! elif metadata.get('maintainer'):
! if not metadata.get('maintainer_email'):
self.warn("missing meta-data: if 'maintainer' supplied, " +
"'maintainer_email' must be supplied too")
else: