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
22 changes: 20 additions & 2 deletions anonyfiles_cli/handlers/anonymize_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,26 @@ def process(
append_timestamp: bool,
force: bool,
):
"""
Traite l'anonymisation d'un fichier en orchestrant les différentes étapes.
"""Launch anonymization for ``input_file``.

Args:
input_file (Path): File to anonymize.
config_path (Optional[Path]): Path to a configuration file.
output (Optional[Path]): Destination for anonymized output.
log_entities (Optional[Path]): CSV file for detected entities.
mapping_output (Optional[Path]): CSV mapping between originals and replacements.
bundle_output (Optional[Path]): Path for the bundle archive.
output_dir (Path): Base output directory for generated files.
dry_run (bool): If ``True`` run without writing files.
csv_no_header (bool): Indicates CSV input has no header row.
has_header_opt (Optional[str]): Explicit CSV header flag ("true"/"false").
exclude_entities (Optional[List[str]]): Entities to exclude from anonymization.
custom_replacements_json (Optional[str]): JSON with custom replacement rules.
append_timestamp (bool): Append run timestamp to file names.
force (bool): Overwrite existing files without confirmation.

Returns:
bool: ``True`` on success, ``False`` otherwise.
"""
run_id = timestamp()
self.console.console.print(f"📂 Anonymisation du fichier : [bold cyan]{input_file.name}[/bold cyan]")
Expand Down
19 changes: 15 additions & 4 deletions anonyfiles_cli/handlers/batch_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,23 @@ def process_directory(
config: Optional[Path],
dry_run: bool,
recursive: bool,
# Passer les options CSV si le batch doit les gérer uniformément
csv_no_header: bool,
csv_no_header: bool, # Passer les options CSV si le batch doit les gérer uniformément
has_header_opt: Optional[str],
):
"""
Traite un répertoire de fichiers en lot.
"""Run anonymization on all files within ``input_dir``.

Args:
input_dir (Path): Directory containing files to anonymize.
pattern (str): Glob pattern used to select files.
output_dir (Optional[Path]): Directory for anonymized files.
config (Optional[Path]): Configuration file applied to all files.
dry_run (bool): If ``True`` simulate anonymization without writing files.
recursive (bool): Search ``input_dir`` recursively.
csv_no_header (bool): Indicates CSV inputs have no header row.
has_header_opt (Optional[str]): Explicit CSV header flag ("true"/"false").

Returns:
None
"""
if not input_dir.exists() or not input_dir.is_dir():
self.console.console.print(
Expand Down
30 changes: 21 additions & 9 deletions anonyfiles_cli/handlers/deanonymize_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,27 @@ class DeanonymizeHandler:
def __init__(self, console: ConsoleDisplay):
self.console = console

def process(self,
input_file: Path,
mapping_csv: Path,
output: Optional[Path],
report: Optional[Path],
dry_run: bool,
permissive: bool):
"""
Traite la désanonymisation d'un fichier en orchestrant les différentes étapes.
def process(
self,
input_file: Path,
mapping_csv: Path,
output: Optional[Path],
report: Optional[Path],
dry_run: bool,
permissive: bool,
):
"""Restore anonymized text using ``mapping_csv``.

Args:
input_file (Path): Text file containing anonymized data.
mapping_csv (Path): CSV mapping produced during anonymization.
output (Optional[Path]): Destination file for restored text.
report (Optional[Path]): JSON report output path.
dry_run (bool): If ``True`` simulate the process without writing files.
permissive (bool): Disable strict validation of mapping coverage.

Returns:
bool: ``True`` on success, ``False`` otherwise.
"""
run_id = timestamp() # Générez le run_id ici pour la désanonymisation aussi
self.console.console.print(f"🔁 Désanonymisation du fichier : [bold cyan]{input_file.name}[/bold cyan]")
Expand Down
24 changes: 19 additions & 5 deletions anonyfiles_cli/handlers/validation_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ def validate_anonymize_inputs(cls,
custom_replacements_json: Optional[str],
csv_no_header: bool,
has_header_opt: Optional[str]):
"""
Valide les entrées communes à la commande d'anonymisation.
Lève ConfigurationError en cas de problème.
"""Validate inputs for anonymization.

Args:
input_file (Path): File provided to the command.
output (Optional[Path]): Optional destination file for anonymized output.
custom_replacements_json (Optional[str]): JSON string containing custom replacement rules.
csv_no_header (bool): Indicates CSV input has no header row.
has_header_opt (Optional[str]): Explicit CSV header flag ("true"/"false").

Raises:
ConfigurationError: If an option is invalid or files are missing.
"""
cls._validate_file_extension(input_file)
cls._validate_csv_options(input_file, csv_no_header, has_header_opt)
Expand All @@ -29,8 +37,14 @@ def validate_anonymize_inputs(cls,
def validate_deanonymize_inputs(cls,
input_file: Path,
mapping_csv: Path):
"""
Valide les entrées communes à la commande de désanonymisation.
"""Validate inputs for deanonymization.

Args:
input_file (Path): Anonymized file to restore.
mapping_csv (Path): Mapping file generated during anonymization.

Raises:
ConfigurationError: If the files are missing or invalid.
"""
if not input_file.exists() or not input_file.is_file():
raise ConfigurationError(f"Le fichier d'entrée '{input_file}' est introuvable ou n'est pas un fichier.")
Expand Down
Loading