From ce98ee9b52071101dc32362c9dded904a9eba8e8 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 1 May 2018 21:38:01 +0200 Subject: [PATCH] Now fully PDF/A-3 compliant with additionnal attachments facturx-pdfgen: don't overwrite by default and add --overwrite option Update version number to 0.6 --- README.rst | 6 ++++++ bin/facturx-pdfgen | 23 ++++++++++++++++------- facturx/_version.py | 2 +- facturx/facturx.py | 5 +++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 8a3a632..330fe48 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,12 @@ Contributors Changelog ========= +* Version 0.6 dated 2018-05-01 + + * Now fully PDF/A-3 compliant with additionnal attachments (tested with veraPDF) + * facturx-pdfgen: don't overwrite by default and add --overwrite option + * Add factur-x library version number in metadata creator entry + * Version 0.5 dated 2018-03-29 * Fix XMP metadata structure diff --git a/bin/facturx-pdfgen b/bin/facturx-pdfgen index 97f72f5..ccab3cd 100755 --- a/bin/facturx-pdfgen +++ b/bin/facturx-pdfgen @@ -10,8 +10,8 @@ import logging from os.path import isfile, isdir __author__ = "Alexis de Lattre " -__date__ = "March 2018" -__version__ = "0.3" +__date__ = "May 2018" +__version__ = "0.4" options = [ {'names': ('-l', '--log-level'), 'dest': 'log_level', @@ -48,6 +48,9 @@ options = [ "Default: generic English subject with information extracted from the " "Factur-X XML file such as: " "'Factur-X invoice I1242 dated 2017-08-17 issued by Akretion'"}, + {'names': ('-w', '--overwrite'), 'dest': 'overwrite', + 'action': 'store_true', 'default': False, + 'help': "Overwrite Factur-X invoice file if it already exists."}, ] @@ -102,14 +105,20 @@ def main(options, arguments): 'title': options.meta_title, 'subject': options.meta_subject, } - # The important line of code is below ! if isfile(facturx_pdf_filename): - logger.warn( - 'File %s already exists. Overwriting it!', facturx_pdf_filename) + if options.overwrite: + logger.warning( + 'File %s already exists. Overwriting it.', + facturx_pdf_filename) + else: + logger.error( + 'File %s already exists. Exit.', facturx_pdf_filename) + sys.exit(1) additional_attachments = {} for additional_attachment_filename in additional_attachment_filenames: additional_attachments[additional_attachment_filename] = '' # desc try: + # The important line of code is below ! generate_facturx_from_file( pdf_filename, xml_file, check_xsd=check_xsd, facturx_level=options.facturx_level, pdf_metadata=pdf_metadata, @@ -128,8 +137,8 @@ if __name__ == '__main__': "metadata only apply if none of the meta-* arguments are used." epilog = "Author: %s\n\nVersion: %s" % (__author__, __version__) description = "This script generate a Factur-X PDF invoice from a "\ - "regular PDF/A invoice and a Factur-X XML file."\ - "It can also include additional embedded files in the PDF."\ + "regular PDF/A invoice and a Factur-X XML file. "\ + "It can also include additional embedded files in the PDF. "\ "To generate a valid PDF/A-3 invoice as requested by the "\ "Factur-X standard, you need to give a valid PDF/A "\ "regular invoice as input." diff --git a/facturx/_version.py b/facturx/_version.py index 5a6f84c..27fda16 100644 --- a/facturx/_version.py +++ b/facturx/_version.py @@ -1 +1 @@ -__version__ = '0.5' +__version__ = '0.6' diff --git a/facturx/facturx.py b/facturx/facturx.py index dfab1c3..c386d64 100644 --- a/facturx/facturx.py +++ b/facturx/facturx.py @@ -410,8 +410,10 @@ def _facturx_update_metadata_add_attachment( sorted(name_arrayobj_cdict.items(), key=lambda x: x[0])) logger.debug('name_arrayobj_content_sort=%s', name_arrayobj_content_sort) name_arrayobj_content_final = [] + af_list = [] for (fname_obj, filespec_obj) in name_arrayobj_content_sort: name_arrayobj_content_final += [fname_obj, filespec_obj] + af_list.append(filespec_obj) embedded_files_names_dict = DictionaryObject({ NameObject("/Names"): ArrayObject(name_arrayobj_content_final), }) @@ -441,8 +443,7 @@ def _facturx_update_metadata_add_attachment( NameObject('/Type'): NameObject('/Metadata'), }) metadata_obj = pdf_filestream._addObject(metadata_file_entry) - af_value_obj = pdf_filestream._addObject( - ArrayObject([filespec_obj])) + af_value_obj = pdf_filestream._addObject(ArrayObject(af_list)) pdf_filestream._root_object.update({ NameObject("/AF"): af_value_obj, NameObject("/Metadata"): metadata_obj,