Browse Source

Moved instruction to function. Changed function API. Fixed docstring.

master 3.0.0
Franco Masotti 4 months ago
parent
commit
cececa262c
Signed by: frnmst
GPG Key ID: 24116ED85666780A
  1. 20
      fattura_elettronica_reader/api.py

20
fattura_elettronica_reader/api.py

@ -410,17 +410,23 @@ def patch_invoice_schema_file(invoice_schema_file: str, offending_line: str,
##############################
def create_appdirs(program_name: str):
r"""Create user data and configuration directories.
def create_appdirs(program_name: str, destination_directory: str = '.'):
r"""Create user data, configuration and destination directories.
:param program_name: the name of the software.
:param destination_directory: the output directory for the files.
Defaults to ``.``
:type program_name: str
:type destination_directory: str
:raises: a pathlib or a built-in exception.
:returns: None
:rtype: None
.. note: for security reasons the directories have restrictive perimissions.
"""
pathlib.Path(destination_directory).mkdir(mode=0o700,
parents=True,
exist_ok=True)
pathlib.Path(appdirs.user_data_dir(program_name)).mkdir(mode=0o700,
parents=True,
exist_ok=True)
@ -542,6 +548,8 @@ def assert_data_structure(source: str, file_type: str, data: dict):
raise ValueError
if 'ignore_assets_checksum' not in data:
raise ValueError
if 'destination_directory' not in data:
raise ValueError
if not isinstance(data['patched'], bool):
raise TypeError
if not isinstance(data['configuration_file'], str):
@ -550,6 +558,8 @@ def assert_data_structure(source: str, file_type: str, data: dict):
raise TypeError
if not isinstance(data['ignore_assets_checksum'], bool):
raise TypeError
if not isinstance(data['destination_directory'], str):
raise TypeError
if source == 'invoice':
if 'extract_attachments' not in data:
@ -696,7 +706,7 @@ def pipeline(source: str, file_type: str, data: dict):
:param source: the type of document to be considered.
Choose between ``invoice`` and ``generic``.
:param file_type the type of file to be considered:
:param file_type: the type of file to be considered.
Choose between ``p7m`` and ``plain``, depending on the
source parameter.
:param data: a data structure containing all the fields.
@ -713,7 +723,7 @@ def pipeline(source: str, file_type: str, data: dict):
raise ValueError
project_name = 'fattura_elettronica_reader'
create_appdirs(project_name)
create_appdirs(project_name, data['destination_directory'])
configuration_file = data['configuration_file']
if configuration_file == str():
configuration_file = define_appdirs_user_config_dir_file_path(
@ -721,8 +731,6 @@ def pipeline(source: str, file_type: str, data: dict):
if not pathlib.Path(configuration_file).is_file() or data['write_default_configuration_file']:
write_configuration_file(configuration_file)
pathlib.Path(data['destination_directory']).mkdir(mode=0o700, parents=True, exist_ok=True)
if source != 'NOOP' and file_type != 'NOOP':
config = yaml.load(open(configuration_file, 'r'), Loader=yaml.SafeLoader)

Loading…
Cancel
Save