Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2018 Garmin Ltd. |
| 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 6 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 7 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 8 | import os |
| 9 | import sys |
| 10 | import logging |
| 11 | import argparse |
| 12 | import sqlite3 |
| 13 | |
| 14 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)),'lib')) |
| 15 | |
| 16 | import hashserv |
| 17 | |
| 18 | VERSION = "1.0.0" |
| 19 | |
| 20 | DEFAULT_HOST = '' |
| 21 | DEFAULT_PORT = 8686 |
| 22 | |
| 23 | def 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 Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 44 | server = hashserv.create_server((args.address, args.port), args.database, args.prefix) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 45 | server.serve_forever() |
| 46 | return 0 |
| 47 | |
| 48 | if __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 | |