3
3
Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
5
5
from distutils.errors import *
6
from distutils.core import Command
6
from distutils.core import PyPIRCCommand
7
7
from distutils.spawn import spawn
8
8
from distutils import log
9
9
from hashlib import md5
17
16
import cStringIO as StringIO
19
class upload(Command):
18
from configparser import ConfigParser
20
# For backward-compatibility with Python versions < 2.6.
21
from ConfigParser import ConfigParser
24
class upload(PyPIRCCommand):
21
26
description = "upload binary package to PyPI"
23
DEFAULT_REPOSITORY = 'http://pypi.python.org/pypi'
27
"url of repository [default: %s]" % DEFAULT_REPOSITORY),
28
('show-response', None,
29
'display full response text from server'),
28
user_options = PyPIRCCommand.user_options + [
31
30
'sign files to upload using gpg'),
32
31
('identity=', 'i', 'GPG identity used to sign files'),
34
boolean_options = ['show-response', 'sign']
34
boolean_options = PyPIRCCommand.boolean_options + ['sign']
36
36
def initialize_options(self):
37
PyPIRCCommand.initialize_options(self)
40
40
self.show_response = 0
42
42
self.identity = None
44
44
def finalize_options(self):
45
PyPIRCCommand.finalize_options(self)
45
46
if self.identity and not self.sign:
46
47
raise DistutilsOptionError(
47
48
"Must use --sign for --identity to have meaning"
49
if 'HOME' in os.environ:
50
rc = os.path.join(os.environ['HOME'], '.pypirc')
51
if os.path.exists(rc):
52
self.announce('Using PyPI login from %s' % rc)
53
config = ConfigParser.ConfigParser({
58
if not self.repository:
59
self.repository = config.get('server-login', 'repository')
61
self.username = config.get('server-login', 'username')
63
self.password = config.get('server-login', 'password')
64
if not self.repository:
65
self.repository = self.DEFAULT_REPOSITORY
50
config = self._read_pypirc()
52
self.username = config['username']
53
self.password = config['password']
54
self.repository = config['repository']
55
self.realm = config['realm']
68
58
if not self.distribution.dist_files: