Run update-copyright.py
[package-cache.git] / package_cache / main.py
1 # Copyright (C) 2014 W. Trevor King <wking@tremily.us>
2 #
3 # This file is part of package-cache.
4 #
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
8 # later version.
9 #
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
13 # details.
14 #
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/>.
17
18 import argparse as _argparse
19 import logging as _logging
20 import wsgiref.simple_server as _wsgiref_simple_server
21
22 from . import __version__
23 from . import server as _server
24
25
26 LOG = _logging.getLogger(__name__)
27
28
29 def run(*args, **kwargs):
30     """Run the package-cache server using Python's WSGI reference server
31     """
32     parser = _argparse.ArgumentParser(description=__doc__)
33     parser.add_argument(
34         '--version', action='version',
35         version='%(prog)s {}'.format(__version__))
36     parser.add_argument(
37         '--host', metavar='HOSTNAME', default='localhost',
38         help='Host to listen as')
39     parser.add_argument(
40         '--port', metavar='INT', default=4000, type=int,
41         help='Port to listen to')
42     parser.add_argument(
43         '--source', metavar='URL', action='append',
44         help='URL for an upstream mirror')
45     parser.add_argument(
46         '--cache', metavar='PATH', default='/tmp/package-cache',
47         help='Path to the package cache directory')
48
49     args = parser.parse_args()
50
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))
55     wsgi.serve_forever()