annotate Lib/distutils/command/upload.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 3947fdca2f40
children b36cb4602e21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34793
3da21fdc2ee7 Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1 """distutils.command.upload
3da21fdc2ee7 Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
2
3da21fdc2ee7 Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
3 Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
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 *
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
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
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 httplib
57844
1772195405e7 Merged revisions 76952 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
14 from base64 import standard_b64encode
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
15 import urlparse
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
16 import cStringIO as StringIO
47252
e534ee0a4cd0 ConfigParser renaming reversal part 3: move module into place and adapt imports.
Georg Brandl <georg@python.org>
parents: 47078
diff changeset
17 from ConfigParser import ConfigParser
47078
57f61dad7b3b Fixed import of configparser in the distutils module.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 47013
diff changeset
18
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
19
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
20 class upload(PyPIRCCommand):
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
21
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
22 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
23
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
24 user_options = PyPIRCCommand.user_options + [
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
25 ('sign', 's',
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
26 '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
27 ('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
28 ]
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
29
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
30 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
31
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
32 def initialize_options(self):
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
33 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
34 self.username = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
35 self.password = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
36 self.show_response = 0
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
37 self.sign = False
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
38 self.identity = None
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
39
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
40 def finalize_options(self):
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
41 PyPIRCCommand.finalize_options(self)
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
42 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
43 raise DistutilsOptionError(
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
44 "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
45 )
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
46 config = self._read_pypirc()
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
47 if config != {}:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
48 self.username = config['username']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
49 self.password = config['password']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
50 self.repository = config['repository']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
51 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
52
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
53 def run(self):
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
54 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
55 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
56 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
57 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
58
34805
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34803
diff changeset
59 def upload_file(self, command, pyversion, filename):
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
60 # Sign if requested
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
61 if self.sign:
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
62 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
63 if self.identity:
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
64 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
65 spawn(gpg_args,
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
66 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
67
36248
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
68 # 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
69 # 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
70 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
71 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
72 data = {
36248
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
73 # action
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
74 ':action': 'file_upload',
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
75 'protcol_version': '1',
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
76
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
77 # identify release
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
78 'name': meta.get_name(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
79 'version': meta.get_version(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
80
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
81 # file content
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
82 '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
83 'filetype': command,
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
84 'pyversion': pyversion,
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
85 'md5_digest': md5(content).hexdigest(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
86
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
87 # additional meta-data
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
88 'metadata_version' : '1.0',
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
89 'summary': meta.get_description(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
90 'home_page': meta.get_url(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
91 'author': meta.get_contact(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
92 '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
93 'license': meta.get_licence(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
94 'description': meta.get_long_description(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
95 'keywords': meta.get_keywords(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
96 'platform': meta.get_platforms(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
97 'classifiers': meta.get_classifiers(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
98 '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
99 # PEP 314
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
100 'provides': meta.get_provides(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
101 'requires': meta.get_requires(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
102 '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
103 }
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
104 comment = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
105 if command == 'bdist_rpm':
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
106 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
107 if dist:
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 %s' % (dist, version)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
109 elif command == 'bdist_dumb':
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
110 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
111 data['comment'] = comment
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
112
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
113 if self.sign:
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
114 data['gpg_signature'] = (os.path.basename(filename) + ".asc",
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
115 open(filename+".asc").read())
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
116
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
117 # set up the authentication
57844
1772195405e7 Merged revisions 76952 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
118 auth = "Basic " + standard_b64encode(self.username + ":" +
1772195405e7 Merged revisions 76952 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
119 self.password)
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'
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
123 sep_boundary = '\n--' + boundary
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
124 end_boundary = sep_boundary + '--'
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
125 body = StringIO.StringIO()
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():
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
127 # 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
128 if type(value) != type([]):
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
129 value = [value]
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
130 for value in value:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
131 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
132 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
133 value = value[1]
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
134 else:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
135 fn = ""
58464
3947fdca2f40 Merged revisions 77717 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57844
diff changeset
136
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)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
138 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
139 body.write(fn)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
140 body.write("\n\n")
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
141 body.write(value)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
142 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
143 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
144 body.write(end_boundary)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
145 body.write("\n")
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
146 body = body.getvalue()
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
147
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
148 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
149
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
150 # build the Request
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
151 # 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
152 # 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
153 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
154 urlparse.urlparse(self.repository)
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':
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
157 http = httplib.HTTPConnection(netloc)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
158 elif schema == 'https':
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
159 http = httplib.HTTPSConnection(netloc)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
160 else:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
161 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
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)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
174 except socket.error, e:
39054
f2ac31fc369e Fix SF#1457312: bad socket error handling in distutils "upload" command.
Phillip J. Eby <pje@telecommunity.com>
parents: 38052
diff changeset
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:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
186 print '-'*75, r.read(), '-'*75