Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/upload.py @ 74135:9c19df6c8ea0 3.2
News entry for Issue12798
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Fri, 23 Dec 2011 11:11:21 +0800 |
| parents | 3c9232a684ae |
| children | ef16a3db4628 |
| 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 |
|
51892
4fd80e66b107
Merged revisions 70017 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
9 import sys |
|
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 |
|
57846
86b5df04634c
Merged revisions 76954 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54568
diff
changeset
|
15 from base64 import standard_b64encode |
|
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 |
|
51892
4fd80e66b107
Merged revisions 70017 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
18 # this keeps compatibility for 2.3 and 2.4 |
|
4fd80e66b107
Merged revisions 70017 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
19 if sys.version < "2.5": |
|
4fd80e66b107
Merged revisions 70017 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
20 from md5 import md5 |
|
4fd80e66b107
Merged revisions 70017 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
21 else: |
|
4fd80e66b107
Merged revisions 70017 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
22 from hashlib import md5 |
|
4fd80e66b107
Merged revisions 70017 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
23 |
|
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
|
24 class upload(PyPIRCCommand): |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
25 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
26 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
|
27 |
|
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
|
28 user_options = PyPIRCCommand.user_options + [ |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
29 ('sign', 's', |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
30 '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
|
31 ('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
|
32 ] |
|
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
|
33 |
|
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
|
34 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
|
35 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
36 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
|
37 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
|
38 self.username = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
39 self.password = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
40 self.show_response = 0 |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
41 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
|
42 self.identity = None |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
43 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 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
|
48 "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
|
49 ) |
|
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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 |
|
50639
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
49784
diff
changeset
|
57 # getting the password from the distribution |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
49784
diff
changeset
|
58 # if previously set by the register command |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
49784
diff
changeset
|
59 if not self.password and self.distribution.password: |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
49784
diff
changeset
|
60 self.password = self.distribution.password |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
49784
diff
changeset
|
61 |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
62 def run(self): |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 |
|
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
|
68 def upload_file(self, command, pyversion, filename): |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
69 # Sign if requested |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 spawn(gpg_args, |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
75 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
|
76 |
|
36248
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
77 # 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
|
78 # register a new release |
|
66007
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
64551
diff
changeset
|
79 f = open(filename,'rb') |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
64551
diff
changeset
|
80 try: |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
64551
diff
changeset
|
81 content = f.read() |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
64551
diff
changeset
|
82 finally: |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
64551
diff
changeset
|
83 f.close() |
|
36248
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
84 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
|
85 data = { |
|
36248
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
86 # action |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
87 ':action': 'file_upload', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
88 'protcol_version': '1', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
89 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
90 # identify release |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
91 'name': meta.get_name(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
92 'version': meta.get_version(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
93 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
94 # file content |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
95 '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
|
96 'filetype': command, |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
97 'pyversion': pyversion, |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
98 'md5_digest': md5(content).hexdigest(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
99 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
100 # additional meta-data |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
101 'metadata_version' : '1.0', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
102 'summary': meta.get_description(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
103 'home_page': meta.get_url(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
104 'author': meta.get_contact(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
105 '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
|
106 'license': meta.get_licence(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
107 'description': meta.get_long_description(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
108 'keywords': meta.get_keywords(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
109 'platform': meta.get_platforms(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
110 'classifiers': meta.get_classifiers(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
111 '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
|
112 # PEP 314 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
113 'provides': meta.get_provides(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
114 'requires': meta.get_requires(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
115 '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
|
116 } |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
117 comment = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
118 if command == 'bdist_rpm': |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
119 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
|
120 if dist: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
121 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
|
122 elif command == 'bdist_dumb': |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
123 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
|
124 data['comment'] = comment |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
125 |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
126 if self.sign: |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
127 data['gpg_signature'] = (os.path.basename(filename) + ".asc", |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
128 open(filename+".asc").read()) |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
129 |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
130 # 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
|
131 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
|
132 # 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
|
133 # Anyway PyPI only accepts ascii for both username or password. |
|
57846
86b5df04634c
Merged revisions 76954 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
54568
diff
changeset
|
134 auth = "Basic " + standard_b64encode(user_pass).decode('ascii') |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
135 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
136 # 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
|
137 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
138 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
|
139 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
|
140 body = io.BytesIO() |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
141 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
|
142 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
|
143 # 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
|
144 if type(value) != type([]): |
|
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: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
147 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
|
148 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
|
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: |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 body.write(value) |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 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
|
160 body = body.getvalue() |
|
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 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
|
163 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
164 # build the Request |
|
48334
5a416a6417d3
Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
47318
diff
changeset
|
165 # 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
|
166 # auth right with the first request |
|
48334
5a416a6417d3
Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
47318
diff
changeset
|
167 # 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
|
168 schema, netloc, url, params, query, fragments = \ |
|
48334
5a416a6417d3
Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
47318
diff
changeset
|
169 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
|
170 assert not params and not query and not fragments |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
171 if schema == 'http': |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
172 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
|
173 elif schema == 'https': |
|
49784
f95ff96fd792
#4338: Fix the distutils "setup.py upload" command.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48334
diff
changeset
|
174 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
|
175 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42501
diff
changeset
|
176 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
|
177 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
178 data = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
179 loglevel = log.INFO |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
180 try: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
181 http.connect() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
182 http.putrequest("POST", url) |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
183 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
|
184 '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
|
185 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
|
186 http.putheader('Authorization', auth) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
187 http.endheaders() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
188 http.send(body) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
189 except socket.error as e: |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
190 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
|
191 return |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
192 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
193 r = http.getresponse() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
194 if r.status == 200: |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
195 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
|
196 log.INFO) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
197 else: |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
198 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
|
199 log.ERROR) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
200 if self.show_response: |
|
64551
d27d4bd488dc
Merged revisions 84614 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
64548
diff
changeset
|
201 msg = '\n'.join(('-' * 75, r.read(), '-' * 75)) |
|
64548
e0623b6b43b6
Merged revisions 84611 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
57846
diff
changeset
|
202 self.announce(msg, log.INFO) |
