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