~pythonregexp2.7/python/issue2636

« back to all changes in this revision

Viewing changes to Lib/distutils/command/upload.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-05-24 16:05:21 UTC
  • mfrom: (39021.1.401 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080524160521-1xenj7p6u3wb89et
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
4
4
 
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
10
10
import os
11
11
import socket
12
12
import platform
13
 
import ConfigParser
14
13
import httplib
15
14
import base64
16
15
import urlparse
17
16
import cStringIO as StringIO
18
 
 
19
 
class upload(Command):
 
17
try:
 
18
    from configparser import ConfigParser
 
19
except ImportError:
 
20
    # For backward-compatibility with Python versions < 2.6.
 
21
    from ConfigParser import ConfigParser
 
22
 
 
23
 
 
24
class upload(PyPIRCCommand):
20
25
 
21
26
    description = "upload binary package to PyPI"
22
27
 
23
 
    DEFAULT_REPOSITORY = 'http://pypi.python.org/pypi'
24
 
 
25
 
    user_options = [
26
 
        ('repository=', 'r',
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 + [
30
29
        ('sign', 's',
31
30
         'sign files to upload using gpg'),
32
31
        ('identity=', 'i', 'GPG identity used to sign files'),
33
32
        ]
34
 
    boolean_options = ['show-response', 'sign']
 
33
 
 
34
    boolean_options = PyPIRCCommand.boolean_options + ['sign']
35
35
 
36
36
    def initialize_options(self):
 
37
        PyPIRCCommand.initialize_options(self)
37
38
        self.username = ''
38
39
        self.password = ''
39
 
        self.repository = ''
40
40
        self.show_response = 0
41
41
        self.sign = False
42
42
        self.identity = None
43
43
 
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"
48
49
            )
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({
54
 
                        'username':'',
55
 
                        'password':'',
56
 
                        'repository':''})
57
 
                config.read(rc)
58
 
                if not self.repository:
59
 
                    self.repository = config.get('server-login', 'repository')
60
 
                if not self.username:
61
 
                    self.username = config.get('server-login', 'username')
62
 
                if not self.password:
63
 
                    self.password = config.get('server-login', 'password')
64
 
        if not self.repository:
65
 
            self.repository = self.DEFAULT_REPOSITORY
 
50
        config = self._read_pypirc()
 
51
        if config != {}:
 
52
            self.username = config['username']
 
53
            self.password = config['password']
 
54
            self.repository = config['repository']
 
55
            self.realm = config['realm']
66
56
 
67
57
    def run(self):
68
58
        if not self.distribution.dist_files: