if not PsubUtils.checkOutDsName(options.outDS, distinguishedName, options.official, nickName, verbose=options.verbose): tmpStr = "invalid output dataset name: %s" % options.outDS tmpLog.error(tmpStr) sys.exit(1) # full execution string fullExecString = PsubUtils.convSysArgv() fullExecString += jsonExecStr # use INTR server if options.intrSrv: Client.useIntrServer() # create tmp dir curDir = os.getcwd() tmpDir = os.path.join(curDir, MiscUtils.wrappedUuidGen()) os.makedirs(tmpDir) # exit action def _onExit(dir, del_command): del_command('rm -rf %s' % dir) atexit.register(_onExit, tmpDir, MiscUtils.commands_get_output) # sandbox
def main(): # parse option parser = argparse.ArgumentParser(conflict_handler="resolve") parser.add_argument("-v", action="store_true", dest="verbose", default=False, help="Verbose") parser.add_argument('-c', action='store', dest='comString', default='', type=str, help='Execute a command in the batch mode') parser.add_argument("-3", action="store_true", dest="python3", default=False, help="Use python3") parser.add_argument('--version', action='store_const', const=True, dest='version', default=False, help='Displays version') parser.add_argument('--devSrv', action='store_const', const=True, dest='devSrv', default=False, help=argparse.SUPPRESS) parser.add_argument('--intrSrv', action='store_const', const=True, dest='intrSrv', default=False, help=argparse.SUPPRESS) options, args = parser.parse_known_args() # display version if options.version: print("Version: %s" % PandaToolsPkgInfo.release_version) sys.exit(0) # use dev server if options.devSrv: Client.useDevServer() # use INTR server if options.intrSrv: Client.useIntrServer() # fork for Ctl-c global fork_child_pid fork_child_pid = os.fork() if fork_child_pid == -1: print("ERROR : Failed to fork") sys.exit(1) if fork_child_pid == 0: # main # instantiate core if options.verbose: print(options) pbookCore = PBookCore.PBookCore(verbose=options.verbose) # CUI intmain(pbookCore, options.comString) else: # set handler signal.signal(signal.SIGINT, catch_sig) signal.signal(signal.SIGHUP, catch_sig) signal.signal(signal.SIGTERM, catch_sig) pid, status = os.wait() if os.WIFSIGNALED(status): sys.exit(-os.WTERMSIG(status)) elif os.WIFEXITED(status): sys.exit(os.WEXITSTATUS(status)) else: sys.exit(0)