blob: 1e9b6cbc1b2809943a1b4c4143561e264f9bd17e [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
9
10sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)),'lib'))
11
12import prserv
13import prserv.serv
14
15__version__="1.0.0"
16
17PRHOST_DEFAULT='0.0.0.0'
18PRPORT_DEFAULT=8585
19
20def main():
21 parser = optparse.OptionParser(
22 version="Bitbake PR Service Core version %s, %%prog version %s" % (prserv.__version__, __version__),
23 usage = "%prog < --start | --stop > [options]")
24
25 parser.add_option("-f", "--file", help="database filename(default: prserv.sqlite3)", action="store",
26 dest="dbfile", type="string", default="prserv.sqlite3")
27 parser.add_option("-l", "--log", help="log filename(default: prserv.log)", action="store",
28 dest="logfile", type="string", default="prserv.log")
29 parser.add_option("--loglevel", help="logging level, i.e. CRITICAL, ERROR, WARNING, INFO, DEBUG",
30 action = "store", type="string", dest="loglevel", default = "INFO")
31 parser.add_option("--start", help="start daemon",
32 action="store_true", dest="start")
33 parser.add_option("--stop", help="stop daemon",
34 action="store_true", dest="stop")
35 parser.add_option("--host", help="ip address to bind", action="store",
36 dest="host", type="string", default=PRHOST_DEFAULT)
37 parser.add_option("--port", help="port number(default: 8585)", action="store",
38 dest="port", type="int", default=PRPORT_DEFAULT)
39
40 options, args = parser.parse_args(sys.argv)
41 prserv.init_logger(os.path.abspath(options.logfile),options.loglevel)
42
43 if options.start:
44 ret=prserv.serv.start_daemon(options.dbfile, options.host, options.port,os.path.abspath(options.logfile))
45 elif options.stop:
46 ret=prserv.serv.stop_daemon(options.host, options.port)
47 else:
48 ret=parser.print_help()
49 return ret
50
51if __name__ == "__main__":
52 try:
53 ret = main()
54 except Exception:
55 ret = 1
56 import traceback
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050057 traceback.print_exc()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 sys.exit(ret)
59