Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/upload.py @ 51749:1408feec0084 3.0
Merged revisions 69798 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r69798 | benjamin.peterson | 2009-02-19 22:02:38 -0600 (Thu, 19 Feb 2009) | 13 lines
Merged revisions 69769,69776 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69769 | georg.brandl | 2009-02-19 02:30:06 -0600 (Thu, 19 Feb 2009) | 1 line
#5310, #3558: fix operator precedence table.
........
r69776 | georg.brandl | 2009-02-19 10:34:51 -0600 (Thu, 19 Feb 2009) | 2 lines
#5317: update IronPython URL.
........
................
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Fri, 20 Feb 2009 04:05:32 +0000 |
| parents | f95ff96fd792 |
| children | 589f6844d8e0 |
| 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).""" |
|
3da21fdc2ee7
Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
4 |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
5 from distutils.errors import * |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
diff
changeset
|
6 from distutils.core import PyPIRCCommand |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
7 from distutils.spawn import spawn |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
8 from distutils import log |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
9 from hashlib import md5 |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
10 import os, io |
|
34810
8fc8e7a6071c
Add missing socket import
Martin v. Löwis <martin@v.loewis.de>
parents:
34805
diff
changeset
|
11 import socket |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
12 import platform |
|
47012
35a8899256c2
Renamed ConfigParser to configparser.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
43193
diff
changeset
|
13 import configparser |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
14 import http.client as httpclient |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
15 import base64 |
|
48334
5a416a6417d3
Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
47318
diff
changeset
|
16 import urllib.parse |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
17 |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
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 |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
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'), |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
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 ] |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
diff
changeset
|
27 |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
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): |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
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 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
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): |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
diff
changeset
|
39 PyPIRCCommand.finalize_options(self) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36248
diff
changeset
|
40 if self.identity and not self.sign: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36248
diff
changeset
|
41 raise DistutilsOptionError( |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36248
diff
changeset
|
42 "Must use --sign for --identity to have meaning" |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36248
diff
changeset
|
43 ) |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
diff
changeset
|
44 config = self._read_pypirc() |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
diff
changeset
|
45 if config != {}: |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
diff
changeset
|
46 self.username = config['username'] |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
diff
changeset
|
47 self.password = config['password'] |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
diff
changeset
|
48 self.repository = config['repository'] |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47012
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 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
51 def run(self): |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 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
|
56 |
|
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
|
57 def upload_file(self, command, pyversion, filename): |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
58 # Sign if requested |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
59 if self.sign: |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36248
diff
changeset
|
60 gpg_args = ["gpg", "--detach-sign", "-a", filename] |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36248
diff
changeset
|
61 if self.identity: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36248
diff
changeset
|
62 gpg_args[2:2] = ["--local-user", self.identity] |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36248
diff
changeset
|
63 spawn(gpg_args, |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
64 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
|
65 |
|
36248
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
66 # 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
|
67 # 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
|
68 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
|
69 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
|
70 data = { |
|
36248
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
71 # action |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
72 ':action': 'file_upload', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
73 'protcol_version': '1', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
74 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
75 # identify release |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
76 'name': meta.get_name(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
77 'version': meta.get_version(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
78 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
79 # file content |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
80 '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
|
81 'filetype': command, |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
82 'pyversion': pyversion, |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
83 'md5_digest': md5(content).hexdigest(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
84 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
85 # additional meta-data |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
86 'metadata_version' : '1.0', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
87 'summary': meta.get_description(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
88 'home_page': meta.get_url(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
89 'author': meta.get_contact(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
90 '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
|
91 'license': meta.get_licence(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
92 'description': meta.get_long_description(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
93 'keywords': meta.get_keywords(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
94 'platform': meta.get_platforms(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
95 'classifiers': meta.get_classifiers(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
96 '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
|
97 # PEP 314 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
98 'provides': meta.get_provides(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
99 'requires': meta.get_requires(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
100 '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
|
101 } |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
102 comment = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
103 if command == 'bdist_rpm': |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
104 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
|
105 if dist: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
106 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
|
107 elif command == 'bdist_dumb': |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
108 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
|
109 data['comment'] = comment |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
110 |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
111 if self.sign: |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
112 data['gpg_signature'] = (os.path.basename(filename) + ".asc", |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
113 open(filename+".asc").read()) |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
114 |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
115 # set up the authentication |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
116 user_pass = (self.username + ":" + self.password).encode('ascii') |
|
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
117 # The exact encoding of the authentication string is debated. |
|
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
118 # Anyway PyPI only accepts ascii for both username or password. |
|
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
119 auth = "Basic " + base64.encodestring(user_pass).strip().decode('ascii') |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
120 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
121 # 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
|
122 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
123 sep_boundary = b'\n--' + boundary.encode('ascii') |
|
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
124 end_boundary = sep_boundary + b'--' |
|
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
125 body = io.BytesIO() |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
126 for key, value in data.items(): |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
127 title = '\nContent-Disposition: form-data; name="%s"' % key |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
128 # handle multiple entries for the same name |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
129 if type(value) != type([]): |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
130 value = [value] |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
131 for value in value: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
132 if type(value) is tuple: |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
133 title += '; filename="%s"' % value[0] |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
134 value = value[1] |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
135 else: |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
136 value = str(value).encode('utf-8') |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
137 body.write(sep_boundary) |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
138 body.write(title.encode('utf-8')) |
|
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
139 body.write(b"\n\n") |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
140 body.write(value) |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
141 if value and value[-1:] == b'\r': |
|
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
142 body.write(b'\n') # write an extra newline (lurve Macs) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
143 body.write(end_boundary) |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
144 body.write(b"\n") |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
145 body = body.getvalue() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
146 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
147 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
|
148 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
149 # build the Request |
|
48334
5a416a6417d3
Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
47318
diff
changeset
|
150 # We can't use urllib since we need to send the Basic |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
151 # auth right with the first request |
|
48334
5a416a6417d3
Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
47318
diff
changeset
|
152 # TODO(jhylton): Can we fix urllib? |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
153 schema, netloc, url, params, query, fragments = \ |
|
48334
5a416a6417d3
Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
47318
diff
changeset
|
154 urllib.parse.urlparse(self.repository) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
155 assert not params and not query and not fragments |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
156 if schema == 'http': |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
157 http = httpclient.HTTPConnection(netloc) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
158 elif schema == 'https': |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
159 http = httpclient.HTTPSConnection(netloc) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
160 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42501
diff
changeset
|
161 raise AssertionError("unsupported schema "+schema) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
162 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
163 data = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
164 loglevel = log.INFO |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
165 try: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
166 http.connect() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
167 http.putrequest("POST", url) |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
168 http.putheader('Content-type', |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
169 'multipart/form-data; boundary=%s'%boundary) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
170 http.putheader('Content-length', str(len(body))) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
171 http.putheader('Authorization', auth) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
172 http.endheaders() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
173 http.send(body) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
174 except socket.error as e: |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
175 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
|
176 return |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
177 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
178 r = http.getresponse() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
179 if r.status == 200: |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
180 self.announce('Server response (%s): %s' % (r.status, r.reason), |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
181 log.INFO) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
182 else: |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
183 self.announce('Upload failed (%s): %s' % (r.status, r.reason), |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
184 log.ERROR) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
185 if self.show_response: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
186 print('-'*75, r.read(), '-'*75) |
