From bca42fd6639449ac0113aa6c28d8d9083648de48 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Tue, 9 Jan 2024 12:38:15 +0100 Subject: [PATCH] Formatted --- a38tool | 85 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/a38tool b/a38tool index be290c2..7c0fc05 100755 --- a/a38tool +++ b/a38tool @@ -47,6 +47,7 @@ class Diff(App): """ show the difference between two fatture """ + NAME = "diff" def __init__(self, args): @@ -65,6 +66,7 @@ class Diff(App): first = self.load_fattura(self.first) second = self.load_fattura(self.second) from a38.diff import Diff + res = Diff() first.diff(res, second) if res.differences: @@ -77,6 +79,7 @@ class Validate(App): """ validate the contents of a fattura """ + NAME = "validate" def __init__(self, args): @@ -92,6 +95,7 @@ class Validate(App): def run(self): f = self.load_fattura(self.pathname) from a38.validation import Validation + res = Validation() f.validate(res) if res.warnings: @@ -114,7 +118,9 @@ class Exporter(App): """ Instantiate the output codec to use for this exporter """ - raise NotImplementedError(f"{self.__class__.__name__}.get_codec is not implemented") + raise NotImplementedError( + f"{self.__class__.__name__}.get_codec is not implemented" + ) def write(self, f: models.Model, file: Union[TextIO, BinaryIO]): self.codec.write_file(f, file) @@ -139,7 +145,9 @@ class Exporter(App): @classmethod def add_subparser(cls, subparsers): parser = super().add_subparser(subparsers) - parser.add_argument("-o", "--output", help="output file (default: standard output)") + parser.add_argument( + "-o", "--output", help="output file (default: standard output)" + ) parser.add_argument("files", nargs="+", help="input files (.xml or .xml.p7m)") return parser @@ -148,6 +156,7 @@ class ExportJSON(Exporter): """ output a fattura in JSON """ + NAME = "json" def get_codec(self) -> codec.Codec: @@ -164,8 +173,11 @@ class ExportJSON(Exporter): @classmethod def add_subparser(cls, subparsers): parser = super().add_subparser(subparsers) - parser.add_argument("--indent", default="1", - help="indentation space (default: 1, use 'no' for all in one line)") + parser.add_argument( + "--indent", + default="1", + help="indentation space (default: 1, use 'no' for all in one line)", + ) return parser @@ -173,6 +185,7 @@ class ExportYAML(Exporter): """ output a fattura in JSON """ + NAME = "yaml" def get_codec(self) -> codec.Codec: @@ -183,6 +196,7 @@ class ExportXML(Exporter): """ output a fattura in XML """ + NAME = "xml" def get_codec(self) -> codec.Codec: @@ -193,6 +207,7 @@ class ExportPython(Exporter): """ output a fattura as Python code """ + NAME = "python" def get_codec(self) -> codec.Codec: @@ -205,10 +220,16 @@ class ExportPython(Exporter): @classmethod def add_subparser(cls, subparsers): parser = super().add_subparser(subparsers) - parser.add_argument("--namespace", default=None, - help="namespace to use for the model classes (default: the module fully qualified name)") - parser.add_argument("--unformatted", action="store_true", - help="disable code formatting, outputting a single-line statement") + parser.add_argument( + "--namespace", + default=None, + help="namespace to use for the model classes (default: the module fully qualified name)", + ) + parser.add_argument( + "--unformatted", + action="store_true", + help="disable code formatting, outputting a single-line statement", + ) return parser @@ -216,6 +237,7 @@ class Edit(App): """ Open a fattura for modification in a text editor """ + def __init__(self, args): super().__init__(args) if self.args.style == "yaml": @@ -250,8 +272,12 @@ class Edit(App): @classmethod def add_subparser(cls, subparsers): parser = super().add_subparser(subparsers) - parser.add_argument("-s", "--style", default="yaml", - help="editable representation to use, one of 'yaml' or 'python'. Default: $(default)s") + parser.add_argument( + "-s", + "--style", + default="yaml", + help="editable representation to use, one of 'yaml' or 'python'. Default: $(default)s", + ) parser.add_argument("file", help="file to edit") return parser @@ -263,6 +289,7 @@ class Renderer(App): def __init__(self, args): from a38.render import HAVE_LXML + if not HAVE_LXML: raise Fail("python3-lxml is needed for XSLT based rendering") @@ -273,13 +300,16 @@ class Renderer(App): self.force = args.force from a38.render import XSLTTransform + self.transform = XSLTTransform(self.stylesheet) def render(self, f, output: str): """ Render the Fattura to the given destination file """ - raise NotImplementedError(self.__class__.__name__ + ".render is not implemented") + raise NotImplementedError( + self.__class__.__name__ + ".render is not implemented" + ) def run(self): for pathname in self.files: @@ -288,7 +318,9 @@ class Renderer(App): basename, ext = os.path.splitext(basename) output = self.output.format(dirname=dirname, basename=basename, ext=ext) if not self.force and os.path.exists(output): - log.warning("%s: output file %s already exists: skipped", pathname, output) + log.warning( + "%s: output file %s already exists: skipped", pathname, output + ) else: log.info("%s: writing %s", pathname, output) f = self.load_fattura(pathname) @@ -297,14 +329,21 @@ class Renderer(App): @classmethod def add_subparser(cls, subparsers): parser = super().add_subparser(subparsers) - parser.add_argument("-f", "--force", action="store_true", help="overwrite existing output files") + parser.add_argument( + "-f", "--force", action="store_true", help="overwrite existing output files" + ) default_output = "{dirname}/{basename}{ext}." + cls.NAME - parser.add_argument("-o", "--output", - default=default_output, - help="output file; use {dirname} for the source file path," - " {basename} for the source file name" - " (default: '" + default_output + "'") - parser.add_argument("stylesheet", help=".xsl/.xslt stylesheet file to use for rendering") + parser.add_argument( + "-o", + "--output", + default=default_output, + help="output file; use {dirname} for the source file path," + " {basename} for the source file name" + " (default: '" + default_output + "'", + ) + parser.add_argument( + "stylesheet", help=".xsl/.xslt stylesheet file to use for rendering" + ) parser.add_argument("files", nargs="+", help="input files (.xml or .xml.p7m)") return parser @@ -313,6 +352,7 @@ class RenderHTML(Renderer): """ render a Fattura as HTML using a .xslt stylesheet """ + NAME = "html" def render(self, f, output): @@ -324,6 +364,7 @@ class RenderPDF(Renderer): """ render a Fattura as PDF using a .xslt stylesheet """ + NAME = "pdf" def __init__(self, args): @@ -341,6 +382,7 @@ class UpdateCAPath(App): create/update an openssl CApath with CA certificates that can be used to validate digital signatures """ + NAME = "update_capath" def __init__(self, args): @@ -352,11 +394,14 @@ class UpdateCAPath(App): def add_subparser(cls, subparsers): parser = super().add_subparser(subparsers) parser.add_argument("destdir", help="CA certificate directory to update") - parser.add_argument("--remove-old", action="store_true", help="remove old certificates") + parser.add_argument( + "--remove-old", action="store_true", help="remove old certificates" + ) return parser def run(self): from a38 import trustedlist as tl + tl.update_capath(self.destdir, remove_old=self.remove_old)