Module copr_be
[hide private]
[frames] | no frames]

Source Code for Module copr_be

 1  #!/usr/bin/python 
 2  # | -ttu 
 3   
 4  from __future__ import print_function 
 5  from __future__ import unicode_literals 
 6  from __future__ import division 
 7  from __future__ import absolute_import 
 8   
 9  import optparse 
10  import os 
11  import sys 
12   
13  from bunch import Bunch 
14   
15  from backend.daemons import run_backend 
16   
17   
18 -def parse_args(args):
19 parser = optparse.OptionParser("\ncopr-be [options]") 20 parser.add_option("-c", "--config", default="/etc/copr/copr-be.conf", 21 dest="config_file", 22 help="config file to use for copr-be run") 23 parser.add_option("-d", "--daemonize", default=False, dest="daemonize", 24 action="store_true", help="daemonize or not") 25 parser.add_option("-p", "--pidfile", 26 default="/var/run/copr-backend/copr-be.pid", 27 dest="pidfile", 28 help="pid file to use for copr-be if daemonized") 29 parser.add_option("-x", "--exit", default=False, dest="exit_on_worker", 30 action="store_true", help="exit on worker failure") 31 parser.add_option("-v", "--verbose", default=False, dest="verbose", 32 action="store_true", help="be more verbose") 33 34 opts, args = parser.parse_args(args) 35 if not os.path.exists(opts.config_file): 36 sys.stderr.write("No config file found at: {0}\n".format( 37 opts.config_file)) 38 sys.exit(1) 39 opts.config_file = os.path.abspath(opts.config_file) 40 41 ret_opts = Bunch() 42 for o in ("daemonize", "exit_on_worker", "pidfile", "config_file"): 43 setattr(ret_opts, o, getattr(opts, o)) 44 45 return ret_opts
46 47
48 -def main(args):
49 opts = parse_args(args) 50 run_backend(opts)
51 52 if __name__ == "__main__": 53 try: 54 main(sys.argv[1:]) 55 except KeyboardInterrupt: 56 sys.stderr.write("\nUser cancelled, may need cleanup\n") 57 sys.exit(0) 58