def run(self, context): o, a = context.get_parsed_arguments() if len(a) < 1: context.options_context.parser.print_usage() # FIXME raise NotImplementedError("expected file argument") else: filename = a[0] if o.repository and (o.username or o.password or o.repository_url): raise bento.errors.UsageException( "Cannot specify repository and username/password/url at the same time" ) if not (o.repository or (o.username or o.password or o.repository_url)): # FIXME: why does distutils use DEFAULT_REPOSITORY (i.e. an url) # here ? config = _read_pypirc(DEFAULT_REPOSITORY) elif o.repository: config = _read_pypirc(o.repository) else: config = PyPIConfig(o.username, o.password, o.repository_url) if o.distribution_type is None: # FIXME raise NotImplementedError( "automatic distribution type not yet implemented") if not o.distribution_type in _SUPPORTED_DISTRIBUTIONS: # FIXME raise NotImplementedError() upload_type = _SUPPORTED_DISTRIBUTIONS[o.distribution_type] upload(filename, upload_type, context.pkg, config=config)
def run(self, context): o, a = context.get_parsed_arguments() if o.repository and (o.username or o.password or o.repository_url): raise bento.errors.UsageException( "Cannot specify repository and username/password/url at the same time" ) if not (o.repository or (o.username or o.password or o.repository_url)): # FIXME: why does distutils use DEFAULT_REPOSITORY (i.e. an url) # here ? config = _read_pypirc(DEFAULT_REPOSITORY) elif o.repository: config = _read_pypirc(o.repository) else: config = PyPIConfig(o.username, o.password, o.repository_url) auth = HTTPPasswordMgr() host = urlparse(config.repository)[1] auth.add_password(config.realm, host, config.username, config.password) post_data = build_post_data(context.pkg, "submit") code, msg = post_to_server(post_data, config, auth) if code != 200: raise bento.errors.BentoError( "Error while submitting package metadata to server: %r" % msg)
def test_pypi_config(self): data = """\ [distutils] index-servers = test [test] username:cdavid password:yoyo repository:http://testpypi.python.org """ config = PyPIConfig.from_file(StringIO(data), repository="test") self.assertEqual(config.username, "cdavid") self.assertEqual(config.password, "yoyo")
def _test_register_server_errors(self): package = PackageDescription(name="foo") config = PyPIConfig.from_string(""" [distutils] index-servers = pypi [pypi] username = cdavid password = yoyo server = http://testpypi.python.org """) post_data = build_post_data(package, "submit") return post_to_server(post_data, config)
def test_register_server(self): package = PackageDescription(name="foo") repository = 'http://testpypi.python.org/pypi' realm = DEFAULT_REALM config = PyPIConfig(username="******", password="******", repository=repository, realm=realm) auth = HTTPPasswordMgr() host = urlparse(config.repository)[0] auth.add_password(config.realm, host, config.username, config.password) post_data = build_post_data(package, "submit") code, msg = post_to_server(post_data, config, auth) self.assertEqual(code, 200) self.assertEqual(msg, "OK")
def _test_register_server_errors(self): package = PackageDescription(name="foo") config = PyPIConfig.from_string( """ [distutils] index-servers = pypi [pypi] username = cdavid password = yoyo server = http://testpypi.python.org """ ) post_data = build_post_data(package, "submit") return post_to_server(post_data, config)
def test_upload_auth(self): config = PyPIConfig("john", "password", repository="http://localhost") self.assertRaises(NotImplementedError, upload, "foo.bin", "bdist_dumb", self.package, config, True)
def test_upload_error_no_host(self): config = PyPIConfig("john", "password", repository="http://llocalhost") self.assertRaises(URLError, upload, "foo.bin", "bdist_dumb", self.package, config)
def test_upload(self): config = PyPIConfig("john", "password", repository="http://localhost") upload("foo.bin", "bdist_dumb", self.package, config)