[Python-checkins] distutils2: refactored the code that builds the HTTP requests for both register and upload
tarek.ziade
python-checkins at python.org
Tue Apr 13 01:23:24 CEST 2010
tarek.ziade pushed 27dd944da9b1 to distutils2:
http://hg.python.org/distutils2/rev/27dd944da9b1
changeset: 115:27dd944da9b1
tag: tip
user: Tarek Ziade <tarek at ziade.org>
date: Tue Apr 13 01:23:15 2010 +0200
summary: refactored the code that builds the HTTP requests for both register and upload
files: src/distutils2/command/register.py, src/distutils2/command/upload.py, src/distutils2/config.py
diff --git a/src/distutils2/command/register.py b/src/distutils2/command/register.py
--- a/src/distutils2/command/register.py
+++ b/src/distutils2/command/register.py
@@ -224,37 +224,8 @@
def build_post_data(self, action):
# figure the data to send - the metadata plus some additional
# information used by the package server
- meta = self.distribution.metadata
- data = {
- ':action': action,
- 'metadata_version' : meta.version,
- 'name': meta['Name'],
- 'version': meta['Version'],
- 'summary': meta['Summary'],
- 'home_page': meta['Home-page'],
- 'author': meta['Author'],
- 'author_email': meta['Author-email'],
- 'license': meta['License'],
- 'description': meta['Description'],
- 'keywords': meta['Keywords'],
- 'platform': meta['Platform'],
- 'classifier': meta['Classifier'],
- 'download_url': meta['Download-URL'],
- }
-
- if meta.version == '1.2':
- data['requires_dist'] = meta['Requires-Dist']
- data['requires_python'] = meta['Requires-Python']
- data['requires_external'] = meta['Requires-External']
- data['provides_dist'] = meta['Provides-Dist']
- data['obsoletes_dist'] = meta['Obsoletes-Dist']
- data['project_url'] = meta['Project-URL']
-
- elif meta.version == '1.1':
- data['provides'] = meta['Provides']
- data['requires'] = meta['Requires']
- data['obsoletes'] = meta['Obsoletes']
-
+ data = self._metadata_to_pypy_dict()
+ data[':action'] = action
return data
def post_to_server(self, data, auth=None):
diff --git a/src/distutils2/command/upload.py b/src/distutils2/command/upload.py
--- a/src/distutils2/command/upload.py
+++ b/src/distutils2/command/upload.py
@@ -85,40 +85,16 @@
content = open(filename,'rb').read()
meta = self.distribution.metadata
- data = {
- # action
- ':action': 'file_upload',
- 'protcol_version': '1',
+ data = self._metadata_to_pypy_dict()
- # identify release
- 'name': meta['Name'],
- 'version': meta['Version'],
+ # extra upload infos
+ data[':action'] = 'file_upload'
+ data['protcol_version'] = '1'
+ data['content'] = os.path.basename(filename), content
+ data['filetype'] = command
+ data['pyversion'] = pyversion
+ data['md5_digest'] = md5(content).hexdigest()
- # file content
- 'content': (os.path.basename(filename),content),
- 'filetype': command,
- 'pyversion': pyversion,
- 'md5_digest': md5(content).hexdigest(),
-
- # additional meta-data
- # XXX Implement 1.1
- 'metadata_version' : '1.0',
- 'name': meta['Name'],
- 'version': meta['Version'],
- 'summary': meta['Summary'],
- 'home_page': meta['Home-page'],
- 'author': meta['Author'],
- 'author_email': meta['Author-email'],
- 'license': meta['License'],
- 'description': meta['Description'],
- 'keywords': meta['Keywords'],
- 'platform': meta['Platform'],
- 'classifiers': meta['Classifier'],
- 'download_url': meta['Download-URL'],
- #'provides': meta['Provides'],
- #'requires': meta['Requires'],
- #'obsoletes': meta['Obsoletes'],
- }
comment = ''
if command == 'bdist_rpm':
dist, version, id = platform.dist()
diff --git a/src/distutils2/config.py b/src/distutils2/config.py
--- a/src/distutils2/config.py
+++ b/src/distutils2/config.py
@@ -107,6 +107,39 @@
return {}
+ def _metadata_to_pypy_dict(self):
+ meta = self.distribution.metadata
+ data = {
+ 'metadata_version' : meta.version,
+ 'name': meta['Name'],
+ 'version': meta['Version'],
+ 'summary': meta['Summary'],
+ 'home_page': meta['Home-page'],
+ 'author': meta['Author'],
+ 'author_email': meta['Author-email'],
+ 'license': meta['License'],
+ 'description': meta['Description'],
+ 'keywords': meta['Keywords'],
+ 'platform': meta['Platform'],
+ 'classifier': meta['Classifier'],
+ 'download_url': meta['Download-URL'],
+ }
+
+ if meta.version == '1.2':
+ data['requires_dist'] = meta['Requires-Dist']
+ data['requires_python'] = meta['Requires-Python']
+ data['requires_external'] = meta['Requires-External']
+ data['provides_dist'] = meta['Provides-Dist']
+ data['obsoletes_dist'] = meta['Obsoletes-Dist']
+ data['project_url'] = meta['Project-URL']
+
+ elif meta.version == '1.1':
+ data['provides'] = meta['Provides']
+ data['requires'] = meta['Requires']
+ data['obsoletes'] = meta['Obsoletes']
+
+ return data
+
def initialize_options(self):
"""Initialize options."""
self.repository = None
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list