From 77f194dac24fe51a1fb41885252bc3bd4f0dfdbd Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 13 Aug 2024 00:36:38 +0100 Subject: [PATCH 1/3] Make output file an explicit argument. (because relying on output-redirection meant that on failure, it still "sucessfully" created a zero-byte output file, which messed up later Make steps) Also update requirements.txt --- cli.py | 26 +++++++++++++------------- requirements.txt | 3 ++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cli.py b/cli.py index 91c8c25..c764fa6 100644 --- a/cli.py +++ b/cli.py @@ -8,28 +8,28 @@ def main(): - """Convert the given Doxygen index.xml to AsciiDoc and print the result.""" + """Convert the given Doxygen index.xml to AsciiDoc and output the result.""" parser = argparse.ArgumentParser() parser.add_argument("-f", "--file", help="The path of the file to convert", default=None) + parser.add_argument("-o", "--output", help="The path of the output file", default=None) parser.add_argument("-c", "--child", help="Is NOT the root index file", default=False, action='store_true') args = parser.parse_args() filename = args.file + output_filename = args.output is_child = args.child - if filename: + if filename and output_filename: xmldir = os.path.dirname(filename) with open(filename, encoding="utf-8") as xml: if is_child: - print( - Node( - BeautifulSoup(xml, "xml").doxygen, xmldir=xmldir - ).to_asciidoc() - ) + result = Node( + BeautifulSoup(xml, "xml").doxygen, xmldir=xmldir + ).to_asciidoc() else: - print( - DoxygenindexNode( - BeautifulSoup(xml, "xml").doxygenindex, xmldir=xmldir - ).to_asciidoc() - ) - + result = DoxygenindexNode( + BeautifulSoup(xml, "xml").doxygenindex, xmldir=xmldir + ).to_asciidoc() + with open(output_filename, "w", encoding="utf-8") as output: + output.write(result) + else: sys.exit(1) diff --git a/requirements.txt b/requirements.txt index 4ba3afa..895defc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ PyYAML -beautifulsoup4 \ No newline at end of file +beautifulsoup4 +lxml From 672e9a920ff59e886b8c1aab6746346d54590f3f Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 13 Aug 2024 08:20:01 +0100 Subject: [PATCH 2/3] Print to STDOUT if output argument not supplied --- cli.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cli.py b/cli.py index c764fa6..f151d29 100644 --- a/cli.py +++ b/cli.py @@ -17,7 +17,7 @@ def main(): filename = args.file output_filename = args.output is_child = args.child - if filename and output_filename: + if filename: xmldir = os.path.dirname(filename) with open(filename, encoding="utf-8") as xml: if is_child: @@ -28,8 +28,11 @@ def main(): result = DoxygenindexNode( BeautifulSoup(xml, "xml").doxygenindex, xmldir=xmldir ).to_asciidoc() - with open(output_filename, "w", encoding="utf-8") as output: - output.write(result) + if output_filename is not None: + with open(output_filename, "w", encoding="utf-8") as output: + output.write(result) + else: + print(result) else: sys.exit(1) From 4bf0bc29b7697dd76325289769ca301b8b18bde3 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 13 Aug 2024 16:25:09 +0100 Subject: [PATCH 3/3] Document new -o flag in README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46af1e6..7182187 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ This project converts doxygen XML output to asciidoc. Allowed args: `-f`: the full path to the file to be converted + +`-o`: the full path the the output file (will print to STDOUT if not specified) + `-c`: process a node other than `doxygenindex` -The following attributes from the XML will be preserved in the generated asciidoc: role, tag, type. \ No newline at end of file +The following attributes from the XML will be preserved in the generated asciidoc: role, tag, type.