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 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | import os |
| 7 | import sys,logging |
| 8 | import optparse |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 9 | import warnings |
| 10 | warnings.simplefilter("default") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | |
| 12 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)),'lib')) |
| 13 | |
| 14 | import prserv |
| 15 | import prserv.serv |
| 16 | |
| 17 | __version__="1.0.0" |
| 18 | |
| 19 | PRHOST_DEFAULT='0.0.0.0' |
| 20 | PRPORT_DEFAULT=8585 |
| 21 | |
| 22 | def 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 Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 41 | parser.add_option("-r", "--read-only", help="open database in read-only mode", |
| 42 | action="store_true") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | |
| 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 Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 48 | ret=prserv.serv.start_daemon(options.dbfile, options.host, options.port,os.path.abspath(options.logfile), options.read_only) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 49 | elif options.stop: |
| 50 | ret=prserv.serv.stop_daemon(options.host, options.port) |
| 51 | else: |
| 52 | ret=parser.print_help() |
| 53 | return ret |
| 54 | |
| 55 | if __name__ == "__main__": |
| 56 | try: |
| 57 | ret = main() |
| 58 | except Exception: |
| 59 | ret = 1 |
| 60 | import traceback |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 61 | traceback.print_exc() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | sys.exit(ret) |
| 63 | |