Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions scripts/lavafuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
lava_db = None
lava_db_name = '_lava_artifacts.db'
lava_json_name = '_lava_data.lava'
LAVA_SCHEMA_VERSION = 2


def sanitize_sql_name(name):
Expand Down Expand Up @@ -102,19 +103,20 @@ def get_sql_type(python_type):
return type_map.get(python_type, 'TEXT')


def initialize_lava(input_path, output_path, input_type):
def initialize_lava(input_path, output_path, input_type, profile_filename=None):
'''
Initialize the LAVA data.
Args:
input_path: The path to the input file.
output_path: The path to the output file.
input_type: The type of input file.
selected_artifacts: List of selected artifacts.
profile_filename: The profile file used for module selection, if any.
'''

global lava_data, lava_db

lava_data = {
"lava_schema_version": LAVA_SCHEMA_VERSION,
"parser_info": {
"leapp_name": "VLEAPP",
"leapp_version": vleapp_version,
Expand All @@ -126,6 +128,8 @@ def initialize_lava(input_path, output_path, input_type):
"param_input": input_path,
"param_output": output_path,
"param_type": input_type,
"param_profile": profile_filename,
"profile_used": profile_filename is not None,
"processing_status": "In Progress",
"lava_db_name": lava_db_name,
"modules": [],
Expand Down Expand Up @@ -248,6 +252,7 @@ def lava_process_artifact(
module_info['artifacts'].append(artifact_meta)

artifact = {
"artifact_key": func_name,
"name": artifact_name,
"tablename": sanitized_table_name,
"module": module_name,
Expand Down Expand Up @@ -306,13 +311,14 @@ def lava_process_artifact(
return sanitized_table_name, object_columns, column_map


def lava_add_module(module_name, module_status, file_count=None):
def lava_add_module(module_name, module_status, file_count=None, artifact_name=None):
"""
Adds a module to the global lava_data structure.
Parameters:
module_name (str): The name of the module to be added.
module_status (str): The status of the module (e.g., 'active', 'inactive').
file_count (int, optional): The number of files associated with the module. Defaults to None.
artifact_name (str, optional): The selected artifact name when it differs from the module filename.
Returns:
None
Global Variables:
Expand All @@ -325,6 +331,8 @@ def lava_add_module(module_name, module_status, file_count=None):
"module_name": module_name,
"module_status": module_status
}
if artifact_name is not None:
module["artifact_name"] = artifact_name
if file_count is not None:
module["file_count"] = file_count
lava_data["modules"].append(module)
Expand Down
6 changes: 5 additions & 1 deletion vleapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def main():
out_params = OutputParameters(output_path, custom_output_folder)
Context.set_output_params(out_params)

initialize_lava(input_path, out_params.output_folder_base, extracttype)
initialize_lava(input_path, out_params.output_folder_base, extracttype, profile_filename)

# Record history if enabled
history.record_input_path(input_path)
Expand Down Expand Up @@ -417,15 +417,19 @@ def crunch_artifacts(
except (FileExistsError, FileNotFoundError) as ex:
logfunc('Error creating {} report directory at path {}'.format(plugin.name, category_folder))
logfunc('Error was {}'.format(str(ex)))
lava_add_module(plugin.module_name, "Error", len(files_found), plugin.name)
continue # cannot do work
try:
plugin.method(files_found, category_folder, seeker, wrap_text)
except Exception as ex:
logfunc('Reading {} artifact had errors!'.format(plugin.name))
logfunc('Error was {}'.format(str(ex)))
logfunc('Exception Traceback: {}'.format(traceback.format_exc()))
lava_add_module(plugin.module_name, "Error", len(files_found), plugin.name)
continue # nope
lava_add_module(plugin.module_name, "Complete", len(files_found), plugin.name)
else:
lava_add_module(plugin.module_name, "No files found", 0, plugin.name)
logfunc(f"No file found")
logfunc('{} [{}] artifact completed'.format(plugin.name, plugin.module_name))
parsed_modules += 1
Expand Down
2 changes: 1 addition & 1 deletion vleappGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def process(casedata):
logtext_frame.pack(padx=8, pady=4, expand=True, fill='both')
progress_bar_frame.pack(padx=2, pady=2, ipady=2, fill='x')

initialize_lava(input_path, out_params.output_folder_base, extracttype)
initialize_lava(input_path, out_params.output_folder_base, extracttype, profile_filename)

# Record history if enabled
history.record_input_path(input_path)
Expand Down
Loading