annotate Lib/distutils/command/upload.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents b36cb4602e21
children aa3a7d5e0478
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34793
3da21fdc2ee7 Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1 """distutils.command.upload
3da21fdc2ee7 Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
2
3da21fdc2ee7 Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
3 Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
4 import os
34810
8fc8e7a6071c Add missing socket import
Martin v. Löwis <martin@v.loewis.de>
parents: 34805
diff changeset
5 import socket
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
6 import platform
54758
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
7 from urllib2 import urlopen, Request, HTTPError
57843
096b1d997853 Fixed #7552: fixed distutils.command.upload failure on very long passwords
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54758
diff changeset
8 from base64 import standard_b64encode
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
9 import urlparse
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
10 import cStringIO as StringIO
54757
1b3a19037f76 code cleanup
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52585
diff changeset
11 from hashlib import md5
34793
3da21fdc2ee7 Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
12
57847
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57843
diff changeset
13 from distutils.errors import DistutilsOptionError
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
14 from distutils.core import PyPIRCCommand
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
15 from distutils.spawn import spawn
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
16 from distutils import log
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
17
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
18 class upload(PyPIRCCommand):
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
19
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
20 description = "upload binary package to PyPI"
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
21
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
22 user_options = PyPIRCCommand.user_options + [
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
23 ('sign', 's',
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
24 'sign files to upload using gpg'),
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
25 ('identity=', 'i', 'GPG identity used to sign files'),
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
26 ]
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
27
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
28 boolean_options = PyPIRCCommand.boolean_options + ['sign']
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
29
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
30 def initialize_options(self):
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
31 PyPIRCCommand.initialize_options(self)
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
32 self.username = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
33 self.password = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
34 self.show_response = 0
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
35 self.sign = False
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
36 self.identity = None
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
37
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
38 def finalize_options(self):
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
39 PyPIRCCommand.finalize_options(self)
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
40 if self.identity and not self.sign:
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
41 raise DistutilsOptionError(
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
42 "Must use --sign for --identity to have meaning"
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
43 )
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
44 config = self._read_pypirc()
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
45 if config != {}:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
46 self.username = config['username']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
47 self.password = config['password']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
48 self.repository = config['repository']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
49 self.realm = config['realm']
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
50
50637
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
51 # getting the password from the distribution
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
52 # if previously set by the register command
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
53 if not self.password and self.distribution.password:
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
54 self.password = self.distribution.password
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
55
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
56 def run(self):
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
57 if not self.distribution.dist_files:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
58 raise DistutilsOptionError("No dist file created in earlier command")
34805
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34803
diff changeset
59 for command, pyversion, filename in self.distribution.dist_files:
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34803
diff changeset
60 self.upload_file(command, pyversion, filename)
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
61
34805
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34803
diff changeset
62 def upload_file(self, command, pyversion, filename):
54758
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
63 # Makes sure the repository URL is compliant
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
64 schema, netloc, url, params, query, fragments = \
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
65 urlparse.urlparse(self.repository)
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
66 if params or query or fragments:
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
67 raise AssertionError("Incompatible url %s" % self.repository)
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
68
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
69 if schema not in ('http', 'https'):
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
70 raise AssertionError("unsupported schema " + schema)
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
71
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
72 # Sign if requested
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
73 if self.sign:
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
74 gpg_args = ["gpg", "--detach-sign", "-a", filename]
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
75 if self.identity:
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
76 gpg_args[2:2] = ["--local-user", self.identity]
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
77 spawn(gpg_args,
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
78 dry_run=self.dry_run)
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
79
36248
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
80 # Fill in the data - send all the meta-data in case we need to
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
81 # register a new release
66008
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 64552
diff changeset
82 f = open(filename,'rb')
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 64552
diff changeset
83 try:
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 64552
diff changeset
84 content = f.read()
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 64552
diff changeset
85 finally:
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 64552
diff changeset
86 f.close()
36248
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
87 meta = self.distribution.metadata
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
88 data = {
36248
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
89 # action
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
90 ':action': 'file_upload',
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
91 'protcol_version': '1',
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
92
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
93 # identify release
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
94 'name': meta.get_name(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
95 'version': meta.get_version(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
96
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
97 # file content
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
98 'content': (os.path.basename(filename),content),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
99 'filetype': command,
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
100 'pyversion': pyversion,
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
101 'md5_digest': md5(content).hexdigest(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
102
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
103 # additional meta-data
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
104 'metadata_version' : '1.0',
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
105 'summary': meta.get_description(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
106 'home_page': meta.get_url(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
107 'author': meta.get_contact(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
108 'author_email': meta.get_contact_email(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
109 'license': meta.get_licence(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
110 'description': meta.get_long_description(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
111 'keywords': meta.get_keywords(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
112 'platform': meta.get_platforms(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
113 'classifiers': meta.get_classifiers(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
114 'download_url': meta.get_download_url(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
115 # PEP 314
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
116 'provides': meta.get_provides(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
117 'requires': meta.get_requires(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
118 'obsoletes': meta.get_obsoletes(),
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
119 }
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
120 comment = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
121 if command == 'bdist_rpm':
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
122 dist, version, id = platform.dist()
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
123 if dist:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
124 comment = 'built for %s %s' % (dist, version)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
125 elif command == 'bdist_dumb':
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
126 comment = 'built for %s' % platform.platform(terse=1)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
127 data['comment'] = comment
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
128
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
129 if self.sign:
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
130 data['gpg_signature'] = (os.path.basename(filename) + ".asc",
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
131 open(filename+".asc").read())
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
132
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
133 # set up the authentication
57844
1772195405e7 Merged revisions 76952 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
134 auth = "Basic " + standard_b64encode(self.username + ":" +
1772195405e7 Merged revisions 76952 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
135 self.password)
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
136
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
137 # Build up the MIME payload for the POST data
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
138 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
139 sep_boundary = '\n--' + boundary
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
140 end_boundary = sep_boundary + '--'
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
141 body = StringIO.StringIO()
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
142 for key, value in data.items():
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
143 # handle multiple entries for the same name
54757
1b3a19037f76 code cleanup
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52585
diff changeset
144 if not isinstance(value, list):
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
145 value = [value]
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
146 for value in value:
54757
1b3a19037f76 code cleanup
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52585
diff changeset
147 if isinstance(value, tuple):
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
148 fn = ';filename="%s"' % value[0]
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
149 value = value[1]
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
150 else:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
151 fn = ""
58464
3947fdca2f40 Merged revisions 77717 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57844
diff changeset
152
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
153 body.write(sep_boundary)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
154 body.write('\nContent-Disposition: form-data; name="%s"'%key)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
155 body.write(fn)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
156 body.write("\n\n")
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
157 body.write(value)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
158 if value and value[-1] == '\r':
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
159 body.write('\n') # write an extra newline (lurve Macs)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
160 body.write(end_boundary)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
161 body.write("\n")
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
162 body = body.getvalue()
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
163
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
164 self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
165
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
166 # build the Request
54758
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
167 headers = {'Content-type':
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
168 'multipart/form-data; boundary=%s' % boundary,
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
169 'Content-length': str(len(body)),
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
170 'Authorization': auth}
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
171
54758
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
172 request = Request(self.repository, data=body,
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
173 headers=headers)
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
174 # send the data
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
175 try:
54758
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
176 result = urlopen(request)
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
177 status = result.getcode()
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
178 reason = result.msg
66649
301d23d6dd9b Fix for issue10367, courtesy of Daniel Tavares.
Phillip J. Eby <pje@telecommunity.com>
parents: 66008
diff changeset
179 if self.show_response:
301d23d6dd9b Fix for issue10367, courtesy of Daniel Tavares.
Phillip J. Eby <pje@telecommunity.com>
parents: 66008
diff changeset
180 msg = '\n'.join(('-' * 75, r.read(), '-' * 75))
301d23d6dd9b Fix for issue10367, courtesy of Daniel Tavares.
Phillip J. Eby <pje@telecommunity.com>
parents: 66008
diff changeset
181 self.announce(msg, log.INFO)
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
182 except socket.error, e:
39054
f2ac31fc369e Fix SF#1457312: bad socket error handling in distutils "upload" command.
Phillip J. Eby <pje@telecommunity.com>
parents: 38052
diff changeset
183 self.announce(str(e), log.ERROR)
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
184 return
54758
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
185 except HTTPError, e:
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
186 status = e.code
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
187 reason = e.msg
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
188
54758
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
189 if status == 200:
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
190 self.announce('Server response (%s): %s' % (status, reason),
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
191 log.INFO)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
192 else:
54758
4373f0e4eb21 Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54757
diff changeset
193 self.announce('Upload failed (%s): %s' % (status, reason),
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
194 log.ERROR)