Skip to content
Open
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
25 changes: 25 additions & 0 deletions openrelik_worker_common/archive_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,28 @@ def extract_archive(input_file: dict, output_folder: str, log_file: str) -> str:
raise RuntimeError("7zip or tar execution error.")

return (command_string, export_folder)

import shutil
import os
Comment on lines +66 to +68
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import shutil
import os

Imports is happening at the top of the file.


def create_archive(input_folder_path: str, archive_path: str, delete_input: bool = False):
"""
Zips the contents of a folder into a .zip archive and (optionally) deletes the original folder.

Args:
input_folder_path (str): Path to the folder to be zipped.
archive_path (str): Path (including filename) where the zip file will be saved.
delete_input (boolean): True if content in folder_path needs to be deleted after archive creation.

Returns:
str: Path to the created zip file.
"""
if not os.path.isdir(input_folder_path):
raise ValueError(f"The folder {input_folder_path} does not exist.")

zip_file = shutil.make_archive(archive_path, 'zip', input_folder_path)

if delete_input:
shutil.rmtree(input_folder_path)

return zip_file