Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/upload.py @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 807d83f57bc8 |
| children | baf1a482b57d |
| 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 | 11 from hashlib import md5 |
|
47078
57f61dad7b3b
Fixed import of configparser in the distutils module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47013
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 |
| 54757 | 14 from distutils.core import PyPIRCCommand |
| 15 from distutils.spawn import spawn | |
| 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 |
|
35210
c857070e97e8
Fix "upload" command garbling and truncating files on Windows. If it's a
Phillip J. Eby <pje@telecommunity.com>
parents:
34818
diff
changeset
|
82 content = open(filename,'rb').read() |
|
36248
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
83 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
|
84 data = { |
|
36248
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
85 # action |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
86 ':action': 'file_upload', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
87 'protcol_version': '1', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
88 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
89 # identify release |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
90 'name': meta.get_name(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
91 'version': meta.get_version(), |
|
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 # file content |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
94 '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
|
95 'filetype': command, |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
96 'pyversion': pyversion, |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
97 'md5_digest': md5(content).hexdigest(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
98 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
99 # additional meta-data |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
100 'metadata_version' : '1.0', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
101 'summary': meta.get_description(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
102 'home_page': meta.get_url(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
103 'author': meta.get_contact(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
104 '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
|
105 'license': meta.get_licence(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
106 'description': meta.get_long_description(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
107 'keywords': meta.get_keywords(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
108 'platform': meta.get_platforms(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
109 'classifiers': meta.get_classifiers(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
110 '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
|
111 # PEP 314 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
112 'provides': meta.get_provides(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
113 'requires': meta.get_requires(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
114 '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
|
115 } |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
116 comment = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
117 if command == 'bdist_rpm': |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
118 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
|
119 if dist: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
120 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
|
121 elif command == 'bdist_dumb': |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
122 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
|
123 data['comment'] = comment |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
124 |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
125 if self.sign: |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
126 data['gpg_signature'] = (os.path.basename(filename) + ".asc", |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
127 open(filename+".asc").read()) |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
128 |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
129 # set up the authentication |
|
57843
096b1d997853
Fixed #7552: fixed distutils.command.upload failure on very long passwords
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54758
diff
changeset
|
130 auth = "Basic " + standard_b64encode(self.username + ":" + |
|
096b1d997853
Fixed #7552: fixed distutils.command.upload failure on very long passwords
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54758
diff
changeset
|
131 self.password) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
132 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
133 # 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
|
134 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
135 sep_boundary = '\n--' + boundary |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
136 end_boundary = sep_boundary + '--' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
137 body = StringIO.StringIO() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
138 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
|
139 # handle multiple entries for the same name |
| 54757 | 140 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
|
141 value = [value] |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
142 for value in value: |
| 54757 | 143 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
|
144 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
|
145 value = value[1] |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
146 else: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
147 fn = "" |
|
58462
807d83f57bc8
Fixed #7748: now upload and register commands don't need to force the encoding anymore : DistributionMetada returns utf8 strings
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
57847
diff
changeset
|
148 |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
149 body.write(sep_boundary) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
150 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
|
151 body.write(fn) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
152 body.write("\n\n") |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
153 body.write(value) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
154 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
|
155 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
|
156 body.write(end_boundary) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
157 body.write("\n") |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
158 body = body.getvalue() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
159 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
160 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
|
161 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
162 # build the Request |
|
54758
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
163 headers = {'Content-type': |
|
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
164 '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
|
165 'Content-length': str(len(body)), |
|
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
166 'Authorization': auth} |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
167 |
|
54758
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
168 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
|
169 headers=headers) |
|
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
170 # send the data |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
171 try: |
|
54758
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
172 result = urlopen(request) |
|
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
173 status = result.getcode() |
|
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
174 reason = result.msg |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
175 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
|
176 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
|
177 return |
|
54758
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
178 except HTTPError, e: |
|
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
179 status = e.code |
|
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
180 reason = e.msg |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
181 |
|
54758
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
182 if status == 200: |
|
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
183 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
|
184 log.INFO) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
185 else: |
|
54758
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
186 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
|
187 log.ERROR) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
188 if self.show_response: |
|
54758
4373f0e4eb21
Issue #6286: distutils upload command now uses urllib2
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54757
diff
changeset
|
189 self.announce('-'*75, result.read(), '-'*75) |
