From b70be8b4e6ee715d0726208c01580cfa2a5ed317 Mon Sep 17 00:00:00 2001 From: alejandro Date: Wed, 26 Jul 2023 11:21:15 +0200 Subject: [PATCH] describe functions --- .../extras/pandoraPlugintools/agents.py | 13 ++++ .../extras/pandoraPlugintools/discover.py | 70 +++++++++++++++++++ .../extras/pandoraPlugintools/transfer.py | 29 ++++++++ 3 files changed, 112 insertions(+) diff --git a/pandora_server/extras/pandoraPlugintools/agents.py b/pandora_server/extras/pandoraPlugintools/agents.py index f81a407086..e3310f5d72 100644 --- a/pandora_server/extras/pandoraPlugintools/agents.py +++ b/pandora_server/extras/pandoraPlugintools/agents.py @@ -17,6 +17,13 @@ def set_global_variable( variable_name, value ): + """ + Sets the value of a global variable in the 'global_variables' dictionary. + + Args: + variable_name (str): Name of the variable to set. + value (any): Value to assign to the variable. + """ global_variables[variable_name] = value @@ -90,6 +97,12 @@ def write_xml( # Init agent template ########################################### def init_agent() : + """ + Initializes an agent template with default values. + + Returns: + dict: Dictionary representing the agent template with default values. + """ agent = { "agent_name" : "", "agent_alias" : "", diff --git a/pandora_server/extras/pandoraPlugintools/discover.py b/pandora_server/extras/pandoraPlugintools/discover.py index 8d872a3588..2171ef4dae 100644 --- a/pandora_server/extras/pandoraPlugintools/discover.py +++ b/pandora_server/extras/pandoraPlugintools/discover.py @@ -8,6 +8,13 @@ def set_summary_value( key="", value="" ): + """ + Sets a fixed value for a key in the 'summary' dictionary. + + Args: + key (str): Key to set the value for. + value (any): Value to assign to the key. + """ global summary summary[key] = value @@ -19,6 +26,15 @@ def add_summary_value( key="", value="" ): + """ + Adds a value to a key in the 'summary' dictionary. + + If the key already exists, the value will be incremented. Otherwise, a new key will be created. + + Args: + key (str): Key to add the value to. + value (any): Value to add to the key. + """ global summary if key in summary: @@ -32,6 +48,12 @@ def add_summary_value( def set_error_level( value=0 ): + """ + Sets the error level to the specified value. + + Args: + value (int, optional): The error level value. Default is 0. + """ global error_level error_level = value @@ -42,6 +64,12 @@ def set_error_level( def add_info_value( data="" ): + """ + Adds data to the 'info' variable. + + Args: + data (str, optional): The data to add to the 'info' variable. Default is an empty string. + """ global info info += data @@ -52,6 +80,12 @@ def add_info_value( def set_info_value( data="" ): + """ + Sets a fixed value to the 'info' variable. + + Args: + data (str, optional): The value to set in the 'info' variable. Default is an empty string. + """ global info info = data @@ -64,6 +98,17 @@ def parse_parameter( default="", key="" ): + """ + Parses a parameter from the configuration file. + + Args: + config (ConfigParser, optional): The ConfigParser object representing the configuration file. Default is None. + default (any, optional): The default value to return if the parameter is not found. Default is an empty string. + key (str): The key of the parameter to parse. + + Returns: + any: The parsed value of the parameter, or the default value if the parameter is not found. + """ try: return config.get("CONF", key) @@ -76,6 +121,15 @@ def parse_parameter( def parse_conf_entities( entities="" ): + """ + Parses the configuration file credentials. + + Args: + entities (str): A JSON string representing the entities. + + Returns: + list: A list of entities parsed from the JSON string. If parsing fails, an empty list is returned. + """ entities_list = [] try: @@ -96,6 +150,15 @@ def parse_conf_entities( def param_int( param="" ): + """ + Parses a parameter as an integer. + + Args: + param (any): The parameter to be parsed as an integer. + + Returns: + int: The parsed integer value. If parsing fails, returns 0. + """ try: return int(param) except: @@ -105,6 +168,13 @@ def param_int( # Print JSON output and exit script ########################################### def print_output(): + """ + Prints the JSON output and exits the script. + + The function uses the global variables 'output', 'error_level', 'summary', and 'info' + to create the JSON output. It then prints the JSON string and exits the script with + the 'error_level' as the exit code. + """ global output global error_level diff --git a/pandora_server/extras/pandoraPlugintools/transfer.py b/pandora_server/extras/pandoraPlugintools/transfer.py index 5dbce337b2..eab9c10616 100644 --- a/pandora_server/extras/pandoraPlugintools/transfer.py +++ b/pandora_server/extras/pandoraPlugintools/transfer.py @@ -22,6 +22,13 @@ def set_global_variable( variable_name, value ): + """ + Sets the value of a global variable in the 'global_variables' dictionary. + + Args: + variable_name (str): Name of the variable to set. + value (any): Value to assign to the variable. + """ global_variables[variable_name] = value @@ -95,6 +102,16 @@ def agentplugin( tentacle=False, tentacle_conf=None ): + """ + Detects the transfer mode and executes the corresponding action. + + Args: + modules (list): List of modules. + agent (dict): Dictionary with agent configuration. + temp_dir (str, optional): Temporary directory. Default is global_variables['temporal']. + tentacle (bool, optional): Indicates whether to use the Tentacle protocol. Default is False. + tentacle_conf (dict, optional): Dictionary with Tentacle protocol configuration. Default is None. + """ agent_file=print_agent(agent,modules,temp_dir) if agent_file[1] is not None: @@ -114,6 +131,18 @@ def transfer_xml( tentacle_port=global_variables['tentacle_port'], temporal=global_variables['temporal'] ): + + """ + Detects the transfer mode and calls the agentplugin() function to perform the transfer. + + Args: + agent (dict): Dictionary with agent configuration. + modules (list): List of modules. + transfer_mode (str, optional): Transfer mode. Default is global_variables['transfer_mode']. + tentacle_ip (str, optional): IP address for Tentacle. Default is global_variables['tentacle_ip']. + tentacle_port (str, optional): Port for Tentacle. Default is global_variables['tentacle_port']. + temporal (str, optional): Temporary directory. Default is global_variables['temporal']. + """ if transfer_mode != "local" and tentacle_ip is not None: tentacle_conf={"address":tentacle_ip,"port":tentacle_port}