mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00

Make the Document class always resolve relative input/output file paths, which are usually passed as arguments by users. Previously, resolving relative filepaths was a job left to the instantiators of the Document class. This was error-prone since this conversion must happen in all the places where we instantiated the Document class.
28 lines
693 B
Python
28 lines
693 B
Python
from typing import Optional
|
|
|
|
import click
|
|
|
|
from . import errors
|
|
from .document import Document
|
|
|
|
|
|
@errors.handle_document_errors
|
|
def validate_input_filename(
|
|
ctx: click.Context, param: str, value: Optional[str]
|
|
) -> Optional[str]:
|
|
if value is None:
|
|
return None
|
|
filename = Document.normalize_filename(value)
|
|
Document.validate_input_filename(filename)
|
|
return filename
|
|
|
|
|
|
@errors.handle_document_errors
|
|
def validate_output_filename(
|
|
ctx: click.Context, param: str, value: Optional[str]
|
|
) -> Optional[str]:
|
|
if value is None:
|
|
return None
|
|
filename = Document.normalize_filename(value)
|
|
Document.validate_output_filename(filename)
|
|
return filename
|