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