Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/upload.py @ 39042:c02fa187e0f4 legacy-trunk
Part of SF patch #1484695. This removes dead code. The chksum was
already verified in .frombuf() on the lines above. If there was
a problem an exception is raised, so there was no way this condition
could have been true.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 10 Jul 2006 00:23:17 +0000 |
| parents | 32a187f3d5ba |
| children | f2ac31fc369e |
| 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 * |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
6 from distutils.core import Command |
|
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 |
|
38052
32a187f3d5ba
In stdlib, use hashlib instead of deprecated md5 and sha modules.
Georg Brandl <georg@python.org>
parents:
37294
diff
changeset
|
9 from hashlib import md5 |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
10 import os |
|
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 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
13 import ConfigParser |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
14 import httplib |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
15 import base64 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
16 import urlparse |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
17 import cStringIO as StringIO |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
18 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
19 class upload(Command): |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
20 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
21 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
|
22 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
23 DEFAULT_REPOSITORY = 'http://www.python.org/pypi' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
24 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
25 user_options = [ |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
26 ('repository=', 'r', |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
27 "url of repository [default: %s]" % DEFAULT_REPOSITORY), |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
28 ('show-response', None, |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
29 'display full response text from server'), |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
30 ('sign', 's', |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
31 '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
|
32 ('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
|
33 ] |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
34 boolean_options = ['show-response', '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): |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
37 self.username = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
38 self.password = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
39 self.repository = '' |
|
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 |
|
37294
b85ad2166c01
Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
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): |
|
37294
b85ad2166c01
Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents:
36248
diff
changeset
|
45 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
|
46 raise DistutilsOptionError( |
|
b85ad2166c01
Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents:
36248
diff
changeset
|
47 "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
|
48 ) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
49 if os.environ.has_key('HOME'): |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
50 rc = os.path.join(os.environ['HOME'], '.pypirc') |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
51 if os.path.exists(rc): |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
52 self.announce('Using PyPI login from %s' % rc) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
53 config = ConfigParser.ConfigParser({ |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
54 'username':'', |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
55 'password':'', |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
56 'repository':''}) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
57 config.read(rc) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
58 if not self.repository: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
59 self.repository = config.get('server-login', 'repository') |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
60 if not self.username: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
61 self.username = config.get('server-login', 'username') |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
62 if not self.password: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
63 self.password = config.get('server-login', 'password') |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
64 if not self.repository: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
65 self.repository = self.DEFAULT_REPOSITORY |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
66 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
67 def run(self): |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 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
|
72 |
|
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
|
73 def upload_file(self, command, pyversion, filename): |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
74 # Sign if requested |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
75 if self.sign: |
|
37294
b85ad2166c01
Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents:
36248
diff
changeset
|
76 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
|
77 if self.identity: |
|
b85ad2166c01
Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents:
36248
diff
changeset
|
78 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
|
79 spawn(gpg_args, |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
80 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
|
81 |
|
36248
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
82 # 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
|
83 # 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
|
84 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
|
85 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
|
86 data = { |
|
36248
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
87 # action |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
88 ':action': 'file_upload', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
89 'protcol_version': '1', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
90 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
91 # identify release |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
92 'name': meta.get_name(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
93 'version': meta.get_version(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
94 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
95 # file content |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
96 '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
|
97 'filetype': command, |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
98 'pyversion': pyversion, |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
99 'md5_digest': md5(content).hexdigest(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
100 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
101 # additional meta-data |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
102 'metadata_version' : '1.0', |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
103 'summary': meta.get_description(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
104 'home_page': meta.get_url(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
105 'author': meta.get_contact(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
106 '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
|
107 'license': meta.get_licence(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
108 'description': meta.get_long_description(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
109 'keywords': meta.get_keywords(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
110 'platform': meta.get_platforms(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
111 'classifiers': meta.get_classifiers(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
112 '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
|
113 # PEP 314 |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
114 'provides': meta.get_provides(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
115 'requires': meta.get_requires(), |
|
811d644d1917
Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents:
35210
diff
changeset
|
116 '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
|
117 } |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
118 comment = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
119 if command == 'bdist_rpm': |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
120 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
|
121 if dist: |
|
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 %s' % (dist, version) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
123 elif command == 'bdist_dumb': |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
124 comment = 'built for %s' % platform.platform(terse=1) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
125 data['comment'] = comment |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
126 |
|
34799
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
127 if self.sign: |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
128 data['gpg_signature'] = (os.path.basename(filename) + ".asc", |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
129 open(filename+".asc").read()) |
|
7933531d02b4
Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents:
34794
diff
changeset
|
130 |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
131 # set up the authentication |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
132 auth = "Basic " + base64.encodestring(self.username + ":" + self.password).strip() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
133 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
134 # 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
|
135 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
136 sep_boundary = '\n--' + boundary |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
137 end_boundary = sep_boundary + '--' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
138 body = StringIO.StringIO() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
139 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
|
140 # 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
|
141 if type(value) != type([]): |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
142 value = [value] |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
143 for value in value: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
144 if type(value) is tuple: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
145 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
|
146 value = value[1] |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
147 else: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
148 fn = "" |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
149 value = str(value) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
150 body.write(sep_boundary) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
151 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
|
152 body.write(fn) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
153 body.write("\n\n") |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
154 body.write(value) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
155 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
|
156 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
|
157 body.write(end_boundary) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
158 body.write("\n") |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
159 body = body.getvalue() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
160 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
161 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
|
162 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
163 # build the Request |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
164 # We can't use urllib2 since we need to send the Basic |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
165 # auth right with the first request |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
166 schema, netloc, url, params, query, fragments = \ |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
167 urlparse.urlparse(self.repository) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
168 assert not params and not query and not fragments |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
169 if schema == 'http': |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
170 http = httplib.HTTPConnection(netloc) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
171 elif schema == 'https': |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
172 http = httplib.HTTPSConnection(netloc) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
173 else: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
174 raise AssertionError, "unsupported schema "+schema |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
175 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
176 data = '' |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
177 loglevel = log.INFO |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
178 try: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
179 http.connect() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
180 http.putrequest("POST", url) |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
181 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
|
182 '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
|
183 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
|
184 http.putheader('Authorization', auth) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
185 http.endheaders() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
186 http.send(body) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
187 except socket.error, e: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
188 self.announce(e.msg, log.ERROR) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
189 return |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
190 |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
191 r = http.getresponse() |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
192 if r.status == 200: |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
193 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
|
194 log.INFO) |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
195 else: |
|
34818
4eaab38566c9
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34810
diff
changeset
|
196 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
|
197 log.ERROR) |
|
34794
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
198 if self.show_response: |
|
f3f99acae59f
Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents:
34793
diff
changeset
|
199 print '-'*75, r.read(), '-'*75 |
