Merge pull request #16 from brocaar/master

Add --fallback-url argument
This commit is contained in:
Ralf Schmitt 2012-08-15 11:24:09 -07:00
commit e4935f095e
4 changed files with 44 additions and 7 deletions

View File

@ -82,6 +82,10 @@ pypi-server -h will print a detailed usage message::
disable redirect to real PyPI index for packages not found in the
local index
--fallback-url FALLBACK_URL
for packages not found in the local index, this URL will be used to
redirect to (default: http://pypi.python.org/simple)
--server METHOD
use METHOD to run the server. Valid values include paste,
cherrypy, twisted, gunicorn, gevent, wsgiref, auto. The

View File

@ -1,5 +1,5 @@
__version_info__ = (0, 6, 1)
version = __version__ = "0.6.1"
__version_info__ = (0, 6, 2, 'dev')
version = __version__ = "0.6.2dev"
def app(root=None,

View File

@ -69,7 +69,7 @@ class pkgset(object):
assert "/" not in filename
dest_fn = os.path.join(self.root, filename)
dest_fh = open(dest_fn, "wb")
dest_fh.write(data)
dest_fh.close()
@ -98,6 +98,10 @@ pypi-server understands the following options:
disable redirect to real PyPI index for packages not found in the
local index
--fallback-url FALLBACK_URL
for packages not found in the local index, this URL will be used to
redirect to (default: http://pypi.python.org/simple)
--server METHOD
use METHOD to run the server. Valid values include paste,
cherrypy, twisted, gunicorn, gevent, wsgiref, auto. The
@ -147,6 +151,7 @@ def main(argv=None):
port = 8080
server = None
redirect_to_fallback = True
fallback_url = "http://pypi.python.org/simple"
password_file = None
update_dry_run = True
@ -154,7 +159,17 @@ def main(argv=None):
update_stable_only = True
try:
opts, roots = getopt.getopt(argv[1:], "i:p:r:d:P:Uuxh", ["interface=", "passwords=", "port=", "root=", "server=", "disable-fallback", "version", "help"])
opts, roots = getopt.getopt(argv[1:], "i:p:r:d:P:Uuxh", [
"interface=",
"passwords=",
"port=",
"root=",
"server=",
"fallback-url=",
"disable-fallback",
"version",
"help"
])
except getopt.GetoptError:
err = sys.exc_info()[1]
sys.exit("usage error: %s" % (err,))
@ -168,9 +183,12 @@ def main(argv=None):
roots.append(v)
elif k == "--disable-fallback":
redirect_to_fallback = False
elif k == "--fallback-url":
fallback_url = v
elif k == "--server":
if v not in server_names:
sys.exit("unknown server %r. choose one of %s" % (v, ", ".join(server_names.keys())))
sys.exit("unknown server %r. choose one of %s" % (
v, ", ".join(server_names.keys())))
server = v
elif k == "--version":
sys.stdout.write("pypiserver %s\n" % __version__)
@ -189,7 +207,6 @@ def main(argv=None):
usage()
sys.exit(0)
if len(roots) == 0:
roots.append(os.path.expanduser("~/packages"))
elif len(roots) > 1:
@ -210,7 +227,12 @@ def main(argv=None):
manage.update(packages, update_directory, update_dry_run, stable_only=update_stable_only)
return
a = app(root=root, redirect_to_fallback=redirect_to_fallback, password_file=password_file)
a = app(
root=root,
redirect_to_fallback=redirect_to_fallback,
password_file=password_file,
fallback_url=fallback_url
)
server = server or "auto"
sys.stdout.write("This is pypiserver %s serving %r on %s:%s\n\n" % (__version__, root, host, port))
run(app=a, host=host, port=port, server=server)

View File

@ -74,3 +74,14 @@ def test_root_r(main):
def test_root_multiple(main):
pytest.raises(SystemExit, main, [".", "."])
pytest.raises(SystemExit, main, ["-r", ".", "."])
def test_fallback_url(main):
main(["--fallback-url", "http://pypi.mirror/simple"])
assert main.app.module.config.fallback_url == "http://pypi.mirror/simple"
def test_fallback_url_default(main):
main([])
assert main.app.module.config.fallback_url == \
"http://pypi.python.org/simple"