From: W. Trevor King Date: Thu, 20 Feb 2014 19:00:16 +0000 (-0800) Subject: main: Add an argparse-based command line interface X-Git-Tag: v0.1~30 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c2913df53212fb6f3deb267eb861807aa94cf498;p=package-cache.git main: Add an argparse-based command line interface And a package-cache.py wrapper script to call it. --- diff --git a/package-cache.py b/package-cache.py new file mode 100755 index 0000000..4378609 --- /dev/null +++ b/package-cache.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +from package_cache.main import run + + +run() diff --git a/package_cache/main.py b/package_cache/main.py new file mode 100644 index 0000000..c6c814e --- /dev/null +++ b/package_cache/main.py @@ -0,0 +1,40 @@ +# Copyright + +import argparse as _argparse +import logging as _logging +import wsgiref.simple_server as _wsgiref_simple_server + +from . import __version__ +from . import server as _server + + +LOG = _logging.getLogger(__name__) + + +def run(*args, **kwargs): + """Run the package-cache server using Python's WSGI reference server + """ + parser = _argparse.ArgumentParser(description=__doc__) + parser.add_argument( + '--version', action='version', + version='%(prog)s {}'.format(__version__)) + parser.add_argument( + '--host', metavar='HOSTNAME', default='localhost', + help='Host to listen as') + parser.add_argument( + '--port', metavar='INT', default=4000, type=int, + help='Port to listen to') + parser.add_argument( + '--source', metavar='URL', action='append', + help='URL for an upstream mirror') + parser.add_argument( + '--cache', metavar='PATH', default='/tmp/package-cache', + help='Path to the package cache directory') + + args = parser.parse_args() + + server = _server.Server(sources=args.source or [], cache=args.cache) + wsgi = _wsgiref_simple_server.make_server( + host=args.host, port=args.port, app=server) + LOG.info('serving WSGI on {}:{}'.format(args.host, args.port)) + wsgi.serve_forever()