1
0
mirror of https://github.com/pypiserver/pypiserver synced 2024-11-09 16:45:51 +01:00

implement multi-root support

one can now specify multiple package roots. watch out for filename
conflicts!
This commit is contained in:
Ralf Schmitt 2013-01-22 23:00:48 +01:00
parent f1d4208081
commit 2232295412
4 changed files with 24 additions and 19 deletions

@ -20,7 +20,6 @@ def app(root=None,
if fallback_url is None: if fallback_url is None:
fallback_url = "http://pypi.python.org/simple" fallback_url = "http://pypi.python.org/simple"
os.listdir(root)
_app.configure(root=root, redirect_to_fallback=redirect_to_fallback, fallback_url=fallback_url, _app.configure(root=root, redirect_to_fallback=redirect_to_fallback, fallback_url=fallback_url,
password_file=password_file) password_file=password_file)
_app.app.module = _app _app.app.module = _app

@ -1,4 +1,4 @@
import sys, os import sys, os, itertools
if sys.version_info >= (3, 0): if sys.version_info >= (3, 0):
from urllib.parse import urljoin from urllib.parse import urljoin
@ -39,8 +39,21 @@ def configure(root=None,
if fallback_url is None: if fallback_url is None:
fallback_url = "http://pypi.python.org/simple" fallback_url = "http://pypi.python.org/simple"
packages = lambda: listdir(root) if not isinstance(root, (list, tuple)):
packages.root = root roots = [root]
else:
roots = root
roots = [os.path.abspath(r) for r in roots]
for r in roots:
try:
os.listdir(r)
except Exception:
err = sys.exc_info()[1]
sys.exit("Error: while trying to list %r: %s" % (r, err))
packages = lambda: itertools.chain(*[listdir(r) for r in roots])
packages.root = roots[0]
config.redirect_to_fallback = redirect_to_fallback config.redirect_to_fallback = redirect_to_fallback
config.fallback_url = fallback_url config.fallback_url = fallback_url

@ -1,7 +1,7 @@
#! /usr/bin/env python #! /usr/bin/env python
"""minimal PyPI like server for use with pip/easy_install""" """minimal PyPI like server for use with pip/easy_install"""
import os, sys, getopt, re, mimetypes, warnings import os, sys, getopt, re, mimetypes, warnings, itertools
warnings.filterwarnings("ignore", "Python 2.5 support may be dropped in future versions of Bottle") warnings.filterwarnings("ignore", "Python 2.5 support may be dropped in future versions of Bottle")
from pypiserver import bottle, __version__, app from pypiserver import bottle, __version__, app
@ -238,31 +238,24 @@ def main(argv=None):
if len(roots) == 0: if len(roots) == 0:
roots.append(os.path.expanduser("~/packages")) roots.append(os.path.expanduser("~/packages"))
elif len(roots) > 1:
sys.exit("Error: more than one root directory specified: %r" % (roots,))
root = os.path.abspath(roots[0]) roots = [os.path.abspath(x) for x in roots]
try:
os.listdir(root)
except Exception:
err = sys.exc_info()[1]
sys.exit("Error: while trying to list %r: %s" % (root, err))
if command == "update": if command == "update":
packages = frozenset(listdir(root)) packages = frozenset(itertools.chain(*[listdir(r) for r in roots]))
from pypiserver import manage from pypiserver import manage
manage.update(packages, update_directory, update_dry_run, stable_only=update_stable_only) manage.update(packages, update_directory, update_dry_run, stable_only=update_stable_only)
return return
a = app( a = app(
root=root, root=roots,
redirect_to_fallback=redirect_to_fallback, redirect_to_fallback=redirect_to_fallback,
password_file=password_file, password_file=password_file,
fallback_url=fallback_url fallback_url=fallback_url
) )
server = server or "auto" server = server or "auto"
sys.stdout.write("This is pypiserver %s serving %r on http://%s:%s\n\n" % (__version__, root, host, port)) sys.stdout.write("This is pypiserver %s serving %r on http://%s:%s\n\n" % (__version__, ", ".join(roots), host, port))
sys.stdout.flush() sys.stdout.flush()
run(app=a, host=host, port=port, server=server) run(app=a, host=host, port=port, server=server)

@ -70,9 +70,9 @@ def test_root_r(main):
assert main.pkgdir == os.path.abspath(".") assert main.pkgdir == os.path.abspath(".")
def test_root_multiple(main): # def test_root_multiple(main):
pytest.raises(SystemExit, main, [".", "."]) # pytest.raises(SystemExit, main, [".", "."])
pytest.raises(SystemExit, main, ["-r", ".", "."]) # pytest.raises(SystemExit, main, ["-r", ".", "."])
def test_fallback_url(main): def test_fallback_url(main):