1 # Copyright (C) 2014 W. Trevor King <wking@tremily.us>
3 # This file is part of package-cache.
5 # package-cache is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
10 # package-cache is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 # You should have received a copy of the GNU General Public License along with
16 # package-cache. If not, see <http://www.gnu.org/licenses/>.
18 import argparse as _argparse
19 import logging as _logging
20 import wsgiref.simple_server as _wsgiref_simple_server
22 from . import __version__
23 from . import server as _server
26 LOG = _logging.getLogger(__name__)
29 def run(*args, **kwargs):
30 """Run the package-cache server using Python's WSGI reference server
32 parser = _argparse.ArgumentParser(description=__doc__)
34 '--version', action='version',
35 version='%(prog)s {}'.format(__version__))
37 '--host', metavar='HOSTNAME', default='localhost',
38 help='Host to listen as')
40 '--port', metavar='INT', default=4000, type=int,
41 help='Port to listen to')
43 '--source', metavar='URL', action='append',
44 help='URL for an upstream mirror')
46 '--cache', metavar='PATH', default='/tmp/package-cache',
47 help='Path to the package cache directory')
49 args = parser.parse_args()
51 server = _server.Server(sources=args.source or [], cache=args.cache)
52 wsgi = _wsgiref_simple_server.make_server(
53 host=args.host, port=args.port, app=server)
54 LOG.info('serving WSGI on {}:{}'.format(args.host, args.port))