Beispiel #1
0
def delete(argv):
    """CLI function: delete."""
    opt_parser = RoseOptionParser().add_my_options("force_mode",
                                                   "non_interactive",
                                                   "local_only")
    opts, args = opt_parser.parse_args(argv)
    report = Reporter(opts.verbosity - opts.quietness)
    client = Client(event_handler=report, force_mode=opts.force_mode)
    SuiteId.svn.event_handler = client.event_handler # FIXME
    if not args:
        args.append(SuiteId(location=os.getcwd()))
    skip_prompt = opts.non_interactive
    prompt = PROMPT_DELETE
    if len(args) > 1:
        prompt = PROMPT_DELETE_ALL
    for arg in args:
        if not skip_prompt:
            try:
                response = raw_input(prompt.format(arg))
            except EOFError:
                continue
            if response == 'a' and len(args) > 1:
                skip_prompt = True
            elif response != 'y':
                continue
        try:
            client.delete(arg, opts.local_only)
        except (LocalCopyStatusError, RosePopenError) as e:
            client.event_handler(e)
            if not opts.force_mode:
                sys.exit(1)
Beispiel #2
0
def main():
    """Implement "rose suite-hook" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options(
        "mail_cc", "mail", "retrieve_job_logs", "shutdown")
    opts, args = opt_parser.parse_args()
    for key in ["mail_cc"]:
        values = []
        if getattr(opts, key):
            for value in getattr(opts, key):
                values.extend(value.split(","))
        setattr(opts, key, values)
    report = Reporter(opts.verbosity - opts.quietness - 1)  # Reduced default
    popen = RosePopener(event_handler=report)
    suite_engine_proc = SuiteEngineProcessor.get_processor(
        event_handler=report, popen=popen)
    args = suite_engine_proc.process_suite_hook_args(*args, **vars(opts))
    hook = RoseSuiteHook(event_handler=report,
                         popen=popen,
                         suite_engine_proc=suite_engine_proc)
    hook(*args,
         should_mail=opts.mail,
         mail_cc_list=opts.mail_cc,
         should_shutdown=opts.shutdown,
         should_retrieve_job_logs=opts.retrieve_job_logs)
Beispiel #3
0
def main():
    """rose task-env."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("cycle", "cycle_offsets", "path_globs", "prefix_delim", "suffix_delim")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness - 1)
    suite_engine_proc = SuiteEngineProcessor.get_processor(event_handler=report)
    kwargs = {}
    for k, v in vars(opts).items():
        kwargs[k] = v
    try:
        task_props = suite_engine_proc.get_task_props(*args, **kwargs)
        for k, v in task_props:
            report(str(EnvExportEvent(k, v)) + "\n", level=0)
        path_globs = opts.path_globs
        if path_globs is None:
            path_globs = []
        prepend_paths_map = get_prepend_paths(report, task_props.suite_dir, path_globs, full_mode=True)
        for k, prepend_paths in prepend_paths_map.items():
            orig_paths = []
            orig_v = os.getenv(k, "")
            if orig_v:
                orig_paths = orig_v.split(os.pathsep)
            v = os.pathsep.join(prepend_paths + orig_paths)
            report(str(EnvExportEvent(k, v)) + "\n", level=0)
    except Exception as e:
        report(e)
        if opts.debug_mode:
            traceback.print_exc(e)
        sys.exit(1)
Beispiel #4
0
def run_suite(*args):
    """Run "rose suite-run [args]" with a GTK dialog."""

    # Set up reporter
    queue = multiprocessing.Manager().Queue()
    verbosity = Reporter.VV
    out_ctx = ReporterContextQueue(Reporter.KIND_OUT, verbosity, queue=queue)
    err_ctx = ReporterContextQueue(Reporter.KIND_ERR, verbosity, queue=queue)
    event_handler = Reporter(contexts={"stdout": out_ctx, "stderr": err_ctx},
                             raise_on_exc=True)

    # Parse arguments
    suite_runner = SuiteRunner(event_handler=event_handler)
    prog = "rose suite-run"
    description = prog
    if args:
        description += " " + suite_runner.popen.list_to_shell_str(args)
    opt_parse = RoseOptionParser(prog=prog)
    opt_parse.add_my_options(*suite_runner.OPTIONS)
    opts, args = opt_parse.parse_args(list(args))

    # Invoke the command with a GTK dialog
    dialog_process = DialogProcess([suite_runner, opts, args],
                                   description=description,
                                   modal=False,
                                   event_queue=queue)
    return dialog_process.run()
Beispiel #5
0
def main():
    """Start quick server."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("non_interactive")
    opts, args = opt_parser.parse_args()
    arg = None
    if sys.argv[1:]:
        arg = sys.argv[1]
    if arg == "start":
        port = None
        if sys.argv[2:]:
            port = sys.argv[2]
        start(is_main=True, port=port)
    else:
        report = Reporter(opts.verbosity - opts.quietness)
        status = rose_bush_quick_server_status()
        level = Reporter.DEFAULT
        if arg != "stop":
           level = 0
        for k, v in sorted(status.items()):
            report("%s=%s\n" % (k, v), level=level)
        if (arg == "stop" and status.get("pid") and
            (opts.non_interactive or
             raw_input("Stop server? y/n (default=n)") == "y")):
            os.killpg(int(status["pid"]), signal.SIGTERM)
Beispiel #6
0
def main():
    """Implement "rose date"."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("offsets", "parse_format", "print_format",
                              "task_cycle_time_mode")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)
    ref_time = None
    if args:
        ref_time = args[0]
    try:
        ds = RoseDateShifter(opts.parse_format, opts.task_cycle_time_mode)
        if opts.task_cycle_time_mode and ds.task_cycle_time is None:
            raise UnboundEnvironmentVariableError(ds.TASK_CYCLE_TIME_MODE_ENV)
        ref_time = ds(ref_time)
        if opts.offsets:
            for offset in opts.offsets:
                ref_time = ds(ref_time, offset)
        if opts.print_format:
            print ds.date_format(opts.print_format, ref_time)
        else:
            print ref_time
    except Exception as e:
        if opts.debug_mode:
            import traceback
            traceback.print_exc(e)
        else:
            report(e)
        sys.exit(1)
Beispiel #7
0
def main():
    """Start quick server."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("non_interactive")
    opts, args = opt_parser.parse_args()
    arg = None
    if sys.argv[1:]:
        arg = sys.argv[1]
    if arg == "start":
        port = None
        if sys.argv[2:]:
            port = sys.argv[2]
        start(is_main=True, port=port)
    else:
        report = Reporter(opts.verbosity - opts.quietness)
        status = rose_bush_quick_server_status()
        level = Reporter.DEFAULT
        if arg != "stop":
           level = 0
        for k, v in sorted(status.items()):
            report("%s=%s\n" % (k, v), level=level)
        if (arg == "stop" and status.get("pid") and
            (opts.non_interactive or
             raw_input("Stop server? y/n (default=n)") == "y")):
            os.killpg(int(status["pid"]), signal.SIGTERM)
Beispiel #8
0
def main():
    """rose task-env."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("cycle", "cycle_offsets", "path_globs",
                              "prefix_delim", "suffix_delim")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness - 1)
    suite_engine_proc = SuiteEngineProcessor.get_processor(
        event_handler=report)
    kwargs = {}
    for k, v in vars(opts).items():
        kwargs[k] = v
    try:
        task_props = suite_engine_proc.get_task_props(*args, **kwargs)
        for k, v in task_props:
            report(str(EnvExportEvent(k, v)) + "\n", level=0)
        path_globs = opts.path_globs
        if path_globs is None:
            path_globs = []
        prepend_paths_map = get_prepend_paths(report,
                                              task_props.suite_dir,
                                              path_globs,
                                              full_mode=True)
        for k, prepend_paths in prepend_paths_map.items():
            orig_paths = []
            orig_v = os.getenv(k, "")
            if orig_v:
                orig_paths = orig_v.split(os.pathsep)
            v = os.pathsep.join(prepend_paths + orig_paths)
            report(str(EnvExportEvent(k, v)) + "\n", level=0)
    except Exception as e:
        report(e)
        if opts.debug_mode:
            traceback.print_exc(e)
        sys.exit(1)
Beispiel #9
0
def lookup(argv):
    """CLI command to run the various search types"""
    opt_parser = RoseOptionParser().add_my_options(
        "address_mode", "all_revs", "lookup_mode", "no_headers", "prefixes",
        "print_format", "query_mode", "reverse", "search_mode", "sort")
    opts, args = opt_parser.parse_args(argv)
    if not args:
        sys.exit(opt_parser.print_usage())
    if not opts.lookup_mode:
        if args[0].startswith("http"):
            opts.lookup_mode = "address"
        else:
            opts.lookup_mode = "search"
    ws_client = RosieWSClient(
        prefixes=opts.prefixes,
        event_handler=Reporter(opts.verbosity - opts.quietness))
    try:
        if opts.lookup_mode == "address":
            data_and_url_list = ws_client.address_lookup(url=args[0])
        elif opts.lookup_mode == "query":
            q_items = ws_client.query_split(args)
            for i, q_item in enumerate(q_items):
                q_items[i] = " ".join(q_item)
            data_and_url_list = ws_client.query(
                q_items, all_revs=int(opts.all_revs))
        else:  # if opts.lookup_mode == "search":
            data_and_url_list = ws_client.search(
                args, all_revs=int(opts.all_revs))
    except RosieWSClientError as exc:
        if opts.debug_mode:
            traceback.print_exc(exc)
        sys.exit(str(exc))
    for data, url in data_and_url_list:
        _display_maps(opts, ws_client, data, url)
Beispiel #10
0
def parse_cli(*args, **kwargs):
    """Parse command line, start/stop ad-hoc server.

    Return a CLI instruction tuple for a valid command instruction, else False:
        ("start", Boolean, port):
            start server on 'port', [2]==True indicating non_interactive mode.
        ("stop", Boolean):
            stop server, [2]==True indicating service_root_mode.
        None:
            bare command, requesting to print server status
    """
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("non_interactive", "service_root_mode")
    opts, args = opt_parser.parse_args()

    arg = None
    if args:
        arg = args[0]

    if arg == "start":
        port = DEFAULT_PORT
        if args[1:]:
            try:
                port = int(args[1])
            except ValueError:
                print("Invalid port specified. Using the default port.")
        return ("start", opts.service_root_mode, port)
    elif arg == "stop":
        return ("stop", opts.non_interactive)
    elif arg:  # unrecognised (invalid) argument, to ignore
        return False  # False to distinguish from None for no arguments given
Beispiel #11
0
def ws_cli(service_cls, *args, **kwargs):
    """Parse command line, start/stop ad-hoc server.

    service_cls - Class to launch web service. Must have the constants
                  service_cls.NS and service_cls.UTIL. *args and **kwargs are
                  passed to its constructor.
    """
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("non_interactive", "service_root_mode")
    opts, args = opt_parser.parse_args()
    arg = None
    if args:
        arg = args[0]
    if arg == "start":
        port = None
        if args[1:]:
            port = args[1]
        _ws_init(service_cls, port, opts.service_root_mode, *args, **kwargs)
    else:
        report = Reporter(opts.verbosity - opts.quietness)
        status = _get_server_status(service_cls)
        level = Reporter.DEFAULT
        if arg != "stop":
            level = 0
        for key, value in sorted(status.items()):
            report("%s=%s\n" % (key, value), level=level)
        if (arg == "stop" and status.get("pid") and
                (opts.non_interactive or
                 raw_input("Stop server? y/n (default=n)") == "y")):
            os.killpg(int(status["pid"]), signal.SIGTERM)
Beispiel #12
0
def local_suites(argv):
    """CLI command to list all the locally checked out suites"""
    opt_parser = RoseOptionParser().add_my_options("format", "prefix", 
                                                   "reverse", "sort")    
    opts, args = opt_parser.parse_args(argv)

    ws_client = Client()
    if opts.prefix is not None: 

        results = get_local_suite_details(opts.prefix)
        return _display_maps(opts, ws_client, results)
    else:
        id_list = get_local_suites()   
        if len(id_list) > 0:
            prefixes = []
            for id_ in id_list:
                prefixes.append(id_.prefix)
            for p in sorted(set(prefixes)):
                if len(prefixes) == 1:
                    suites_this_prefix = id_list
                else:
                    suites_this_prefix = []
                    for id_ in id_list:
                        if id_.prefix == p:
                            suites_this_prefix.append(id_)
            
                results = get_local_suite_details(p, id_list)
                opts.prefix = p
                _display_maps(opts, ws_client, results, 
                              local_suites=suites_this_prefix)
        return
Beispiel #13
0
def main():
    """Implement "rose env-cat"."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("unbound")
    opts, args = opt_parser.parse_args()
    if not args:
        args = ["-"]
    for arg in args:
        if arg == "-":
            f = sys.stdin
        else:
            f = open(arg)
        line_num = 0
        while True:
            line_num += 1
            line = f.readline()
            if not line:
                break
            try:
                sys.stdout.write(env_var_process(line, opts.unbound))
            except UnboundEnvironmentVariableError as e:
                name = arg
                if arg == "-":
                    name = "<STDIN>"
                sys.exit("%s:%s: %s" % (name, line_num, str(e)))
        f.close()
Beispiel #14
0
def ws_cli(service_cls, *args, **kwargs):
    """Parse command line, start/stop ad-hoc server.

    service_cls - Class to launch web service. Must have the constants
                  service_cls.NS and service_cls.UTIL. *args and **kwargs are
                  passed to its constructor.
    """
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("non_interactive", "service_root_mode")
    opts, args = opt_parser.parse_args()
    arg = None
    if args:
        arg = args[0]
    if arg == "start":
        port = None
        if args[1:]:
            port = args[1]
        _ws_init(service_cls, port, opts.service_root_mode, *args, **kwargs)
    else:
        report = Reporter(opts.verbosity - opts.quietness)
        status = _get_server_status(service_cls)
        level = Reporter.DEFAULT
        if arg != "stop":
            level = 0
        for key, value in sorted(status.items()):
            report("%s=%s\n" % (key, value), level=level)
        if (arg == "stop" and status.get("pid")
                and (opts.non_interactive
                     or raw_input("Stop server? y/n (default=n)") == "y")):
            os.killpg(int(status["pid"]), signal.SIGTERM)
Beispiel #15
0
def main():
    """Launcher for command line invokation of rose stem."""

    # Process options
    opt_parser = RoseOptionParser()

    option_keys = SuiteRunner.OPTIONS + OPTIONS
    opt_parser.add_my_options(*option_keys)
    opts, args = opt_parser.parse_args()

    # Set up a runner instance and process the options
    stem = StemRunner(opts)
    if opts.debug_mode:
        opts = stem.process()
    else:
        try:
            opts = stem.process()
        except Exception as e:
            stem.reporter(e)
            sys.exit(1)

    # Get the suiterunner object and execute
    runner = SuiteRunner(event_handler=stem.reporter,
                         popen=stem.popen,
                         fs_util=stem.fs_util)
    if opts.debug_mode:
        sys.exit(runner(opts, args))
    try:
        sys.exit(runner(opts, args))
    except Exception as e:
        runner.handle_event(e)
        if isinstance(e, RosePopenError):
            sys.exit(e.rc)
        else:
            sys.exit(1)
Beispiel #16
0
def lookup(argv):
    """CLI command to run the various search types"""
    opt_parser = RoseOptionParser().add_my_options(
        "address_mode", "all_revs", "lookup_mode", "no_headers", "prefixes",
        "print_format", "query_mode", "reverse", "search_mode", "sort")
    opts, args = opt_parser.parse_args(argv)
    if not args:
        sys.exit(opt_parser.print_usage())
    if not opts.lookup_mode:
        if args[0].startswith("http"):
            opts.lookup_mode = "address"
        else:
            opts.lookup_mode = "search"
    ws_client = RosieWSClient(
        prefixes=opts.prefixes,
        event_handler=Reporter(opts.verbosity - opts.quietness))
    try:
        if opts.lookup_mode == "address":
            data_and_url_list = ws_client.address_lookup(url=args[0])
        elif opts.lookup_mode == "query":
            q_items = ws_client.query_split(args)
            for i, q_item in enumerate(q_items):
                q_items[i] = " ".join(q_item)
            data_and_url_list = ws_client.query(
                q_items, all_revs=int(opts.all_revs))
        else:  # if opts.lookup_mode == "search":
            data_and_url_list = ws_client.search(
                args, all_revs=int(opts.all_revs))
    except RosieWSClientError as exc:
        if opts.debug_mode:
            traceback.print_exc(exc)
        sys.exit(str(exc))
    for data, url in data_and_url_list:
        _display_maps(opts, ws_client, data, url)
Beispiel #17
0
Datei: run.py Projekt: kinow/rose
def run_suite(*args):
    """Run "rose suite-run [args]" with a GTK dialog."""

    # Set up reporter
    queue = multiprocessing.Manager().Queue()
    verbosity = Reporter.VV
    out_ctx = ReporterContextQueue(Reporter.KIND_OUT, verbosity, queue=queue)
    err_ctx = ReporterContextQueue(Reporter.KIND_ERR, verbosity, queue=queue)
    event_handler = Reporter(contexts={
        "stdout": out_ctx,
        "stderr": err_ctx
    },
                             raise_on_exc=True)

    # Parse arguments
    suite_runner = SuiteRunner(event_handler=event_handler)
    prog = "rose suite-run"
    description = prog
    if args:
        description += " " + suite_runner.popen.list_to_shell_str(args)
    opt_parse = RoseOptionParser(prog=prog)
    opt_parse.add_my_options(*suite_runner.OPTIONS)
    opts, args = opt_parse.parse_args(list(args))

    # Invoke the command with a GTK dialog
    dialog_process = DialogProcess([suite_runner, opts, args],
                                   description=description,
                                   modal=False,
                                   event_queue=queue)
    return dialog_process.run()
Beispiel #18
0
def main():
    """Implement "rose env-cat"."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("match_mode", "output_file", "unbound")
    opts, args = opt_parser.parse_args()
    if not args:
        args = ["-"]
    if not opts.output_file or opts.output_file == "-":
        out_handle = sys.stdout
    else:
        out_handle = open(opts.output_file, "wb")
    for arg in args:
        if arg == "-":
            in_handle = sys.stdin
        else:
            in_handle = open(arg)
        line_num = 0
        while True:
            line_num += 1
            line = in_handle.readline()
            if not line:
                break
            try:
                out_handle.write(
                    env_var_process(line, opts.unbound, opts.match_mode))
            except UnboundEnvironmentVariableError as exc:
                name = arg
                if arg == "-":
                    name = "<STDIN>"
                sys.exit("%s:%s: %s" % (name, line_num, str(exc)))
        in_handle.close()
    out_handle.close()
Beispiel #19
0
def main():
    """Implement the "rose config-dump" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("conf_dir", "files", "no_pretty_mode")
    opts, args = opt_parser.parse_args()
    verbosity = opts.verbosity - opts.quietness
    report = Reporter(verbosity)
    fs_util = FileSystemUtil(report)
    if opts.conf_dir:
        fs_util.chdir(opts.conf_dir)
    file_names = []
    if opts.files:
        file_names = opts.files
    else:
        for dirpath, dirnames, filenames in os.walk("."):
            for filename in fnmatch.filter(filenames, "rose-*.conf"):
                p = os.path.join(dirpath, filename)[2:]  # remove leading ./
                file_names.append(p)
    for file_name in file_names:
        t = NamedTemporaryFile()
        node = ConfigLoader()(file_name)
        if (not opts.no_pretty_mode
                and os.path.basename(file_name) != META_CONFIG_NAME):
            pretty_format_config(node, ignore_error=True)
        ConfigDumper()(node, t)
        t.seek(0)
        if not filecmp.cmp(t.name, file_name, shallow=False):
            report(ConfigDumpEvent(file_name))
            ConfigDumper()(node, file_name)
Beispiel #20
0
def main():
    """Implement the "rose config-dump" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("conf_dir", "files", "no_pretty_mode")
    opts, args = opt_parser.parse_args()
    verbosity = opts.verbosity - opts.quietness
    report = Reporter(verbosity)
    fs_util = FileSystemUtil(report)
    if opts.conf_dir:
        fs_util.chdir(opts.conf_dir)
    file_names = []
    if opts.files:
        file_names = opts.files
    else:
        for dirpath, dirnames, filenames in os.walk("."):
            for filename in fnmatch.filter(filenames, "rose-*.conf"):
                p = os.path.join(dirpath, filename)[2:] # remove leading ./
                file_names.append(p)
    for file_name in file_names:
        t = NamedTemporaryFile()
        node = ConfigLoader()(file_name)
        if not opts.no_pretty_mode:
            pretty_format_config(node)
        ConfigDumper()(node, t)
        t.seek(0)
        if not filecmp.cmp(t.name, file_name, shallow=False):
            report(ConfigDumpEvent(file_name))
            ConfigDumper()(node, file_name)
Beispiel #21
0
def main():
    """Implement "rose env-cat"."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("match_mode", "output_file", "unbound")
    opts, args = opt_parser.parse_args()
    if not args:
        args = ["-"]
    if not opts.output_file or opts.output_file == "-":
        out_handle = sys.stdout
    else:
        out_handle = open(opts.output_file, "wb")
    for arg in args:
        if arg == "-":
            in_handle = sys.stdin
        else:
            in_handle = open(arg)
        line_num = 0
        while True:
            line_num += 1
            line = in_handle.readline()
            if not line:
                break
            try:
                out_handle.write(
                    env_var_process(line, opts.unbound, opts.match_mode))
            except UnboundEnvironmentVariableError as exc:
                name = arg
                if arg == "-":
                    name = "<STDIN>"
                sys.exit("%s:%s: %s" % (name, line_num, str(exc)))
        in_handle.close()
    out_handle.close()
Beispiel #22
0
def main():
    """Implement the "rose config-dump" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("conf_dir", "files", "no_pretty_mode")
    opts = opt_parser.parse_args()[0]
    verbosity = opts.verbosity - opts.quietness
    report = Reporter(verbosity)
    fs_util = FileSystemUtil(report)
    if opts.conf_dir:
        fs_util.chdir(opts.conf_dir)
    file_names = []
    if opts.files:
        file_names = opts.files
    else:
        for dirpath, _, filenames in os.walk("."):
            for filename in fnmatch.filter(filenames, "rose-*.conf"):
                path = os.path.join(dirpath, filename)[2:]  # remove leading ./
                file_names.append(path)
    for file_name in file_names:
        handle = NamedTemporaryFile()
        node = ConfigLoader()(file_name)
        if (not opts.no_pretty_mode and
                os.path.basename(file_name) != META_CONFIG_NAME):
            pretty_format_config(node, ignore_error=True)
        ConfigDumper()(node, handle)
        handle.seek(0)
        if not filecmp.cmp(handle.name, file_name, shallow=False):
            report(ConfigDumpEvent(file_name))
            ConfigDumper()(node, file_name)
Beispiel #23
0
def main():
    """Implement the "rose suite-clean" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("name", "non_interactive")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)
    cleaner = SuiteRunCleaner(event_handler=report)
    if opts.name:
        args.append(opts.name)
    if not args:
        args = [os.path.basename(os.getcwd())]
    os.chdir(os.path.expanduser('~'))
    n_done = 0
    for arg in args:
        if not opts.non_interactive:
            try:
                answer = raw_input("Clean %s? y/n (default n) " % arg)
            except EOFError:
                sys.exit(1)
            if answer not in ["Y", "y"]:
                continue
        try:
            cleaner.clean(arg)
        except Exception as e:
            report(e)
            if opts.debug_mode:
                traceback.print_exc(e)
        else:
            n_done += 1
    sys.exit(len(args) - n_done) # Return 0 if everything done
Beispiel #24
0
def main():
    """Launcher for the CLI functions."""
    argv = sys.argv[1:]
    if not argv:
        return sys.exit(1)
    name = argv[0]
    try:
        runner_class = Runner.get_runner_class(name)
    except KeyError:
        sys.exit("rose.run: %s: incorrect usage" % argv[0])
    option_keys = runner_class.OPTIONS
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options(*option_keys)
    opts, args = opt_parser.parse_args(argv[1:])
    event_handler = Reporter(opts.verbosity - opts.quietness)
    runner = runner_class(event_handler)
    if opts.debug_mode:
        sys.exit(runner(opts, args))
    try:
        sys.exit(runner(opts, args))
    except Exception as e:
        runner.handle_event(e)
        if isinstance(e, RosePopenError):
            sys.exit(e.rc)
        else:
            sys.exit(1)
Beispiel #25
0
def main():
    """Launcher for command line invokation of rose stem."""

    # Process options
    opt_parser = RoseOptionParser()

    option_keys = SuiteRunner.OPTIONS + OPTIONS
    opt_parser.add_my_options(*option_keys)
    opts, args = opt_parser.parse_args()

    # Set up a runner instance and process the options
    stem = StemRunner(opts)
    if opts.debug_mode:
        opts = stem.process()
    else:
        try:
            opts = stem.process()
        except Exception as e:
            stem.reporter(e)
            sys.exit(1)

    # Get the suiterunner object and execute
    runner = SuiteRunner(event_handler=stem.reporter,
                         popen=stem.popen,
                         fs_util=stem.fs_util)
    if opts.debug_mode:
        sys.exit(runner(opts, args))
    try:
        sys.exit(runner(opts, args))
    except Exception as e:
        runner.handle_event(e)
        if isinstance(e, RosePopenError):
            sys.exit(e.rc)
        else:
            sys.exit(1)
Beispiel #26
0
def main():
    """Implement "rose suite-hook" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options(
        "mail_cc", "mail", "retrieve_job_logs", "shutdown")
    opts, args = opt_parser.parse_args()
    for key in ["mail_cc"]:
        values = []
        if getattr(opts, key):
            for value in getattr(opts, key):
                values.extend(value.split(","))
        setattr(opts, key, values)
    report = Reporter(opts.verbosity - opts.quietness - 1)  # Reduced default
    popen = RosePopener(event_handler=report)
    suite_engine_proc = SuiteEngineProcessor.get_processor(
        event_handler=report, popen=popen)
    args = suite_engine_proc.process_suite_hook_args(*args, **vars(opts))
    hook = RoseSuiteHook(event_handler=report,
                         popen=popen,
                         suite_engine_proc=suite_engine_proc)
    hook(*args,
         should_mail=opts.mail,
         mail_cc_list=opts.mail_cc,
         should_shutdown=opts.shutdown,
         should_retrieve_job_logs=opts.retrieve_job_logs)
Beispiel #27
0
def hello(argv):
    """Set up connection to a Rosie web service."""
    opt_parser = RoseOptionParser().add_my_options("prefix")
    opts = opt_parser.parse_args(argv)[0]
    report = Reporter(opts.verbosity - opts.quietness)
    popen = RosePopener(event_handler=report)
    ws_client = RosieWSClient(prefix=opts.prefix, popen=popen)
    report(ws_client.prefix + ": " + ws_client.hello(), level=0)
Beispiel #28
0
def hello(argv):
    """Set up connection to a Rosie web service."""
    opt_parser = RoseOptionParser().add_my_options("prefixes")
    opts = opt_parser.parse_args(argv)[0]
    report = Reporter(opts.verbosity - opts.quietness)
    ws_client = RosieWSClient(prefixes=opts.prefixes, event_handler=report)
    for response_data, response_url in ws_client.hello():
        report("%s: %s" % (response_url, response_data), level=0)
Beispiel #29
0
def hello(argv):
    """Set up connection to a Rosie web service."""
    opt_parser = RoseOptionParser().add_my_options("prefixes")
    opts = opt_parser.parse_args(argv)[0]
    report = Reporter(opts.verbosity - opts.quietness)
    ws_client = RosieWSClient(prefixes=opts.prefixes, event_handler=report)
    for response_data, response_url in ws_client.hello():
        report("%s: %s" % (response_url, response_data), level=0)
Beispiel #30
0
Datei: vc.py Projekt: csimag/rose
def create(argv):
    """CLI function: create and copy."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("checkout_mode", "info_file",
                              "meta_suite_mode", "non_interactive", "prefix")
    opts, args = opt_parser.parse_args(argv)
    verbosity = opts.verbosity - opts.quietness
    report = Reporter(verbosity)
    client = RosieVCClient(event_handler=report)
    SuiteId.svn.event_handler = client.event_handler # FIXME: ugly?
    from_id = None
    if args:
        from_id = SuiteId(id_text=args[0])
        if from_id.branch is None:
            from_id.branch = from_id.BRANCH_TRUNK
        if from_id.revision is None:
            from_id.revision = from_id.REV_HEAD
            from_id = SuiteId(id_text=from_id.to_string_with_version())
    if opts.info_file is None:
        try:
            info_config = client.generate_info_config(from_id, opts.prefix)
        except (RosePopenError) as e:
            report(e)
            sys.exit(1)
        info_file = tempfile.NamedTemporaryFile(delete=False)
        try:
            rose.config.dump(info_config, info_file)
            info_file.close()
            command_list = client.popen.get_cmd("editor", info_file.name)
            client.popen(*command_list, stdout=sys.stdout)
            info_config = rose.config.load(info_file.name)
        finally:
            os.unlink(info_file.name)
    elif opts.info_file == "-":
        info_config = rose.config.load(sys.stdin)
    else:
        info_config = rose.config.load(opts.info_file)
    if not opts.non_interactive:
        try:
            response = raw_input("Create? y/n (default n) ")
        except EOFError:
            sys.exit(1)
        if response != 'y':
            sys.exit(1)
    try:
        id = client.create(info_config, from_id, opts.prefix,
                           opts.meta_suite_mode)
    except (RosePopenError, SuiteInfoFieldError, SuiteIdOverflowError) as e:
        report(e)
        sys.exit(1)
    if opts.checkout_mode:
        try:
            client.checkout(id)
        except (FileExistError, RosePopenError) as e:
            report(e)
            sys.exit(1)
Beispiel #31
0
def main():
    opt_parser = RoseOptionParser()
    opts, args = opt_parser.parse_args()
    event_handler = Reporter(opts.verbosity - opts.quietness)
    suite_scan = SuiteScan(event_handler=event_handler)
    results = suite_scan(*args)
    if results:
        for result in results:
            print(result)
    else:
        sys.exit(1)
Beispiel #32
0
def main():
    """Implement the "rose config" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("default", "files", "keys", "no_ignore")
    opts, args = opt_parser.parse_args()
    try:
        if opts.files:
            root_node = ConfigNode()
            for file in opts.files:
                if file == "-":
                    load(sys.stdin, root_node)
                    sys.stdin.close()
                else:
                    load(file, root_node)
        else:
            root_node = default_node()
    except SyntaxError as e:
        sys.exit(repr(e))
    if opts.quietness:
        if root_node.get(args, opts.no_ignore) is None:
            sys.exit(1)
    elif opts.keys_mode:
        try:
            keys = root_node.get(args, opts.no_ignore).value.keys()
        except:
            sys.exit(1)
        keys.sort()
        for key in keys:
            print key
    elif len(args) == 0:
        dump(root_node)
    else:
        node = root_node.get(args, opts.no_ignore)
        if node is not None and isinstance(node.value, dict):
            keys = node.value.keys()
            keys.sort()
            for key in keys:
                node_of_key = node.get([key], opts.no_ignore)
                value = node_of_key.value
                state = node_of_key.state
                string = "%s%s=%s" % (state, key, value)
                lines = string.splitlines()
                print lines[0]
                i_equal = len(state + key) + 1
                for line in lines[1:]:
                    print " " * i_equal + line
        else:
            if node is None:
                if opts.default is None:
                    sys.exit(1)
                print opts.default
            else:
                print node.value
Beispiel #33
0
def list_local_suites(argv):
    """CLI command to list all the locally checked out suites"""
    opt_parser = RoseOptionParser().add_my_options(
        "no_headers", "prefixes", "print_format", "reverse", "sort", "user")
    opts = opt_parser.parse_args(argv)[0]
    report = Reporter(opts.verbosity - opts.quietness)

    if opts.user:
        alternative_roses_dir = SuiteId.get_local_copy_root(opts.user)
        report(UserSpecificRoses(alternative_roses_dir), prefix=None)

    ws_client = RosieWSClient(prefixes=opts.prefixes, event_handler=report)
    _display_maps(opts, ws_client, ws_client.query_local_copies(opts.user))
Beispiel #34
0
def main():
    """Implement "rosa svn-post-commit"."""
    opt_parser = RoseOptionParser()
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)
    hook = RosieSvnPostCommitHook(report)
    try:
        repos, revision = args[0:2]
        hook.run(repos, revision)
    except Exception as exc:
        report(exc)
        if opts.debug_mode:
            traceback.print_exc(exc)
        sys.exit(1)
Beispiel #35
0
def main():
    """Implement "rosa svn-post-commit"."""
    opt_parser = RoseOptionParser()
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)
    hook = RosieSvnPostCommitHook(report)
    try:
        repos, revision = args[0:2]
        hook.run(repos, revision)
    except Exception as exc:
        report(exc)
        if opts.debug_mode:
            traceback.print_exc(exc)
        sys.exit(1)
Beispiel #36
0
def list_local_suites(argv):
    """CLI command to list all the locally checked out suites"""
    opt_parser = RoseOptionParser().add_my_options("no_headers", "prefixes",
                                                   "print_format", "reverse",
                                                   "sort", "user")
    opts = opt_parser.parse_args(argv)[0]
    report = Reporter(opts.verbosity - opts.quietness)

    if opts.user:
        alternative_roses_dir = SuiteId.get_local_copy_root(opts.user)
        report(UserSpecificRoses(alternative_roses_dir), prefix=None)

    ws_client = RosieWSClient(prefixes=opts.prefixes, event_handler=report)
    _display_maps(opts, ws_client, ws_client.query_local_copies(opts.user))
Beispiel #37
0
def main():
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("web_browser_mode")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)

    if opts.debug_mode:
        suite_log_view(opts, args, report)
    else:
        try:
            suite_log_view(opts, args, report)
        except Exception as e:
            report(e)
            sys.exit(1)
Beispiel #38
0
def main():
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("archive_mode", "force_mode", "name",
                              "non_interactive", "prune_remote_mode",
                              "update_mode", "user", "view_mode")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)

    try:
        suite_log_view(opts, args, report)
    except Exception as e:
        report(e)
        if opts.debug_mode:
            traceback.print_exc(e)
        sys.exit(1)
Beispiel #39
0
def main():
    """Implement "rosa svn-pre-commit"."""
    add_meta_paths()
    opt_parser = RoseOptionParser()
    opts, args = opt_parser.parse_args()
    repos, txn = args
    report = Reporter(opts.verbosity - opts.quietness)
    hook = RosieSvnPreCommitHook(report)
    try:
        hook(repos, txn)
    except Exception as exc:
        report(exc)
        if opts.debug_mode:
            traceback.print_exc(exc)
        sys.exit(1)
Beispiel #40
0
def main():
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("archive_mode", "force_mode", "name",
                              "non_interactive", "prune_remote_mode",
                              "update_mode", "user", "view_mode")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)

    try:
        suite_log_view(opts, args, report)
    except Exception as e:
        report(e)
        if opts.debug_mode:
            traceback.print_exc(e)
        sys.exit(1)
Beispiel #41
0
def checkout(argv):
    """CLI function: checkout."""
    opt_parser = RoseOptionParser().add_my_options("force_mode")
    opts, args = opt_parser.parse_args(argv)
    verbosity = opts.verbosity - opts.quietness
    report = Reporter(verbosity)
    client = Client(event_handler=report, force_mode=opts.force_mode)
    SuiteId.svn.event_handler = client.event_handler # FIXME: ugly?
    for arg in args:
        try:
            client.checkout(arg)
        except (FileExistError, RosePopenError) as e:
            report(e)
            if not opts.force_mode:
                sys.exit(1)
Beispiel #42
0
def main():
    """Implement "rosa svn-pre-commit"."""
    add_meta_paths()
    opt_parser = RoseOptionParser()
    opts, args = opt_parser.parse_args()
    repos, txn = args
    report = Reporter(opts.verbosity - opts.quietness)
    hook = RosieSvnPreCommitHook(report)
    try:
        hook(repos, txn)
    except Exception as exc:
        report(exc)
        if opts.debug_mode:
            traceback.print_exc(exc)
        sys.exit(1)
Beispiel #43
0
def main():
    opt_parser = RoseOptionParser()
    opts, args = opt_parser.parse_args()
    event_handler = Reporter(opts.verbosity - opts.quietness)
    suite_scanner = SuiteScanner(event_handler=event_handler)
    results, exceptions = SuiteScanner(event_handler=event_handler)(*args)
    ret = 1
    if results:
        ret = 0
        for result in results:
            suite_scanner.handle_event(result)
    if exceptions:
        ret = 2
        for exception in exceptions:
            event_handler(exception)
    sys.exit(ret)
Beispiel #44
0
def main():
    opt_parser = RoseOptionParser()
    opts, args = opt_parser.parse_args()
    event_handler = Reporter(opts.verbosity - opts.quietness)
    suite_scanner = SuiteScanner(event_handler=event_handler)
    results, exceptions = SuiteScanner(event_handler=event_handler)(*args)
    ret = 1
    if results:
        ret = 0
        for result in results:
            suite_scanner.handle_event(result)
    if exceptions:
        ret = 2
        for exception in exceptions:
            event_handler(exception)
    sys.exit(ret)
Beispiel #45
0
def parse_macro_mode_args(mode="macro", argv=None):
    """Parse options/arguments for rose macro and upgrade."""
    opt_parser = RoseOptionParser()
    options = ["conf_dir", "meta_path", "non_interactive", "output_dir"]
    if mode == "macro":
        options.extend(["fix", "validate_all"])
    elif mode == "upgrade":
        options.extend(["downgrade", "all_versions"])
    else:
        raise KeyError("Wrong mode: {0}".format(mode))
    opt_parser.add_my_options(*options)
    if argv is None:
        opts, args = opt_parser.parse_args()
    else:
        opts, args = opt_parser.parse_args(argv)
    opts, args = opt_parser.parse_args(argv)
    if mode == "upgrade" and len(args) > 1:
        sys.stderr.write(opt_parser.get_usage())
        return None
    if opts.conf_dir is None:
        opts.conf_dir = os.getcwd()
    opts.conf_dir = os.path.abspath(opts.conf_dir)
    if opts.output_dir is not None:
        opts.output_dir = os.path.abspath(opts.output_dir)
    sys.path.append(os.getenv("ROSE_HOME"))
    add_opt_meta_paths(opts.meta_path)
    config_name = os.path.basename(opts.conf_dir)
    config_file_path = os.path.join(opts.conf_dir, rose.SUB_CONFIG_NAME)
    if (not os.path.exists(config_file_path)
            or not os.path.isfile(config_file_path)):
        rose.reporter.Reporter()(ERROR_LOAD_CONFIG_DIR.format(opts.conf_dir),
                                 kind=rose.reporter.Reporter.KIND_ERR,
                                 level=rose.reporter.Reporter.FAIL)
        return None
    # Load the configuration and the metadata macros.
    config_loader = rose.config.ConfigLoader()
    app_config = config_loader(config_file_path)
    standard_format_config(app_config)

    # Load meta config if it exists.
    meta_config = rose.config.ConfigNode()
    meta_path, warning = load_meta_path(app_config, opts.conf_dir)
    if meta_path is None:
        if mode == "macro":
            text = ERROR_LOAD_METADATA.format("")
            if warning:
                text = warning
            rose.reporter.Reporter()(text,
                                     kind=rose.reporter.Reporter.KIND_ERR,
                                     level=rose.reporter.Reporter.FAIL)
            return None
    else:
        meta_config = load_meta_config(app_config,
                                       directory=opts.conf_dir,
                                       config_type=rose.SUB_CONFIG_NAME,
                                       ignore_meta_error=True)
    return app_config, meta_config, config_name, args, opts
Beispiel #46
0
def main():
    """Implement "rose date"."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options(
        "calendar",
        "diff",
        "offsets1",
        "offsets2",
        "parse_format",
        "print_format",
        "task_cycle_time_mode",
        "as_total",
        "utc_mode")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)

    ref_point_str = None
    if opts.task_cycle_time_mode:
        ref_point_str = os.getenv(
            RoseDateTimeOperator.TASK_CYCLE_TIME_ENV)
        if ref_point_str is None:
            exc = UnboundEnvironmentVariableError(
                RoseDateTimeOperator.TASK_CYCLE_TIME_ENV)
            report(exc)
            if opts.debug_mode:
                raise exc
            sys.exit(1)

    date_time_oper = RoseDateTimeOperator(
        parse_format=opts.parse_format,
        utc_mode=opts.utc_mode,
        calendar_mode=opts.calendar,
        ref_point_str=ref_point_str)

    try:
        if len(args) < 2:
            if opts.duration_print_format:
                _convert_duration(date_time_oper, opts, args)
            else:
                _print_time_point(date_time_oper, opts, args)
        else:
            _print_duration(date_time_oper, opts, args)
    except OffsetValueError as exc:
        report(exc)
        if opts.debug_mode:
            raise exc
        sys.exit(1)
Beispiel #47
0
def main():
    """Implement "rose date"."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options(
        "calendar",
        "diff",
        "offsets1",
        "offsets2",
        "parse_format",
        "print_format",
        "task_cycle_time_mode",
        "as_total",
        "utc_mode")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)

    ref_point_str = None
    if opts.task_cycle_time_mode:
        ref_point_str = os.getenv(
            RoseDateTimeOperator.TASK_CYCLE_TIME_ENV)
        if ref_point_str is None:
            exc = UnboundEnvironmentVariableError(
                RoseDateTimeOperator.TASK_CYCLE_TIME_ENV)
            report(exc)
            if opts.debug_mode:
                raise exc
            sys.exit(1)

    date_time_oper = RoseDateTimeOperator(
        parse_format=opts.parse_format,
        utc_mode=opts.utc_mode,
        calendar_mode=opts.calendar,
        ref_point_str=ref_point_str)

    try:
        if len(args) < 2:
            if opts.duration_print_format:
                _convert_duration(date_time_oper, opts, args)
            else:
                _print_time_point(date_time_oper, opts, args)
        else:
            _print_duration(date_time_oper, opts, args)
    except OffsetValueError as exc:
        report(exc)
        if opts.debug_mode:
            raise exc
        sys.exit(1)
Beispiel #48
0
def main():
    """Launcher for the CLI."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options('name')
    opts, args = opt_parser.parse_args(sys.argv[1:])
    event_handler = Reporter(opts.verbosity - opts.quietness)
    suite_vc_cmp = SuiteVCComparator(event_handler)
    suite_name = opts.name
    if not suite_name and args:
        suite_name = args[0]
    if not suite_name:
        suite_name = os.getenv(suite_vc_cmp.suite_engine_proc.SUITE_NAME_ENV)
    if not suite_name:
        opt_parser.print_usage(sys.stderr)
        sys.exit(2)
    try:
        lines = suite_vc_cmp.cmp_source_vc_info(suite_name=suite_name)
    except (StandardError, RosePopenError) as exc:
        event_handler(exc)
        traceback.print_exc()
        sys.exit(2)
    else:
        if lines is None:
            event_handler('%s: rose-suite-run.version: VC info not found' %
                          (suite_name),
                          kind=Reporter.KIND_ERR,
                          level=Reporter.FAIL)
            sys.exit(2)
        lines = list(line for line in lines)
        for line in lines:
            event_handler('%s\n' % line, prefix='')
        if lines:
            sys.exit(1)
        else:
            sys.exit(0)
Beispiel #49
0
def main():
    """Launcher for the CLI."""
    opt_parser = RoseOptionParser()
    option_keys = TaskRunner.OPTIONS
    opt_parser.add_my_options(*option_keys)
    opts, args = opt_parser.parse_args(sys.argv[1:])
    event_handler = Reporter(opts.verbosity - opts.quietness)
    runner = TaskRunner(event_handler)
    try:
        sys.exit(runner(opts, args))
    except Exception as e:
        runner.handle_event(e)
        if opts.debug_mode:
            traceback.print_exc(e)
        if isinstance(e, RosePopenError):
            sys.exit(e.rc)
        else:
            sys.exit(1)
Beispiel #50
0
def main():
    """Implement the "rose suite-id" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("latest", "next", "to_local_copy", "to_origin",
                              "to_output", "to_web")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)
    SuiteId.svn.event_handler = report  # FIXME: ugly?
    arg = None
    if args:
        arg = args[0]

    try:
        if opts.to_origin:
            for arg in args:
                report(str(SuiteId(id_text=arg).to_origin()) + "\n", level=0)
        elif opts.to_local_copy:
            for arg in args:
                report(str(SuiteId(id_text=arg).to_local_copy()) + "\n",
                       level=0)
        elif opts.to_output:
            for arg in args:
                url = SuiteId(id_text=arg).to_output()
                report(str(url) + "\n", level=0)
        elif opts.to_web:
            for arg in args:
                report(str(SuiteId(id_text=arg).to_web()) + "\n", level=0)
        elif opts.latest:
            suite_id = SuiteId.get_latest(prefix=arg)
            if suite_id is not None:
                report(str(suite_id) + "\n", level=0)
        elif opts.next:
            suite_id = SuiteId.get_next(prefix=arg)
            if suite_id is not None:
                report(str(suite_id) + "\n", level=0)
        else:
            if not arg:
                arg = os.getcwd()
            report(str(SuiteId(location=arg)) + "\n", level=0)
    except (NoSuiteLogError, SuiteIdError) as exc:
        report(exc)
        if opts.debug_mode:
            traceback.print_exc(exc)
        sys.exit(1)
Beispiel #51
0
Datei: vc.py Projekt: kaday/rose
def checkout(argv):
    """CLI function: checkout."""
    opt_parser = RoseOptionParser().add_my_options("force_mode")
    opts, args = opt_parser.parse_args(argv)
    verbosity = opts.verbosity - opts.quietness
    report = Reporter(verbosity)
    client = RosieVCClient(event_handler=report, force_mode=opts.force_mode)
    SuiteId.svn.event_handler = client.event_handler
    ret_code = 0
    for arg in args:
        try:
            client.checkout(arg)
        except (FileExistError, RosePopenError, SuiteIdPrefixError) as exc:
            ret_code = 1
            report(exc)
            if not opts.force_mode:
                sys.exit(1)
    if ret_code:
        sys.exit(ret_code)
Beispiel #52
0
def delete(argv):
    """CLI function: delete."""
    opt_parser = RoseOptionParser().add_my_options("force_mode",
                                                   "non_interactive",
                                                   "local_only")
    opts, args = opt_parser.parse_args(argv)
    report = Reporter(opts.verbosity - opts.quietness)
    client = RosieVCClient(event_handler=report, force_mode=opts.force_mode)
    SuiteId.svn.event_handler = client.event_handler # FIXME
    if not args:
        args.append(SuiteId(location=os.getcwd()))
    interactive_mode = not opts.non_interactive
    prompt = ("%s: delete local+repository copies? " +
              "y/n/a (default n, a=yes-to-all) ")
    if opts.local_only:
        prompt = "%s: delete local copy? y/n/a (default n, a=yes-to-all) "
    rc = 0
    for arg in args:
        if interactive_mode:
            try:
                response = raw_input(prompt % arg)
            except EOFError:
                rc = 1
                continue
            if response == 'a':
                interactive_mode = False
            elif response != 'y':
                rc = 1
                continue
        if opts.debug_mode:
            client.delete(arg, opts.local_only)
        else:
            try:
                client.delete(arg, opts.local_only)
            except (LocalCopyStatusError, RosePopenError,
                    SuiteIdPrefixError) as e:
                client.event_handler(e)
                rc = 1
                if not opts.force_mode:
                    sys.exit(1)
    if rc:
        sys.exit(rc)
Beispiel #53
0
def main():
    """Implement the "rose host-select" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("choice", "rank_method", "thresholds", "timeout")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)
    popen = RosePopener(event_handler=report)
    select = HostSelector(event_handler=report, popen=popen)
    try:
        host_score_list = select(names=args,
                                 rank_method=opts.rank_method,
                                 thresholds=opts.thresholds,
                                 ssh_cmd_timeout=opts.timeout)
    except (NoHostError, NoHostSelectError) as exc:
        report(exc)
        if opts.debug_mode:
            traceback.print_exc(exc)
        sys.exit(1)
    opts.choice = int(opts.choice)
    report(choice(host_score_list[0:opts.choice])[0] + "\n", level=0)
Beispiel #54
0
Datei: vc.py Projekt: kaday/rose
def delete(argv):
    """CLI function: delete."""
    opt_parser = RoseOptionParser().add_my_options("force_mode",
                                                   "non_interactive",
                                                   "local_only")
    opts, args = opt_parser.parse_args(argv)
    report = Reporter(opts.verbosity - opts.quietness)
    client = RosieVCClient(event_handler=report, force_mode=opts.force_mode)
    SuiteId.svn.event_handler = client.event_handler
    if not args:
        args.append(SuiteId(location=os.getcwd()))
    interactive_mode = not opts.non_interactive
    prompt = PROMPT_DELETE
    if opts.local_only:
        prompt = PROMPT_DELETE_LOCAL
    ret_code = 0
    for arg in args:
        if interactive_mode:
            try:
                response = raw_input(prompt % arg)
            except EOFError:
                ret_code = 1
                continue
            if response == YES_TO_ALL:
                interactive_mode = False
            elif response != YES:
                ret_code = 1
                continue
        if opts.debug_mode:
            client.delete(arg, opts.local_only)
        else:
            try:
                client.delete(arg, opts.local_only)
            except (LocalCopyStatusError, RosePopenError,
                    SuiteIdPrefixError) as exc:
                client.event_handler(exc)
                ret_code = 1
                if not opts.force_mode:
                    sys.exit(1)
    if ret_code:
        sys.exit(ret_code)
Beispiel #55
0
def main():
    """Launcher for the CLI."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("gcontrol_mode", "host", "name")
    opts, args = opt_parser.parse_args(sys.argv[1:])
    event_handler = Reporter(opts.verbosity - opts.quietness)
    suite_restarter = SuiteRestarter(event_handler)
    try:
        sys.exit(
            suite_restarter.restart(suite_name=opts.name,
                                    host=opts.host,
                                    gcontrol_mode=opts.gcontrol_mode,
                                    args=args))
    except Exception as exc:
        event_handler(exc)
        if opts.debug_mode:
            traceback.print_exc(exc)
        if isinstance(exc, RosePopenError):
            sys.exit(exc.rc)
        else:
            sys.exit(1)
Beispiel #56
0
def main():
    """Implement "rose suite-gcontrol" and "rose suite-shutdown"."""
    argv = sys.argv[1:]
    method_name = argv.pop(0)
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("all", "host", "name", "non_interactive")
    opts, args = opt_parser.parse_args(argv)
    event_handler = Reporter(opts.verbosity - opts.quietness)
    suite_control = SuiteControl(event_handler=event_handler)
    method = getattr(suite_control, method_name)
    confirm = None
    suite_names = []
    if not opts.non_interactive:
        confirm = prompt
    if opts.all:
        suite_scanner = SuiteScanner(event_handler=event_handler)
        results, exceptions = suite_scanner.scan()
        suite_names = [result.name for result in results]
    else:
        if opts.name:
            suite_names.append(opts.name)
        else:
            try:
                suite_name = get_suite_name(event_handler)
                suite_names.append(suite_name)
            except SuiteNotFoundError as e:
                event_handler(e)
                sys.exit(1)

    if opts.debug_mode:
        for sname in suite_names:
            method(sname, opts.host, confirm, sys.stderr, sys.stdout, *args)
    else:
        for sname in suite_names:
            try:
                method(sname, opts.host, confirm, sys.stderr, sys.stdout,
                       *args)
            except Exception as e:
                event_handler(e)
                sys.exit(1)
Beispiel #57
0
def main():
    """rosa db-create."""
    db_conf = ResourceLocator.default().get_conf().get(["rosie-db"])
    if db_conf is not None:
        opts = RoseOptionParser().parse_args()[0]
        reporter = Reporter(opts.verbosity - opts.quietness)
        init = RosieDatabaseInitiator(event_handler=reporter)
        conf = ResourceLocator.default().get_conf()
        for key in db_conf.value:
            if key.startswith("db."):
                prefix = key.replace("db.", "", 1)
                db_url = conf.get_value(["rosie-db", "db." + prefix])
                repos_path = conf.get_value(["rosie-db", "repos." + prefix])
                init(db_url, repos_path)
Beispiel #58
0
def main():
    """Implement the "rose suite-clean" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("name", "non_interactive", "only_items")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)
    cleaner = SuiteRunCleaner(event_handler=report)
    if opts.name:
        args.append(opts.name)
    if not args:
        args = [os.path.basename(os.getcwd())]
    os.chdir(os.path.expanduser('~'))
    n_done = 0
    for arg in args:
        if not opts.non_interactive:
            try:
                answer = raw_input("Clean %s? y/n (default n) " % arg)
            except EOFError:
                sys.exit(1)
            if answer not in ["Y", "y"]:
                continue
        try:
            cleaner.clean(arg, opts.only_items)
        except (
                OSError,
                IOError,
                ConfigSyntaxError,
                RosePopenError,
                SuiteStillRunningError,
        ) as exc:
            report(exc)
            if opts.debug_mode:
                traceback.print_exc(exc)
        else:
            n_done += 1
    sys.exit(len(args) - n_done)  # Return 0 if everything done
Beispiel #59
0
def main():
    """Implement the "rose config" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("default", "env_var_process_mode", "files",
                              "keys", "meta", "meta_key", "no_ignore",
                              "no_opts", "print_conf_mode")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)

    rose.macro.add_meta_paths()

    if opts.meta_key:
        opts.meta = True

    if opts.files and opts.meta_key:
        report(Exception("Cannot specify both a file and meta key."))
        sys.exit(1)

    config_loader = ConfigLoader()
    sources = []
    if opts.files:
        root_node = ConfigNode()
        for fname in opts.files:
            if fname == "-":
                sources.append(sys.stdin)
            else:
                if opts.meta:
                    try:
                        root_node = config_loader.load(fname)
                    except ConfigSyntaxError as exc:
                        report(exc)
                        sys.exit(1)
                    rel_path = os.sep.join(fname.split(os.sep)[:-1])
                    fpath = get_meta_path(root_node, rel_path)
                    if fpath is None:
                        report(MetadataNotFoundEvent(fname))
                    else:
                        sources.append(fpath)
                else:
                    sources.append(fname)
    elif opts.meta:
        root_node = ConfigNode()
        if opts.meta_key:
            root_node.set(["meta"], opts.meta_key)
        else:
            fname = os.path.join(os.getcwd(), rose.SUB_CONFIG_NAME)
            try:
                root_node = config_loader.load(fname)
            except ConfigSyntaxError as exc:
                report(exc)
                sys.exit(1)
        fpath = get_meta_path(root_node, meta_key=opts.meta_key)
        root_node.unset(["meta"])
        if fpath is None:
            report(Exception("Metadata not found"))
            sys.exit(1)
        else:
            sources.append(fpath)
    else:
        root_node = ResourceLocator.default().get_conf()

    for source in sources:
        try:
            if opts.meta or opts.no_opts:
                config_loader.load(source, root_node)
            else:
                config_loader.load_with_opts(source, root_node)
        except (ConfigSyntaxError, IOError) as exc:
            report(exc)
            sys.exit(1)
        if source is sys.stdin:
            source.close()

    if opts.quietness:
        sys.exit(root_node.get(args, opts.no_ignore) is None)

    if opts.keys_mode:
        try:
            keys = root_node.get(args, opts.no_ignore).value.keys()
        except AttributeError:
            sys.exit(1)
        keys.sort()
        for key in keys:
            print key
        sys.exit()

    conf_dump = ConfigDumper()
    if len(args) == 0:
        conf_dump(root_node, concat_mode=opts.print_conf_mode)
        sys.exit()

    node = root_node.get(args, opts.no_ignore)

    if node is not None and isinstance(node.value, dict):
        if opts.print_conf_mode:
            conf_dump(ConfigNode().set(args, node.value), concat_mode=True)
            sys.exit()

        keys = node.value.keys()
        keys.sort()
        for key in keys:
            node_of_key = node.get([key], opts.no_ignore)
            if node_of_key:
                value = node_of_key.value
                state = node_of_key.state
                string = "%s%s=%s" % (state, key, value)
                lines = string.splitlines()
                print lines[0]
                i_equal = len(state + key) + 1
                for line in lines[1:]:
                    print " " * i_equal + line
        sys.exit()

    if node is None:
        if opts.default is None:
            sys.exit(1)
        value = opts.default
    elif opts.env_var_process_mode:
        value = env_var_process(node.value)
    else:
        value = node.value
    if opts.print_conf_mode:
        conf_dump(ConfigNode().set(args, value), concat_mode=True)
    else:
        print value
    sys.exit()
Beispiel #60
0
Datei: vc.py Projekt: kaday/rose
def create(argv):
    """CLI function: create and copy."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("checkout_mode", "info_file", "meta_suite_mode",
                              "non_interactive", "prefix", "project")
    opts, args = opt_parser.parse_args(argv)
    verbosity = opts.verbosity - opts.quietness
    client = RosieVCClient(event_handler=Reporter(verbosity))
    SuiteId.svn.event_handler = client.event_handler
    from_id = None
    if args:
        from_id = SuiteId(id_text=args[0])
        if from_id.branch is None:
            from_id.branch = from_id.BRANCH_TRUNK
        if from_id.revision is None:
            from_id.revision = from_id.REV_HEAD
            from_id = SuiteId(id_text=from_id.to_string_with_version())
    interactive_mode = not opts.non_interactive
    if opts.info_file is None:
        info_config = client.generate_info_config(from_id, opts.prefix,
                                                  opts.project)
        if from_id is not None:
            meta_config = load_meta_config(info_config,
                                           directory=None,
                                           config_type=rose.INFO_CONFIG_NAME,
                                           error_handler=None,
                                           ignore_meta_error=False)
            for node_keys, node in meta_config.walk(no_ignore=True):
                if isinstance(node.value, dict):
                    continue
                sect, key = node_keys
                value = node.value
                sect = sect.translate(None, "=")
                if key == "copy-mode" and value == "clear":
                    info_config.set([sect], "")
                if key == "copy-mode" and value == "never":
                    info_config.unset([sect])
        info_config = _edit_info_config(opts, client, info_config)
    else:
        file_ = opts.info_file
        if opts.info_file == "-":
            file_ = sys.stdin
        info_config = rose.config.load(file_)
    info_config = _validate_info_config(opts, client, info_config)
    if interactive_mode:
        prefix = opts.prefix
        if from_id:
            if not prefix:
                prefix = from_id.prefix
            question = PROMPT_COPY % (from_id.to_string_with_version(), prefix)
        else:
            if not prefix:
                prefix = SuiteId.get_prefix_default()
            question = PROMPT_CREATE % prefix
        try:
            response = raw_input(question)
        except EOFError:
            sys.exit(1)
        if response != YES:
            sys.exit(1)
    try:
        id_ = client.create(info_config, from_id, opts.prefix,
                            opts.meta_suite_mode)
    except (RosePopenError, SuiteIdOverflowError) as exc:
        client.event_handler(exc)
        sys.exit(1)
    if opts.checkout_mode:
        try:
            client.checkout(id_)
        except (FileExistError, RosePopenError) as exc:
            client.event_handler(exc)
            sys.exit(1)