1#!/usr/bin/env python3 2# 3# Copyright BitBake Contributors 4# 5# SPDX-License-Identifier: GPL-2.0-only 6# 7 8import os 9import sys,logging 10import argparse 11import warnings 12warnings.simplefilter("default") 13 14sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), "lib")) 15 16import prserv 17import prserv.serv 18 19VERSION = "1.1.0" 20 21PRHOST_DEFAULT="0.0.0.0" 22PRPORT_DEFAULT=8585 23 24def main(): 25 parser = argparse.ArgumentParser( 26 description="BitBake PR Server. Version=%s" % VERSION, 27 formatter_class=argparse.RawTextHelpFormatter) 28 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 ) 73 74 args = parser.parse_args() 75 prserv.init_logger(os.path.abspath(args.log), args.loglevel) 76 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) 81 else: 82 ret=parser.print_help() 83 return ret 84 85if __name__ == "__main__": 86 try: 87 ret = main() 88 except Exception: 89 ret = 1 90 import traceback 91 traceback.print_exc() 92 sys.exit(ret) 93 94