This is an automated email from the ASF dual-hosted git repository. sebb pushed a commit to branch drydump in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
commit 9e6dfefa7497b7770db114ab30bd28092f15fe85 Author: Sebb <s...@apache.org> AuthorDate: Fri Apr 26 00:04:56 2024 +0100 Allow dump with dryrun --- tools/archiver.py | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tools/archiver.py b/tools/archiver.py index 2feb887..519f1cb 100755 --- a/tools/archiver.py +++ b/tools/archiver.py @@ -645,6 +645,28 @@ class Archiver(object): # N.B. Also used by import-mbox.py return output_json, contents, msg_metadata, irt, False + def dump_message(self, dump, ojson, msg_metadata, raw_message, contents): + uid = uuid.uuid4() + mbox_path = os.path.join(dump, "%s.json" % uid) + print("Dumping data to %s" % mbox_path) + with open(mbox_path, "w") as f: + json.dump( + { + "id": ojson["mid"], + "mbox": ojson, + "mbox_source": { + "id": ojson["dbid"], + "permalink": ojson["mid"], + "message-id": msg_metadata["message-id"], + "source": mbox_source(raw_message), + }, + "attachments": contents, + }, + f, + indent=2, + ) + f.close() + def archive_message(self, mlist, msg, raw_message=None, dry=False, dump=None, defaultepoch=None, digest=False): """Send the message to the archiver. @@ -687,6 +709,8 @@ class Archiver(object): # N.B. Also used by import-mbox.py return lid, ojson["mid"] if dry: print("**** Dry run, not saving message to database *****") + if dump: + self.dump_message(dump, ojson, msg_metadata, raw_message, contents) return lid, ojson["mid"] if dump: @@ -764,25 +788,7 @@ class Archiver(object): # N.B. Also used by import-mbox.py print( "Pushing to ES failed, but dumponfail specified, dumping JSON docs" ) - uid = uuid.uuid4() - mbox_path = os.path.join(dump, "%s.json" % uid) - with open(mbox_path, "w") as f: - json.dump( - { - "id": ojson["mid"], - "mbox": ojson, - "mbox_source": { - "id": ojson["dbid"], - "permalink": ojson["mid"], - "message-id": msg_metadata["message-id"], - "source": mbox_source(raw_message), - }, - "attachments": contents, - }, - f, - indent=2, - ) - f.close() + self.dump_message(dump, ojson, msg_metadata, raw_message, contents) sys.exit(0) # We're exiting here, the rest can't be done without ES # otherwise fail as before raise err