Example #1
0
def move_bin(path, options=None):
    """Move Function

    Function allow move bin folder by path with 
    bin history changes.

    Parameters:
        path: where to move.
        options: list of copy politics.

    Returns:
        value: 0 - successful, 1 - fail.

    """
    try:
        # Check if command run in confirm mod and if it's so, ask
        # user about activity confirmation.
        if not confirm_question("Try to move bin to: \n{}\n".format(path),
                                "no", options):
            return 1

        # Check if command run in dry mode and if so skip main management
        # operation and only print info
        if not bin_config_manager.is_dry_mode(options):
            clean_path.move(user_config_manager.get_property('bin_path'),
                            os.path.abspath(path))
            user_config_manager.set_property('bin_path', os.path.abspath(path))

        # Print info about what was done while operation
        get_log().info(INFO_MESSAGES['bin_move'].format(os.path.abspath(path)))
        return 0
    except Exception as e:
        get_log().error(e)
        return 1
Example #2
0
def create_bin(path, options=None):
    """Create Function

        Function allow to create bin in new location with empty bin.
        Previous bin location is not deleter.

        Parameters:
            path: where to create.
            options: list of copy politics.

        Returns:
            value: 0 - successful, 1 - fail.

        """
    try:
        # Check if command run in confirm mod and if it's so, ask
        # user about activity confirmation.
        if not confirm_question("Try to create bin: \n{}\n".format(path),
                                "yes", options):
            return 1

        # Check if command run in dry mode and if so skip main management
        # operation and only print info
        if not bin_config_manager.is_dry_mode(options):
            user_config_manager.set_property('bin_path', os.path.abspath(path))
            bin_config_manager.history_empty()
            os.mkdir(user_config_manager.get_property('bin_path'))

        # Print info about what was done while operation
        get_log().info(INFO_MESSAGES['bin_create'].format(
            os.path.abspath(path)))
        return 0
    except Exception as e:
        get_log().error(e)
        return 1
Example #3
0
def empty_bin(options=None):
    """Copy Function

    Function allow to empty bin folder and history too.

    Parameters:
        options: list of copy politics.

    Returns:
        value: 0 - successful, 1 - fail.

    """
    try:
        # Check if command run in confirm mod and if it's so, ask
        # user about activity confirmation.
        if not confirm_question("Try to empty bin: \n{}\n", "no", options):
            return 1

        # Check if command run in dry mode and if so skip main management
        # operation and only print info
        if not bin_config_manager.is_dry_mode(options):
            history_items = bin_config_manager.get_property('history')
            # Go through over every single history item and
            # delete it from history and from actual bin folder
            for history_item in history_items:
                bin_config_manager.history_del(history_item['bin_name'])
                clean_path.delete(
                    os.path.join(user_config_manager.get_property('bin_path'),
                                 history_item['bin_name']))
                get_log().info(INFO_MESSAGES['progress_del'].format(
                    ascii_bar.get_progress_bar(
                        history_items.index(history_item) + 1,
                        len(history_items)),
                    history_item['bin_name'],
                ))

        # Print info about what was done while operation
        get_log().info(INFO_MESSAGES['bin_empty'])
        return 0
    except Exception as e:
        get_log().error(e)
        return 1
Example #4
0
def restore(paths, options=None):
    """Restore Function

    Function allow to restore file/dirs by paths
    in different mods.

    Parameters:
        paths: what to restore.
        options: list of restore politics.

    Returns:
        value: 0 - successful, 1 - fail.

    """
    try:
        restore_paths = _get_restore_paths(paths, options)

        # Check if command run in confirm mod and if it's so, ask
        # user about activity confirmation.
        if not confirm_question(
            "Try to restore: \n{}\n".format(
                "\n".join(map(lambda x: '--' + x, restore_paths))
            ),
            "no", options
        ):
            return 1

        # Check if command run in dry mode and if so skip main management
        # operation and only print info
        if not bin_config_manager.is_dry_mode(options):
            _move_from_bin(restore_paths, options)

        # Print info about what was done while operation
        get_log().info(
            INFO_MESSAGES['restore'].format('\n '.join(restore_paths))
        )

        return 0
    except Exception as e:
        get_log().error(e)
        return 1