]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/command/upload.py
1 """distutils.command.upload
3 Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
7 from urllib2
import urlopen
, Request
, HTTPError
8 from base64
import standard_b64encode
10 import cStringIO
as StringIO
11 from hashlib
import md5
13 from distutils
.errors
import DistutilsOptionError
14 from distutils
.core
import PyPIRCCommand
15 from distutils
.spawn
import spawn
16 from distutils
import log
18 class upload(PyPIRCCommand
):
20 description
= "upload binary package to PyPI"
22 user_options
= PyPIRCCommand
.user_options
+ [
24 'sign files to upload using gpg'),
25 ('identity=', 'i', 'GPG identity used to sign files'),
28 boolean_options
= PyPIRCCommand
.boolean_options
+ ['sign']
30 def initialize_options(self
):
31 PyPIRCCommand
.initialize_options(self
)
34 self
.show_response
= 0
38 def finalize_options(self
):
39 PyPIRCCommand
.finalize_options(self
)
40 if self
.identity
and not self
.sign
:
41 raise DistutilsOptionError(
42 "Must use --sign for --identity to have meaning"
44 config
= self
._read
_pypirc
()
46 self
.username
= config
['username']
47 self
.password
= config
['password']
48 self
.repository
= config
['repository']
49 self
.realm
= config
['realm']
51 # getting the password from the distribution
52 # if previously set by the register command
53 if not self
.password
and self
.distribution
.password
:
54 self
.password
= self
.distribution
.password
57 if not self
.distribution
.dist_files
:
58 raise DistutilsOptionError("No dist file created in earlier command")
59 for command
, pyversion
, filename
in self
.distribution
.dist_files
:
60 self
.upload_file(command
, pyversion
, filename
)
62 def upload_file(self
, command
, pyversion
, filename
):
63 # Makes sure the repository URL is compliant
64 schema
, netloc
, url
, params
, query
, fragments
= \
65 urlparse
.urlparse(self
.repository
)
66 if params
or query
or fragments
:
67 raise AssertionError("Incompatible url %s" % self
.repository
)
69 if schema
not in ('http', 'https'):
70 raise AssertionError("unsupported schema " + schema
)
74 gpg_args
= ["gpg", "--detach-sign", "-a", filename
]
76 gpg_args
[2:2] = ["--local-user", self
.identity
]
80 # Fill in the data - send all the meta-data in case we need to
81 # register a new release
82 f
= open(filename
,'rb')
87 meta
= self
.distribution
.metadata
90 ':action': 'file_upload',
91 'protcol_version': '1',
94 'name': meta
.get_name(),
95 'version': meta
.get_version(),
98 'content': (os
.path
.basename(filename
),content
),
100 'pyversion': pyversion
,
101 'md5_digest': md5(content
).hexdigest(),
103 # additional meta-data
104 'metadata_version' : '1.0',
105 'summary': meta
.get_description(),
106 'home_page': meta
.get_url(),
107 'author': meta
.get_contact(),
108 'author_email': meta
.get_contact_email(),
109 'license': meta
.get_licence(),
110 'description': meta
.get_long_description(),
111 'keywords': meta
.get_keywords(),
112 'platform': meta
.get_platforms(),
113 'classifiers': meta
.get_classifiers(),
114 'download_url': meta
.get_download_url(),
116 'provides': meta
.get_provides(),
117 'requires': meta
.get_requires(),
118 'obsoletes': meta
.get_obsoletes(),
121 if command
== 'bdist_rpm':
122 dist
, version
, id = platform
.dist()
124 comment
= 'built for %s %s' % (dist
, version
)
125 elif command
== 'bdist_dumb':
126 comment
= 'built for %s' % platform
.platform(terse
=1)
127 data
['comment'] = comment
130 data
['gpg_signature'] = (os
.path
.basename(filename
) + ".asc",
131 open(filename
+".asc").read())
133 # set up the authentication
134 auth
= "Basic " + standard_b64encode(self
.username
+ ":" +
137 # Build up the MIME payload for the POST data
138 boundary
= '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
139 sep_boundary
= '\n--' + boundary
140 end_boundary
= sep_boundary
+ '--'
141 body
= StringIO
.StringIO()
142 for key
, value
in data
.items():
143 # handle multiple entries for the same name
144 if not isinstance(value
, list):
147 if isinstance(value
, tuple):
148 fn
= ';filename="%s"' % value
[0]
153 body
.write(sep_boundary
)
154 body
.write('\nContent-Disposition: form-data; name="%s"'%key
)
158 if value
and value
[-1] == '\r':
159 body
.write('\n') # write an extra newline (lurve Macs)
160 body
.write(end_boundary
)
162 body
= body
.getvalue()
164 self
.announce("Submitting %s to %s" % (filename
, self
.repository
), log
.INFO
)
167 headers
= {'Content-type':
168 'multipart/form-data; boundary=%s' % boundary
,
169 'Content-length': str(len(body
)),
170 'Authorization': auth
}
172 request
= Request(self
.repository
, data
=body
,
176 result
= urlopen(request
)
177 status
= result
.getcode()
179 if self
.show_response
:
180 msg
= '\n'.join(('-' * 75, r
.read(), '-' * 75))
181 self
.announce(msg
, log
.INFO
)
182 except socket
.error
, e
:
183 self
.announce(str(e
), log
.ERROR
)
190 self
.announce('Server response (%s): %s' % (status
, reason
),
193 self
.announce('Upload failed (%s): %s' % (status
, reason
),