def run(): try: if len(sys.argv) >= 2 and sys.argv[1] == '--compgen': compgen() return 0 envsetup() userdir.mv_user_files() ui = ui_root.Root() context = ui_context.Context(ui) load_rc(context, userdir.RC_FILE) atexit.register(exit_handler) options.interactive = utils.can_ask() if not options.interactive: err_buf.reset_lineno() options.batch = True user_args = parse_options() term._init() if options.profile: return profile_run(context, user_args) else: return do_work(context, user_args) except KeyboardInterrupt: print "Ctrl-C, leaving" sys.exit(1) except ValueError, e: common_err(str(e))
def handle_noninteractive_use(context, user_args): if options.shadow: if not context.run("cib use " + options.shadow): return 1 # this special case is silly, but we have to keep it to # preserve the backward compatibility if len(user_args) == 1 and user_args[0].startswith("conf"): if not context.run("configure"): return 1 elif len(user_args) > 0: # we're not sure yet whether it's an interactive session or not # (single-shot commands aren't) err_buf.reset_lineno() options.interactive = False l = add_quotes(user_args) if context.run(' '.join(l)): # if the user entered a level, then just continue if not context.previous_level(): return 0 set_interactive() if options.interactive: err_buf.reset_lineno(-1) else: return 1 return None
def do_work(context, user_args): compatibility_setup() if options.shadow: if not context.run("cib use " + options.shadow): return 1 # this special case is silly, but we have to keep it to # preserve the backward compatibility if len(user_args) == 1 and user_args[0].startswith("conf"): if not context.run("configure"): return 1 elif len(user_args) > 0: # we're not sure yet whether it's an interactive session or not # (single-shot commands aren't) err_buf.reset_lineno() options.interactive = False l = add_quotes(user_args) if context.run(' '.join(l)): # if the user entered a level, then just continue if not context.previous_level(): return 0 set_interactive() if options.interactive: err_buf.reset_lineno(-1) else: return 1 if options.input_file and options.input_file != "-": try: sys.stdin = open(options.input_file) except IOError, msg: common_err(msg) usage(2)
def parse_options(): opts, args = option_parser.parse_args() config.core.debug = "yes" if opts.debug else config.core.debug options.profile = opts.profile or options.profile options.regression_tests = opts.regression_tests or options.regression_tests config.color.style = opts.display or config.color.style config.core.force = opts.force or config.core.force if opts.filename: err_buf.reset_lineno() options.input_file, options.batch, options.interactive = opts.filename, True, False options.history = opts.history or options.history config.core.wait = opts.wait or config.core.wait options.shadow = opts.cib or options.shadow options.scriptdir = opts.scriptdir or options.scriptdir return args
def parse_options(): try: opts, user_args = getopt.getopt( sys.argv[1:], 'whdc:f:FX:RD:H:', ("wait", "version", "help", "debug", "cib=", "file=", "force", "profile=", "regression-tests", "display=", "history=", "scriptdir=")) for o, p in opts: if o in ("-h", "--help"): usage(0) elif o == "--version": print >> sys.stdout, ("%s" % config.CRM_VERSION) sys.exit(0) elif o == "-d": config.core.debug = "yes" elif o == "-X": options.profile = p elif o == "-R": options.regression_tests = True elif o in ("-D", "--display"): config.color.style = p elif o in ("-F", "--force"): config.core.force = "yes" elif o in ("-f", "--file"): options.batch = True options.interactive = False err_buf.reset_lineno() options.input_file = p elif o in ("-H", "--history"): options.history = p elif o in ("-w", "--wait"): config.core.wait = "yes" elif o in ("-c", "--cib"): options.shadow = p elif o == "--scriptdir": options.scriptdir = p return user_args except getopt.GetoptError, msg: print msg usage(1)