Commits

Tarek Ziadé committed 27dd944

refactored the code that builds the HTTP requests for both register and upload

  • Participants
  • Parent commits 010d480

Comments (0)

Files changed (3)

File src/distutils2/command/register.py

     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):

File src/distutils2/command/upload.py

         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()

File src/distutils2/config.py

 
         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