mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00

svn+ssh://pythondev@svn.python.org/python/trunk ........ r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines #1858 from Tarek Ziade: Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI for discussion. The patch is slightly revised from Tarek's last patch: I've simplified the PyPIRCCommand.finalize_options() method to not look at sys.argv. Tests still pass. ........ r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines Cleaned up io._BytesIO.write(). I am amazed that the old code, for inserting null-bytes, actually worked. Who wrote that thing? Oh, it is me... doh. ........ r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines Revert r62998 as it broke the build (seems distutils.config is missing). ........ r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line #1858: add distutils.config module ........ r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines Flesh out the 3.0 deprecation to suggest using the ctypes module. ........ r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines Copied two versions of the example from the interactive session. Delete one. ........ r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines reload() takes the module itself. ........ r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines Added test framework for handling module renames. Factored the import guard in test_py3kwarn.TestStdlibRemovals into a context manager, namely test_support.CleanImport. ........ r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines #2742: ``''`` is not converted to NULL in getaddrinfo. ........ r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines Fixed typo in a comment of test_support.CleanImport. ........ r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines Removed a dead line of code. ........ r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines #2812: document property.getter/setter/deleter. ........ r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines #1153769: document PEP 237 changes to string formatting. ........ r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines #2809: elaborate str.split docstring a bit. ........ r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines Fix typo. ........ r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines #2709: clarification. ........ r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines #2659: add ``break_on_hyphens`` to TextWrapper. ........ r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines #2741: clarification of value range for address_family. ........ r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines #2452: timeout is used for all blocking operations. ........ r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines #1792: Improve performance of marshal.dumps() on large objects by increasing the size of the buffer more quickly. ........ r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line #1858: re-apply patch for this, adding the missing files ........ r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines Add the "until" command to pdb ........ r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines Add some sentence endings. ........
124 lines
4.2 KiB
Python
124 lines
4.2 KiB
Python
"""distutils.pypirc
|
|
|
|
Provides the PyPIRCCommand class, the base class for the command classes
|
|
that uses .pypirc in the distutils.command package.
|
|
"""
|
|
import os
|
|
import sys
|
|
from configparser import ConfigParser
|
|
|
|
from distutils.core import Command
|
|
|
|
DEFAULT_PYPIRC = """\
|
|
[pypirc]
|
|
servers =
|
|
pypi
|
|
|
|
[pypi]
|
|
username:%s
|
|
password:%s
|
|
"""
|
|
|
|
class PyPIRCCommand(Command):
|
|
"""Base command that knows how to handle the .pypirc file
|
|
"""
|
|
DEFAULT_REPOSITORY = 'http://pypi.python.org/pypi'
|
|
DEFAULT_REALM = 'pypi'
|
|
repository = None
|
|
realm = None
|
|
|
|
user_options = [
|
|
('repository=', 'r',
|
|
"url of repository [default: %s]" % \
|
|
DEFAULT_REPOSITORY),
|
|
('show-response', None,
|
|
'display full response text from server')]
|
|
|
|
boolean_options = ['show-response']
|
|
|
|
def _get_rc_file(self):
|
|
"""Returns rc file path."""
|
|
return os.path.join(os.path.expanduser('~'), '.pypirc')
|
|
|
|
def _store_pypirc(self, username, password):
|
|
"""Creates a default .pypirc file."""
|
|
rc = self._get_rc_file()
|
|
f = open(rc, 'w')
|
|
try:
|
|
f.write(DEFAULT_PYPIRC % (username, password))
|
|
finally:
|
|
f.close()
|
|
try:
|
|
os.chmod(rc, 0o600)
|
|
except OSError:
|
|
# should do something better here
|
|
pass
|
|
|
|
def _read_pypirc(self):
|
|
"""Reads the .pypirc file."""
|
|
rc = self._get_rc_file()
|
|
if os.path.exists(rc):
|
|
print('Using PyPI login from %s' % rc)
|
|
repository = self.repository or self.DEFAULT_REPOSITORY
|
|
realm = self.realm or self.DEFAULT_REALM
|
|
|
|
config = ConfigParser()
|
|
config.read(rc)
|
|
sections = config.sections()
|
|
if 'distutils' in sections:
|
|
# let's get the list of servers
|
|
index_servers = config.get('distutils', 'index-servers')
|
|
_servers = [server.strip() for server in
|
|
index_servers.split('\n')
|
|
if server.strip() != '']
|
|
if _servers == []:
|
|
# nothing set, let's try to get the default pypi
|
|
if 'pypi' in sections:
|
|
_servers = ['pypi']
|
|
else:
|
|
# the file is not properly defined, returning
|
|
# an empty dict
|
|
return {}
|
|
for server in _servers:
|
|
current = {'server': server}
|
|
current['username'] = config.get(server, 'username')
|
|
current['password'] = config.get(server, 'password')
|
|
|
|
# optional params
|
|
for key, default in (('repository',
|
|
self.DEFAULT_REPOSITORY),
|
|
('realm', self.DEFAULT_REALM)):
|
|
if config.has_option(server, key):
|
|
current[key] = config.get(server, key)
|
|
else:
|
|
current[key] = default
|
|
if (current['server'] == repository or
|
|
current['repository'] == repository):
|
|
return current
|
|
elif 'server-login' in sections:
|
|
# old format
|
|
server = 'server-login'
|
|
if config.has_option(server, 'repository'):
|
|
repository = config.get(server, 'repository')
|
|
else:
|
|
repository = self.DEFAULT_REPOSITORY
|
|
return {'username': config.get(server, 'username'),
|
|
'password': config.get(server, 'password'),
|
|
'repository': repository,
|
|
'server': server,
|
|
'realm': self.DEFAULT_REALM}
|
|
|
|
return {}
|
|
|
|
def initialize_options(self):
|
|
"""Initialize options."""
|
|
self.repository = None
|
|
self.realm = None
|
|
self.show_response = 0
|
|
|
|
def finalize_options(self):
|
|
"""Finalizes options."""
|
|
if self.repository is None:
|
|
self.repository = self.DEFAULT_REPOSITORY
|
|
if self.realm is None:
|
|
self.realm = self.DEFAULT_REALM
|