<filename>octowire_framework/core/commands/use.py
# Octowire Framework
# Copyright (c) ImmunIT - <NAME> / <NAME>
# License: Apache 2.0
# <NAME> / Eresse <<EMAIL>>
# <NAME> / Ghecko <<EMAIL>>


from octowire.utils.Logger import Logger


def _print_usage(owf_instance):
    """
    Print 'use' command usage.
    :param owf_instance: Octowire framework instance (self).
    :return: Nothing
    """
    owf_instance.logger.handle("Bad usage", Logger.ERROR)
    owf_instance.logger.handle("Usage: use <module_name>", Logger.INFO)


def _check_args(owf_instance, *args):
    """
    Check the length of 'use' command arguments and their validity.
    :param owf_instance: Octowire framework instance (self).
    :param args: Varargs ('use' command arguments).
    :return: bool
    """
    if len(args) < 1:
        _print_usage(owf_instance)
        return False
    if args[0] == "":
        _print_usage(owf_instance)
        return False
    return True


def use(owf_instance, *args):
    """
    Method used to select a specific module.
    :param owf_instance: Octowire framework instance (self).
    :param args: Varargs command options.
    :return: Nothing
    """
    if _check_args(owf_instance, *args):
        for module in owf_instance.modules:
            if module["path"] == args[0]:
                # Check module dependencies
                new_module = module["class"](owf_instance.config)
                if new_module._check_dependencies():
                    # Save current module in the history before switching
                    if owf_instance.current_module is not None and owf_instance.current_module_name != module["path"]:
                        owf_instance.modules_history.append({"path": owf_instance.current_module_name,
                                                             "class": owf_instance.current_module})
                    owf_instance.current_module = new_module
                    owf_instance.current_module_name = module["path"]
                    # Set module option from global option
                    for global_option_name, global_option_value in owf_instance.global_options.items():
                        for module_option_name, module_option in owf_instance.current_module.options.items():
                            if global_option_name.upper() == module_option_name.upper():
                                module_option["Value"] = global_option_value
                    owf_instance.update_completer_options_list()
                    # Update global option completer
                    owf_instance.update_set_global_completer()
                break
        else:
            owf_instance.logger.handle("Module not found", Logger.ERROR)

<filename>octowire_framework/core/commands/use.py
# Octowire Framework
# Copyright (c) ImmunIT - <NAME> / <NAME>
# License: Apache 2.0
# <NAME> / Eresse <<EMAIL>>
# <NAME> / Ghecko <<EMAIL>>


from octowire.utils.Logger import Logger


def _print_usage(owf_instance):
    """
    Print 'use' command usage.
    :param owf_instance: Octowire framework instance (self).
    :return: Nothing
    """
    owf_instance.logger.handle("Bad usage", Logger.ERROR)
    owf_instance.logger.handle("Usage: use <module_name>", Logger.INFO)


def _check_args(owf_instance, *args):
    """
    Check the length of 'use' command arguments and their validity.
    :param owf_instance: Octowire framework instance (self).
    :param args: Varargs ('use' command arguments).
    :return: bool
    """
    if len(args) < 1:
        _print_usage(owf_instance)
        return False
    if args[0] == "":
        _print_usage(owf_instance)
        return False
    return True


def use(owf_instance, *args):
    """
    Method used to select a specific module.
    :param owf_instance: Octowire framework instance (self).
    :param args: Varargs command options.
    :return: Nothing
    """
    if _check_args(owf_instance, *args):
        for module in owf_instance.modules:
            if module["path"] == args[0]:
                # Check module dependencies
                new_module = module["class"](owf_instance.config)
                if new_module._check_dependencies():
                    # Save current module in the history before switching
                    if owf_instance.current_module is not None and owf_instance.current_module_name != module["path"]:
                        owf_instance.modules_history.append({"path": owf_instance.current_module_name,
                                                             "class": owf_instance.current_module})
                    owf_instance.current_module = new_module
                    owf_instance.current_module_name = module["path"]
                    # Set module option from global option
                    for global_option_name, global_option_value in owf_instance.global_options.items():
                        for module_option_name, module_option in owf_instance.current_module.options.items():
                            if global_option_name.upper() == module_option_name.upper():
                                module_option["Value"] = global_option_value
                    owf_instance.update_completer_options_list()
                    # Update global option completer
                    owf_instance.update_set_global_completer()
                break
        else:
            owf_instance.logger.handle("Module not found", Logger.ERROR)

# Octowire Framework # Copyright (c) ImmunIT - <NAME> / <NAME> # License: Apache 2.0 # <NAME> / Eresse <<EMAIL>> # <NAME> / Ghecko <<EMAIL>> Print 'use' command usage.     :param owf_instance: Octowire framework instance (self).     :return: Nothing Check the length of 'use' command arguments and their validity.     :param owf_instance: Octowire framework instance (self).     :param args: Varargs ('use' command arguments).     :return: bool Method used to select a specific module.     :param owf_instance: Octowire framework instance (self).     :param args: Varargs command options.     :return: Nothing # Check module dependencies # Save current module in the history before switching # Set module option from global option # Update global option completer