annotate Lib/distutils/command/upload.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents cb0969071f2a
children 1b3a19037f76
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
51890
8b68968879c7 Issue #5052: make Distutils compatible with 2.3 again.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
9 import sys
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
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
14 import base64
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
51890
8b68968879c7 Issue #5052: make Distutils compatible with 2.3 again.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
19 # this keeps compatibility for 2.3 and 2.4
8b68968879c7 Issue #5052: make Distutils compatible with 2.3 again.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
20 if sys.version < "2.5":
8b68968879c7 Issue #5052: make Distutils compatible with 2.3 again.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
21 from md5 import md5
8b68968879c7 Issue #5052: make Distutils compatible with 2.3 again.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
22 else:
8b68968879c7 Issue #5052: make Distutils compatible with 2.3 again.
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
23 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
24
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
25 class upload(PyPIRCCommand):
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
26
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
27 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
28
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
29 user_options = PyPIRCCommand.user_options + [
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 ]
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
34
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
35 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
36
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
37 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
38 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
39 self.username = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
40 self.password = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
41 self.show_response = 0
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
42 self.sign = False
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
43 self.identity = None
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
44
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
45 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
46 PyPIRCCommand.finalize_options(self)
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
47 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
48 raise DistutilsOptionError(
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
49 "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
50 )
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
51 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
52 if config != {}:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
53 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
54 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
55 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
56 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
57
50637
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
58 # getting the password from the distribution
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
59 # if previously set by the register command
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
60 if not self.password and self.distribution.password:
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
61 self.password = self.distribution.password
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 47252
diff changeset
62
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
63 def run(self):
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
64 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
65 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
66 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
67 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
68
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
69 def upload_file(self, command, pyversion, filename):
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
70 # Sign if requested
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
71 if self.sign:
37294
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
72 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
73 if self.identity:
b85ad2166c01 Implementation for patch request #1457316: support --identity option
Phillip J. Eby <pje@telecommunity.com>
parents: 36248
diff changeset
74 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
75 spawn(gpg_args,
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
76 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
77
36248
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
78 # 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
79 # 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
80 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
81 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
82 data = {
36248
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
83 # action
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
84 ':action': 'file_upload',
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
85 'protcol_version': '1',
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 # identify release
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
88 'name': meta.get_name(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
89 'version': meta.get_version(),
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 # file content
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
92 '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
93 'filetype': command,
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
94 'pyversion': pyversion,
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
95 'md5_digest': md5(content).hexdigest(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
96
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
97 # additional meta-data
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
98 'metadata_version' : '1.0',
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
99 'summary': meta.get_description(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
100 'home_page': meta.get_url(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
101 'author': meta.get_contact(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
102 '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
103 'license': meta.get_licence(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
104 'description': meta.get_long_description(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
105 'keywords': meta.get_keywords(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
106 'platform': meta.get_platforms(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
107 'classifiers': meta.get_classifiers(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
108 '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
109 # PEP 314
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
110 'provides': meta.get_provides(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
111 'requires': meta.get_requires(),
811d644d1917 Patch #1299675: Pass metadata in upload.
Martin v. Löwis <martin@v.loewis.de>
parents: 35210
diff changeset
112 '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
113 }
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
114 comment = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
115 if command == 'bdist_rpm':
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
116 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
117 if dist:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
118 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
119 elif command == 'bdist_dumb':
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
120 comment = 'built for %s' % platform.platform(terse=1)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
121 data['comment'] = comment
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
122
34799
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
123 if self.sign:
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
124 data['gpg_signature'] = (os.path.basename(filename) + ".asc",
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
125 open(filename+".asc").read())
7933531d02b4 Upload GPG signature.
Martin v. Löwis <martin@v.loewis.de>
parents: 34794
diff changeset
126
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
127 # set up the authentication
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
128 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
129
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
130 # 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
131 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
132 sep_boundary = '\n--' + boundary
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
133 end_boundary = sep_boundary + '--'
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
134 body = StringIO.StringIO()
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
135 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
136 # 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
137 if type(value) != type([]):
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
138 value = [value]
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
139 for value in value:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
140 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
141 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
142 value = value[1]
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
143 else:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
144 fn = ""
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
145 value = str(value)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
146 body.write(sep_boundary)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
147 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
148 body.write(fn)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
149 body.write("\n\n")
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
150 body.write(value)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
151 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
152 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
153 body.write(end_boundary)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
154 body.write("\n")
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
155 body = body.getvalue()
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
156
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
157 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
158
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
159 # build the Request
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
160 # 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
161 # 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
162 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
163 urlparse.urlparse(self.repository)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
164 assert not params and not query and not fragments
34818
4eaab38566c9 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34810
diff changeset
165 if schema == 'http':
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
166 http = httplib.HTTPConnection(netloc)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
167 elif schema == 'https':
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
168 http = httplib.HTTPSConnection(netloc)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
169 else:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
170 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
171
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
172 data = ''
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
173 loglevel = log.INFO
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
174 try:
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
175 http.connect()
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
176 http.putrequest("POST", url)
34818
4eaab38566c9 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34810
diff changeset
177 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
178 '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
179 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
180 http.putheader('Authorization', auth)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
181 http.endheaders()
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
182 http.send(body)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
183 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
184 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
185 return
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
186
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
187 r = http.getresponse()
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
188 if r.status == 200:
34818
4eaab38566c9 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34810
diff changeset
189 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
190 log.INFO)
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
191 else:
34818
4eaab38566c9 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34810
diff changeset
192 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
193 log.ERROR)
34794
f3f99acae59f Actually add the implementation of the command.
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
194 if self.show_response:
52585
cb0969071f2a more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51890
diff changeset
195 self.announce('-'*75, r.read(), '-'*75)