blob: 6c911c098a73804d5c9fa00b2710f625cf642b43 [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
Brad Bishop08902b02019-08-20 09:16:51 -040044 server = hashserv.create_server((args.address, args.port), args.database, args.prefix)
Brad Bishop19323692019-04-05 15:28:33 -040045 server.serve_forever()
46 return 0
47
48if __name__ == '__main__':
49 try:
50 ret = main()
51 except Exception:
52 ret = 1
53 import traceback
54 traceback.print_exc()
55 sys.exit(ret)
56