blob: 323df66dd06fae7a373920dd5548bdfe454df9d3 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Brad Bishopc342db32019-05-15 21:57:59 -04002#
3# SPDX-License-Identifier: GPL-2.0-only
4#
5
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006import os
7import sys,logging
8import optparse
Andrew Geissler5199d832021-09-24 16:47:35 -05009import warnings
10warnings.simplefilter("default")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
12sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)),'lib'))
13
14import prserv
15import prserv.serv
16
17__version__="1.0.0"
18
19PRHOST_DEFAULT='0.0.0.0'
20PRPORT_DEFAULT=8585
21
22def main():
23 parser = optparse.OptionParser(
24 version="Bitbake PR Service Core version %s, %%prog version %s" % (prserv.__version__, __version__),
25 usage = "%prog < --start | --stop > [options]")
26
27 parser.add_option("-f", "--file", help="database filename(default: prserv.sqlite3)", action="store",
28 dest="dbfile", type="string", default="prserv.sqlite3")
29 parser.add_option("-l", "--log", help="log filename(default: prserv.log)", action="store",
30 dest="logfile", type="string", default="prserv.log")
31 parser.add_option("--loglevel", help="logging level, i.e. CRITICAL, ERROR, WARNING, INFO, DEBUG",
32 action = "store", type="string", dest="loglevel", default = "INFO")
33 parser.add_option("--start", help="start daemon",
34 action="store_true", dest="start")
35 parser.add_option("--stop", help="stop daemon",
36 action="store_true", dest="stop")
37 parser.add_option("--host", help="ip address to bind", action="store",
38 dest="host", type="string", default=PRHOST_DEFAULT)
39 parser.add_option("--port", help="port number(default: 8585)", action="store",
40 dest="port", type="int", default=PRPORT_DEFAULT)
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050041 parser.add_option("-r", "--read-only", help="open database in read-only mode",
42 action="store_true")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043
44 options, args = parser.parse_args(sys.argv)
45 prserv.init_logger(os.path.abspath(options.logfile),options.loglevel)
46
47 if options.start:
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050048 ret=prserv.serv.start_daemon(options.dbfile, options.host, options.port,os.path.abspath(options.logfile), options.read_only)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049 elif options.stop:
50 ret=prserv.serv.stop_daemon(options.host, options.port)
51 else:
52 ret=parser.print_help()
53 return ret
54
55if __name__ == "__main__":
56 try:
57 ret = main()
58 except Exception:
59 ret = 1
60 import traceback
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050061 traceback.print_exc()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062 sys.exit(ret)
63