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 |
| 9 | |
| 10 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)),'lib')) |
| 11 | |
| 12 | import prserv |
| 13 | import prserv.serv |
| 14 | |
| 15 | __version__="1.0.0" |
| 16 | |
| 17 | PRHOST_DEFAULT='0.0.0.0' |
| 18 | PRPORT_DEFAULT=8585 |
| 19 | |
| 20 | def 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 | |
| 51 | if __name__ == "__main__": |
| 52 | try: |
| 53 | ret = main() |
| 54 | except Exception: |
| 55 | ret = 1 |
| 56 | import traceback |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 57 | traceback.print_exc() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | sys.exit(ret) |
| 59 | |