From 3d125455d302da82ed7ea5478eeafd343bbb3de6 Mon Sep 17 00:00:00 2001 From: Matmaus Date: Mon, 27 Feb 2023 16:43:17 +0100 Subject: [PATCH 1/3] Print document in JSON form if option is set `process_onenote_file` does not print document in JSON if `json_output` parameter is set. Instead, it always returns it. This return value is not even used in the main. This commit fixes use of `json_output` parameter. If `True`, `process_onenote_file` will print document in JSON form instead of the default text form. The default text form will be used otherwise. No value will be returned. --- pyOneNote/Main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyOneNote/Main.py b/pyOneNote/Main.py index c8af2fb..2fec777 100644 --- a/pyOneNote/Main.py +++ b/pyOneNote/Main.py @@ -58,8 +58,8 @@ def process_onenote_file(file, output_dir, extension, json_output): ) as output_file: output_file.write(file["content"]) counter += 1 - - return json.dumps(document.get_json()) + else: + print(json.dumps(data)) def get_hex_format(hex_str, col, indent): From c9c2f7df6445fda9667971ee309a42a2c1f8d468 Mon Sep 17 00:00:00 2001 From: Matmaus Date: Mon, 27 Feb 2023 17:28:42 +0100 Subject: [PATCH 2/3] Fix typo OneDocment -> OneDocument --- pyOneNote/Main.py | 2 +- pyOneNote/OneDocument.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyOneNote/Main.py b/pyOneNote/Main.py index 2fec777..94f119d 100644 --- a/pyOneNote/Main.py +++ b/pyOneNote/Main.py @@ -24,7 +24,7 @@ def process_onenote_file(file, output_dir, extension, json_output): exit() file.seek(0) - document = OneDocment(file) + document = OneDocument(file) data = document.get_json() if not json_output: print('Headers\n####################################################################') diff --git a/pyOneNote/OneDocument.py b/pyOneNote/OneDocument.py index 22d01be..0a6cb54 100644 --- a/pyOneNote/OneDocument.py +++ b/pyOneNote/OneDocument.py @@ -3,7 +3,7 @@ import json -class OneDocment: +class OneDocument: def __init__(self, file): self.header = Header(file) self.root_file_node_list = FileNodeList(file, self.header.fcrFileNodeListRoot) @@ -19,7 +19,7 @@ def traverse_nodes(root_file_node_list, nodes, filters): nodes.append(file_node) for child_file_node_list in file_node.children: - OneDocment.traverse_nodes(child_file_node_list, nodes, filters) + OneDocument.traverse_nodes(child_file_node_list, nodes, filters) def get_properties(self): if self._properties: @@ -29,7 +29,7 @@ def get_properties(self): self._properties = [] - OneDocment.traverse_nodes(self.root_file_node_list, nodes, filters) + OneDocument.traverse_nodes(self.root_file_node_list, nodes, filters) for node in nodes: if hasattr(node, 'propertySet'): node.propertySet.body.indent= '\t\t' @@ -44,7 +44,7 @@ def get_files(self): self._files = {} filters = ["FileDataStoreObjectReferenceFND", "ObjectDeclarationFileData3RefCountFND"] - OneDocment.traverse_nodes(self.root_file_node_list, nodes, filters) + OneDocument.traverse_nodes(self.root_file_node_list, nodes, filters) for node in nodes: if hasattr(node, "data") and node.data: From e363ca651f610f315f0f617f2854f08975a1f0b3 Mon Sep 17 00:00:00 2001 From: Matmaus Date: Mon, 6 Mar 2023 11:44:54 +0100 Subject: [PATCH 3/3] Fix handling of non-existing file --- pyOneNote/Main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyOneNote/Main.py b/pyOneNote/Main.py index 94f119d..3dae144 100644 --- a/pyOneNote/Main.py +++ b/pyOneNote/Main.py @@ -81,7 +81,7 @@ def main(): args = p.parse_args() if not os.path.exists(args.file): - sys.exit("File: %s doesn't exist", args.file) + sys.exit("File: '{}' doesn't exist".format(args.file)) with open(args.file, "rb") as file: process_onenote_file(file, args.output_dir, args.extension, args.json)