Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 2 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 3 | # Copyright BitBake Contributors |
| 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
| 6 | # |
| 7 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | import os |
| 9 | import sys,logging |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 10 | import argparse |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 11 | import warnings |
| 12 | warnings.simplefilter("default") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 14 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), "lib")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | |
| 16 | import prserv |
| 17 | import prserv.serv |
| 18 | |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 19 | VERSION = "1.1.0" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 21 | PRHOST_DEFAULT="0.0.0.0" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 22 | PRPORT_DEFAULT=8585 |
| 23 | |
| 24 | def main(): |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 25 | parser = argparse.ArgumentParser( |
| 26 | description="BitBake PR Server. Version=%s" % VERSION, |
| 27 | formatter_class=argparse.RawTextHelpFormatter) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 29 | parser.add_argument( |
| 30 | "-f", |
| 31 | "--file", |
| 32 | default="prserv.sqlite3", |
| 33 | help="database filename (default: prserv.sqlite3)", |
| 34 | ) |
| 35 | parser.add_argument( |
| 36 | "-l", |
| 37 | "--log", |
| 38 | default="prserv.log", |
| 39 | help="log filename(default: prserv.log)", |
| 40 | ) |
| 41 | parser.add_argument( |
| 42 | "--loglevel", |
| 43 | default="INFO", |
| 44 | help="logging level, i.e. CRITICAL, ERROR, WARNING, INFO, DEBUG", |
| 45 | ) |
| 46 | parser.add_argument( |
| 47 | "--start", |
| 48 | action="store_true", |
| 49 | help="start daemon", |
| 50 | ) |
| 51 | parser.add_argument( |
| 52 | "--stop", |
| 53 | action="store_true", |
| 54 | help="stop daemon", |
| 55 | ) |
| 56 | parser.add_argument( |
| 57 | "--host", |
| 58 | help="ip address to bind", |
| 59 | default=PRHOST_DEFAULT, |
| 60 | ) |
| 61 | parser.add_argument( |
| 62 | "--port", |
| 63 | type=int, |
| 64 | default=PRPORT_DEFAULT, |
| 65 | help="port number (default: 8585)", |
| 66 | ) |
| 67 | parser.add_argument( |
| 68 | "-r", |
| 69 | "--read-only", |
| 70 | action="store_true", |
| 71 | help="open database in read-only mode", |
| 72 | ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 74 | args = parser.parse_args() |
| 75 | prserv.init_logger(os.path.abspath(args.log), args.loglevel) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 77 | if args.start: |
| 78 | ret=prserv.serv.start_daemon(args.file, args.host, args.port, os.path.abspath(args.log), args.read_only) |
| 79 | elif args.stop: |
| 80 | ret=prserv.serv.stop_daemon(args.host, args.port) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | else: |
| 82 | ret=parser.print_help() |
| 83 | return ret |
| 84 | |
| 85 | if __name__ == "__main__": |
| 86 | try: |
| 87 | ret = main() |
| 88 | except Exception: |
| 89 | ret = 1 |
| 90 | import traceback |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 91 | traceback.print_exc() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | sys.exit(ret) |
| 93 | |