libraries.archive_manager.archive_manager
ct
functools
io
os
Optional
Union
glasswall
dft
utils
log
errors
successes
Library
ArchiveManager Objects
class ArchiveManager(Library)
A high level Python wrapper for Glasswall Archive Manager.
__init__
def __init__(library_path)
version
def version()
Returns the Glasswall library version.
Returns:
versionstr - The Glasswall library version.
release
def release()
Releases any resources held by the Glasswall Archive Manager library.
supported_archives
@property
@functools.lru_cache()
def supported_archives()
Returns a list of supported archive file formats.
is_supported_archive
@functools.lru_cache()
def is_supported_archive(archive_type: str)
Returns True if the archive type (e.g. 7z) is supported.
list_archive_paths
def list_archive_paths(directory: str,
recursive: bool = True,
absolute: bool = True,
followlinks: bool = True)
Returns a list of file paths of supported archives in a directory and all of its subdirectories.
determine_file_type
def determine_file_type(input_file: str,
as_string: bool = False,
raise_unsupported: bool = True)
Returns an int representing the file type of an archive.
Arguments:
input_file (str) The input file path.
as_stringbool, optional - Return file type as string, eg: "xz" instead of: 262. Defaults to False.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
file_typeUnion[int, str] - The file format.
analyse_archive
def analyse_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Extracts the input_file archive and processes each file within the archive using the Glasswall engine. Repackages all files regenerated by the Glasswall engine into a new archive, optionally writing the new archive and report to the paths specified by output_file and output_report.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.output_fileOptional[str], optional - Default None. If str, write the archive to the output_file path.output_reportOptional[str], optional - Default None. If str, write the analysis report to the output_report path.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
gw_return_objectglasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)
analyse_directory
def analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Calls analyse_archive on each file in input_directory using the given content management configuration. The resulting archives and analysis reports are written to output_directory maintaining the same directory structure as input_directory.
Arguments:
input_directorystr - The input directory containing archives to analyse.output_directoryOptional[str], optional - Default None. If str, the output directory where the archives containing analysis reports of each file will be written.output_report_directoryOptional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
analysed_archives_dictdict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)
protect_archive
def protect_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Extracts the input_file archive and processes each file within the archive using the Glasswall engine. Repackages all files regenerated by the Glasswall engine into a new archive, optionally writing the new archive and report to the paths specified by output_file and output_report.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.output_fileOptional[str], optional - Default None. If str, write the archive to the output_file path.output_reportOptional[str], optional - Default None. If str, write the analysis report to the output_report path.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
gw_return_objectglasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)
protect_directory
def protect_directory(
input_directory: str,
output_directory: Optional[str] = None,
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Calls protect_archive on each file in input_directory using the given content management configuration. The resulting archives are written to output_directory maintaining the same directory structure as input_directory.
Arguments:
input_directorystr - The input directory containing archives to protect.output_directoryOptional[str], optional - Default None. If str, the output directory where the archives will be written.output_report_directoryOptional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
protected_archives_dictdict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)
file_to_file_unpack
def file_to_file_unpack(input_file: str,
output_directory: str,
raise_unsupported: bool = True)
file_to_file_pack
def file_to_file_pack(input_directory: str,
output_directory: str,
file_type: Optional[str] = None,
add_extension: Optional[bool] = True,
raise_unsupported: Optional[bool] = True)
unpack
def unpack(input_file: str,
output_directory: str,
recursive: bool = True,
include_file_type: bool = False,
raise_unsupported: bool = True,
delete_origin: bool = False)
Unpack an archive, maintaining directory structure. Supported archive formats are: "7z", "bz2", "gz", "rar", "tar", "xz", "zip".
Arguments:
input_filestr - The archive file pathoutput_directorystr - The output directory where the archive will be unpacked to a new directory.recursivebool, optional - Default True. Recursively unpack all nested archives.include_file_typebool, optional - Default False. Include the archive format in the directory name. Useful when there are multiple same-named archives of different formats.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.delete_originbool, optional - Default False. Delete input_file after unpacking to output_directory.
unpack_directory
def unpack_directory(input_directory: str,
output_directory: str,
recursive: bool = True,
include_file_type: Optional[bool] = False,
raise_unsupported: bool = True,
delete_origin: bool = False)
Unpack a directory of archives, maintaining directory structure.
Arguments:
input_directorystr - The input directory containing archives to unpack.output_directorystr - The output directory where archives will be unpacked to a new directory.recursivebool, optional - Default True. Recursively unpack all nested archives.include_file_typebool, optional - Default False. Include the archive format in the directory name. Useful when there are multiple same-named archives of different formats.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.delete_originbool, optional - Default False. Delete input_file after unpacking to output_directory.
pack_directory
def pack_directory(input_directory: str,
output_directory: str,
file_type: str,
add_extension: Optional[bool] = True,
raise_unsupported: Optional[bool] = True,
delete_origin: Optional[bool] = False)
Pack a directory. Supported archive formats are: "7z", "bz2", "gz", "rar", "tar", "xz", "zip".
Arguments:
input_directorystr - The input directory containing files to archive.output_directorystr - The output directory to store the created archive.file_typestr - The archive file type.add_extensionbool, optional - Default: True. Archive file type extension to result file.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.delete_originbool, optional - Default False. Delete input_directory after packing to output_directory.
export_archive
def export_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Exports an archive using the Glasswall engine.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.output_fileOptional[str], optional - Default None. If str, write the archive to the output_file path.output_reportOptional[str], optional - Default None. If str, write the analysis report to the output_report path.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
gw_return_objectglasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)
export_directory
def export_directory(
input_directory: str,
output_directory: Optional[str],
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)
Calls export_archive on each file in input_directory. The exported archives are written to output_directory maintaining the same directory structure as input_directory.
Arguments:
input_directorystr - The input directory containing archives to export.output_directoryOptional[str], optional - Default None. If str, the output directory where the archives will be written.output_report_directoryOptional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
exported_archives_dictdict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)
import_archive
def import_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
include_analysis_report: Optional[bool] = False,
raise_unsupported: Optional[bool] = True)
Imports an archive using the Glasswall engine.
Arguments:
input_fileUnion[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.output_fileOptional[str], optional - Default None. If str, write the archive to the output_file path.output_reportOptional[str], optional - Default None. If str, write the analysis report to the output_report path.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.include_analysis_reportOptional[bool], optional - Default False. If True, write the analysis report into the imported archive.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
gw_return_objectglasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)
import_directory
def import_directory(
input_directory: str,
output_directory: Optional[str],
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
include_analysis_report: Optional[bool] = False,
raise_unsupported: bool = True)
Calls import_archive on each file in input_directory. The imported archives are written to output_directory maintaining the same directory structure as input_directory.
Arguments:
input_directorystr - The input directory containing archives to import.output_directoryOptional[str], optional - Default None. If str, the output directory where the archives will be written.output_report_directoryOptional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.content_management_policyUnion[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.include_analysis_reportOptional[bool], optional - Default False. If True, write the analysis report into the imported archive.raise_unsupportedbool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
Returns:
imported_archives_dictdict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)