Skip to content

Commit

Permalink
Formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
spanezz committed Jan 9, 2024
1 parent 5cc145c commit bca42fd
Showing 1 changed file with 65 additions and 20 deletions.
85 changes: 65 additions & 20 deletions a38tool
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Diff(App):
"""
show the difference between two fatture
"""

NAME = "diff"

def __init__(self, args):
Expand All @@ -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:
Expand All @@ -77,6 +79,7 @@ class Validate(App):
"""
validate the contents of a fattura
"""

NAME = "validate"

def __init__(self, args):
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -148,6 +156,7 @@ class ExportJSON(Exporter):
"""
output a fattura in JSON
"""

NAME = "json"

def get_codec(self) -> codec.Codec:
Expand All @@ -164,15 +173,19 @@ 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


class ExportYAML(Exporter):
"""
output a fattura in JSON
"""

NAME = "yaml"

def get_codec(self) -> codec.Codec:
Expand All @@ -183,6 +196,7 @@ class ExportXML(Exporter):
"""
output a fattura in XML
"""

NAME = "xml"

def get_codec(self) -> codec.Codec:
Expand All @@ -193,6 +207,7 @@ class ExportPython(Exporter):
"""
output a fattura as Python code
"""

NAME = "python"

def get_codec(self) -> codec.Codec:
Expand All @@ -205,17 +220,24 @@ 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


class Edit(App):
"""
Open a fattura for modification in a text editor
"""

def __init__(self, args):
super().__init__(args)
if self.args.style == "yaml":
Expand Down Expand Up @@ -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

Expand All @@ -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")

Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -313,6 +352,7 @@ class RenderHTML(Renderer):
"""
render a Fattura as HTML using a .xslt stylesheet
"""

NAME = "html"

def render(self, f, output):
Expand All @@ -324,6 +364,7 @@ class RenderPDF(Renderer):
"""
render a Fattura as PDF using a .xslt stylesheet
"""

NAME = "pdf"

def __init__(self, args):
Expand All @@ -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):
Expand All @@ -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)


Expand Down

0 comments on commit bca42fd

Please sign in to comment.