Commit 4f5c1303 authored by guyroz's avatar guyroz

Issue #244 raises ValueError in upload and register commands if using a...

Issue #244 raises ValueError in upload and register commands if using a section without a repository value

--HG--
branch : distribute
extra : rebase_source : e57437a8ac03832ed8170c902996423a27235856
parent 51e06f79
......@@ -8,6 +8,7 @@ saveopts = setuptools.command.saveopts:saveopts
egg_info = setuptools.command.egg_info:egg_info
register = setuptools.command.register:register
upload_docs = setuptools.command.upload_docs:upload_docs
upload = setuptools.command.upload:upload
install_egg_info = setuptools.command.install_egg_info:install_egg_info
alias = setuptools.command.alias:alias
easy_install = setuptools.command.easy_install:easy_install
......@@ -32,7 +33,7 @@ depends.txt = setuptools.command.egg_info:warn_depends_obsolete
[console_scripts]
easy_install = setuptools.command.easy_install:main
easy_install-2.6 = setuptools.command.easy_install:main
easy_install-2.3 = setuptools.command.easy_install:main
[setuptools.file_finders]
svn_cvs = setuptools.command.sdist:_default_revctrl
......
......@@ -8,13 +8,8 @@ __all__ = [
from setuptools.command import install_scripts
import sys
if sys.version>='2.5':
# In Python 2.5 and above, distutils includes its own upload command
__all__.remove('upload')
from distutils.command.bdist import bdist
if 'egg' not in bdist.format_commands:
bdist.format_command['egg'] = ('bdist_egg', "Python .egg file")
bdist.format_commands.append('egg')
......
from distutils.command.register import register as _register
from ConfigParser import ConfigParser
import os
class register(_register):
__doc__ = _register.__doc__
......@@ -6,5 +8,63 @@ class register(_register):
def run(self):
# Make sure that we are using valid current name/version info
self.run_command('egg_info')
self._section_name = self.repository
_register.run(self)
def _read_pypirc(self):
"""Reads the .pypirc file."""
rc = self._get_rc_file()
if os.path.exists(rc):
repository = self.repository
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')
# optional params
for key, default in (('repository',
None),
('realm', self.DEFAULT_REALM),
('password', None)):
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 = None
return {'username': config.get(server, 'username'),
'password': config.get(server, 'password'),
'repository': repository,
'server': server,
'realm': self.DEFAULT_REALM}
return {}
def _set_config(self):
_register._set_config(self)
if self.repository is None:
raise ValueError('%s is missing a repository value in .pypirc' % self._section_name)
......@@ -2,6 +2,7 @@
Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
from distutils.errors import *
from distutils.core import Command
from distutils.spawn import spawn
......@@ -11,6 +12,7 @@ try:
except ImportError:
from md5 import md5
import os
import sys
import socket
import platform
import ConfigParser
......@@ -19,7 +21,7 @@ import base64
import urlparse
import cStringIO as StringIO
class upload(Command):
class _upload(Command):
description = "upload binary package to PyPI"
......@@ -65,7 +67,7 @@ class upload(Command):
if not self.password:
self.password = config.get('server-login', 'password')
if not self.repository:
self.repository = self.DEFAULT_REPOSITORY
raise ValueError('%s is missing a repository value in .pypirc' % self._section_name)
def run(self):
if not self.distribution.dist_files:
......@@ -181,3 +183,75 @@ class upload(Command):
log.ERROR)
if self.show_response:
print '-'*75, r.read(), '-'*75
if sys.version >= "2.5":
from distutils.command.upload import upload as distutils_upload
class upload(distutils_upload):
def run(self):
self._section_name = self.repository
distutils_upload.run(self)
def _read_pypirc(self):
"""Reads the .pypirc file."""
self._section_name = self.repository
rc = self._get_rc_file()
if os.path.exists(rc):
repository = self.repository
config = ConfigParser.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')
# optional params
for key, default in (('repository',
None),
('realm', self.DEFAULT_REALM),
('password', None)):
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 = None
return {'username': config.get(server, 'username'),
'password': config.get(server, 'password'),
'repository': repository,
'server': server,
'realm': self.DEFAULT_REALM}
return {}
def finalize_options(self):
distutils_upload.finalize_options(self)
if not self.repository:
raise ValueError('%s is missing a repository value in .pypirc' % self._section_name)
else:
upload = _upload
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment