+def catch_termination():
+ def run_cleanups():
+ for cleanup in cleanups:
+ cleanup()
+
+ atexit.register(run_cleanups)
+
+ def signal_handler(name, sig, *args):
+ signal.signal(sig, signal.SIG_DFL)
+ print('exiting due to %s' % name, file=sys.stderr)
+ run_cleanups()
+ os.kill(os.getpid(), sig)
+ raise RuntimeError('did not die due to signal %s !' % name)
+
+ for sig in (signal.SIGINT, signal.SIGTERM):
+ signal.signal(sig, partial(signal_handler, sig.name))
+
+optparser.add_option('--ownsource', default=2,
+ action='store_const', dest='ownsource', const=2,
+ help='source download fully enabled (default)')
+
+optparser.add_option('--ownsource-local',
+ action='store_const', dest='ownsource', const=1,
+ help='source download is local source code only')
+
+optparser.add_option('--no-ownsource',
+ action='store_const', dest='ownsource', const=0,
+ help='source download disabled (for testing only)')
+