blob: 848a0ca39f9d203da87b0bcc5cf1b5b5ddfcb9bc [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001#! /usr/bin/env python3
2#
3# Copyright (C) 2018 Garmin Ltd.
4#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
Brad Bishop19323692019-04-05 15:28:33 -04006#
Brad Bishopc342db32019-05-15 21:57:59 -04007
Brad Bishop19323692019-04-05 15:28:33 -04008import os
9import sys
10import logging
11import argparse
12import sqlite3
13
14sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)),'lib'))
15
16import hashserv
17
18VERSION = "1.0.0"
19
20DEFAULT_HOST = ''
21DEFAULT_PORT = 8686
22
23def main():
24 parser = argparse.ArgumentParser(description='HTTP Equivalence Reference Server. Version=%s' % VERSION)
25 parser.add_argument('--address', default=DEFAULT_HOST, help='Bind address (default "%(default)s")')
26 parser.add_argument('--port', type=int, default=DEFAULT_PORT, help='Bind port (default %(default)d)')
27 parser.add_argument('--prefix', default='', help='HTTP path prefix (default "%(default)s")')
28 parser.add_argument('--database', default='./hashserv.db', help='Database file (default "%(default)s")')
29 parser.add_argument('--log', default='WARNING', help='Set logging level')
30
31 args = parser.parse_args()
32
33 logger = logging.getLogger('hashserv')
34
35 level = getattr(logging, args.log.upper(), None)
36 if not isinstance(level, int):
37 raise ValueError('Invalid log level: %s' % args.log)
38
39 logger.setLevel(level)
40 console = logging.StreamHandler()
41 console.setLevel(level)
42 logger.addHandler(console)
43
44 db = sqlite3.connect(args.database)
45
46 server = hashserv.create_server((args.address, args.port), db, args.prefix)
47 server.serve_forever()
48 return 0
49
50if __name__ == '__main__':
51 try:
52 ret = main()
53 except Exception:
54 ret = 1
55 import traceback
56 traceback.print_exc()
57 sys.exit(ret)
58