Example #1
0
 def run(self):
     runtime_info = Globals.get_runtime_info()
     print(
         yaml.safe_dump(runtime_info,
                        explicit_start=True,
                        explicit_end=True))
     return 0
Example #2
0
    def test_runtime_info_calling(self):
        """make sure that the --version output can be read back as YAML when API is 201"""
        output = subprocess.check_output(
            [RBBin, b'--version', b'--api-version', b'201'])
        out_info = yaml.safe_load(output)

        Globals.api_version['actual'] = 201
        info = Globals.get_runtime_info()

        # because the current test will have a different call than rdiff-backup itself
        # we can't compare certain keys
        self.assertIn('exec', out_info)
        self.assertIn('argv', out_info['exec'])
        out_info['exec'].pop('argv')
        info['exec'].pop('argv')
        # info['python']['executable'] could also be different but I think that our test
        # environments make sure that it doesn't happen
        self.assertEqual(info, out_info)
Example #3
0
def main_run(arglist, security_override=False):
    """
    Main function to be called with arguments list without the
    name of the program, aka $0 resp. sys.argv[0].

    The security override is only meant for test purposes.

    Returns with an error code depending on the result.
    Check the man-page of the rdiff-backup binary for possible values
    and their meaning.
    """

    # get a dictionary of discovered action plugins
    discovered_actions = actions_mgr.get_actions_dict()

    # parse accordingly the arguments
    parsed_args = arguments.parse(
        arglist, "rdiff-backup {ver}".format(ver=Globals.version),
        actions_mgr.get_generic_parsers(),
        actions_mgr.get_parent_parsers_compat200(),
        discovered_actions)

    # we need verbosity set properly asap
    if parsed_args.terminal_verbosity is not None:
        log.Log.setterm_verbosity(parsed_args.terminal_verbosity)
    log.Log.setverbosity(parsed_args.verbosity)

    # compatibility plug
    _parse_cmdlineoptions_compat200(parsed_args)

    # instantiate the action object from the dictionary, handing over the
    # parsed arguments
    action = discovered_actions[parsed_args.action](parsed_args)

    log.Log("Runtime information =>{ri}<=".format(
        ri=Globals.get_runtime_info(parsed=vars(parsed_args))), log.DEBUG)

    # validate that everything looks good before really starting
    ret_val = action.pre_check()
    if ret_val & Globals.RET_CODE_ERR:
        log.Log("Action {ac} failed on step {st}".format(
            ac=parsed_args.action, st="pre_check"), log.ERROR)
        return ret_val

    # now start for real, conn_act and action are the same object
    with action.connect() as conn_act:

        # For test purposes only, hence we allow ourselves to overwrite a
        # "private" variable
        if security_override:
            from rdiff_backup import Security
            Security._security_level = "override"

        ret_val |= conn_act.check()
        if ret_val & Globals.RET_CODE_ERR:
            log.Log("Action {ac} failed on step {st}".format(
                ac=parsed_args.action, st="check"), log.ERROR)
            return ret_val

        ret_val |= conn_act.setup()
        if ret_val & Globals.RET_CODE_ERR:
            log.Log("Action {ac} failed on step {st}".format(
                ac=parsed_args.action, st="setup"), log.ERROR)
            return ret_val

        ret_val |= conn_act.run()
        if ret_val & Globals.RET_CODE_ERR:
            log.Log("Action {ac} failed on step {st}".format(
                ac=parsed_args.action, st="run"), log.ERROR)
            return ret_val

    # Give a final summary of what might have happened to the user
    if ret_val & Globals.RET_CODE_WARN:
        log.Log("Action {ac} emitted warnings, "
                "see previous messages for details".format(
                    ac=parsed_args.action), log.WARNING)
    if ret_val & Globals.RET_CODE_FILE_ERR:
        log.Log("Action {ac} failed on one or more files, "
                "see previous messages for details".format(
                    ac=parsed_args.action), log.WARNING)
    if ret_val & Globals.RET_CODE_FILE_WARN:
        log.Log("Action {ac} emitted a warning on one or more files, "
                "see previous messages for details".format(
                    ac=parsed_args.action), log.WARNING)

    return ret_val
Example #4
0
def _main_run(arglist, security_override=False):
    """
    Internal main function to be called with arguments list without the
    name of the program, aka $0 resp. sys.argv[0].

    The security override is only meant for test purposes

    The function returns with an error code.
    """

    # get a dictionary of discovered action plugins
    discovered_actions = actions_mgr.get_actions_dict()

    # parse accordingly the arguments
    parsed_args = arguments.parse(
        arglist, "rdiff-backup {ver}".format(ver=Globals.version),
        actions_mgr.get_generic_parsers(),
        actions_mgr.get_parent_parsers_compat200(), discovered_actions)

    # we need verbosity set properly asap
    if parsed_args.terminal_verbosity is not None:
        log.Log.setterm_verbosity(parsed_args.terminal_verbosity)
    log.Log.setverbosity(parsed_args.verbosity)

    # compatibility plug
    _parse_cmdlineoptions_compat200(parsed_args)

    # instantiate the action object from the dictionary, handing over the
    # parsed arguments
    action = discovered_actions[parsed_args.action](parsed_args)

    log.Log(
        "Runtime information =>{ri}<=".format(ri=Globals.get_runtime_info(
            parsed=vars(parsed_args))), log.DEBUG)

    # validate that everything looks good before really starting
    ret_val = action.pre_check()
    if ret_val != 0:
        log.Log(
            "Action {ac} failed on step {st}".format(ac=parsed_args.action,
                                                     st="pre_check"),
            log.ERROR)
        return ret_val

    # now start for real, conn_act and action are the same object
    with action.connect() as conn_act:

        # For test purposes only, hence we allow ourselves to overwrite a
        # "private" variable
        if security_override:
            from rdiff_backup import Security
            Security._security_level = "override"

        ret_val = conn_act.check()
        if ret_val != 0:
            log.Log(
                "Action {ac} failed on step {st}".format(ac=parsed_args.action,
                                                         st="check"),
                log.ERROR)
            return ret_val

        ret_val = conn_act.setup()
        if ret_val != 0:
            log.Log(
                "Action {ac} failed on step {st}".format(ac=parsed_args.action,
                                                         st="setup"),
                log.ERROR)
            return ret_val

        ret_val = conn_act.run()
        if ret_val != 0:
            log.Log(
                "Action {ac} failed on step {st}".format(ac=parsed_args.action,
                                                         st="run"), log.ERROR)
            return ret_val

    return ret_val