Merge in RR/pyinfra from pika_encapsulation to master
Squashed commit of the following:
commit 251fea4094062a72f5f0b1f8a54f959a1d7309ec
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Mar 15 15:02:25 2022 +0100
Adjusted readme and config to the actual changes.
commit d00a0aadc02be8ab1343dbaa2a8df82418e77673
Merge: ded29bb c34a1ce
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Mar 15 14:06:21 2022 +0100
Merge branch 'master' of ssh://git.iqser.com:2222/rr/pyinfra into pika_encapsulation
commit ded29bb8d0a78c1d5fd172edb74f0b120da05d5f
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Mar 15 14:02:37 2022 +0100
blackkkkkkkkkkkkkkkk
commit de3899c69f4e83fa5b8dc2702a18be66661201e9
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Mar 15 13:59:43 2022 +0100
Judgement Day - The Great Refactoring
commit 48eb2bb792dd45539e7db20949fedae03316c2b3
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Mar 15 13:30:41 2022 +0100
blacky
commit 38fb073291c6989fcc5560ef9f97e7dafd9570be
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Mar 15 13:29:46 2022 +0100
update mock client/publish
commit 8744cdeb6d21adab81fb82c7850a4ada31a1a3f9
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Mar 15 13:29:19 2022 +0100
quickfix consumer.consume_and_publish bug
commit 0ce30cafbf15142e3f773d0e510b7d22927ee86d
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Tue Mar 15 11:42:04 2022 +0100
updated serving logic for new queue, visior and storage logic
commit 5ac5fbf50bf9d8a6b6466cd04d82d21525250b4c
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Tue Mar 15 11:41:18 2022 +0100
changed callback signature to expect a dict with a key 'data'
commit 4c7c4b466e2b5228a6098c9130cd6c3334315153
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Tue Mar 15 09:46:39 2022 +0100
set dead letter queue related params
commit f8b60aad16eb0f5c91bed857ac3b352c4bcb7468
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 20:22:57 2022 +0100
added republishing logic
commit a40f07139af9121d8b72efa52b6b2588e7d233e8
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 19:10:08 2022 +0100
removed obsolete import
commit d3605b0913f8b155961b8c8e90e7c1d442a1da4f
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 19:09:50 2022 +0100
removed obsolete code
commit 9130b9fc753c63bfe4abd3cc26b31caf5c5bf2cb
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 19:05:59 2022 +0100
test refac
commit 1205adecdbd42a46dcc264a46086aab94c285b94
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 14:49:59 2022 +0100
removed obsolete import
commit 59d0de97e39646b3fa6c6ca91644dbf8adbd0de3
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 14:49:21 2022 +0100
applied black
commit f78a6894bc99b42d53a7c265ffd8c7869e9d606d
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 14:49:03 2022 +0100
applied black
commit 32740a914f8be15eed954389f6ddbb565e1567e6
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 14:47:47 2022 +0100
removed obsolete code
commit f21cbc141efc10d0e779f683dcc452e6c889dd6b
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 14:47:27 2022 +0100
consumer with visitor test fixed (added connection.close() in case of pika queue manager)
commit c415dcd8e6375e015b959a9c3cdee61b8ffe7d60
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Mon Mar 14 13:56:54 2022 +0100
consumer with visitor test WIP 2
... and 15 more commits
70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
import argparse
|
|
import gzip
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from tqdm import tqdm
|
|
|
|
from pyinfra.config import CONFIG
|
|
from pyinfra.storage.storages import get_s3_storage
|
|
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser()
|
|
|
|
subparsers = parser.add_subparsers(help="sub-command help", dest="command")
|
|
|
|
parser_add = subparsers.add_parser("add", help="Add file(s) to the MinIO store")
|
|
parser_add.add_argument("dossier_id")
|
|
add_group = parser_add.add_mutually_exclusive_group(required=True)
|
|
add_group.add_argument("--file", "-f")
|
|
add_group.add_argument("--directory", "-d")
|
|
|
|
subparsers.add_parser("purge", help="Delete all files and buckets in the MinIO store")
|
|
|
|
args = parser.parse_args()
|
|
return args
|
|
|
|
|
|
def add_file_compressed(storage, bucket_name, dossier_id, path) -> None:
|
|
|
|
path_gz = combine_dossier_id_and_file_id_and_extension(dossier_id, Path(path).stem, ".ORIGIN.pdf.gz")
|
|
|
|
with open(path, "rb") as f:
|
|
data = gzip.compress(f.read())
|
|
storage.put_object(bucket_name, path_gz, data)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
storage = get_s3_storage()
|
|
bucket_name = CONFIG.storage.bucket
|
|
|
|
if not storage.has_bucket(bucket_name):
|
|
storage.make_bucket(bucket_name)
|
|
|
|
args = parse_args()
|
|
|
|
if args.command == "add":
|
|
|
|
if args.file:
|
|
add_file_compressed(storage, bucket_name, args.dossier_id, args.file)
|
|
|
|
elif args.directory:
|
|
for fname in tqdm([*os.listdir(args.directory)], desc="Adding files"):
|
|
path = Path(args.directory) / fname
|
|
add_file_compressed(storage, bucket_name, args.dossier_id, path)
|
|
|
|
elif args.command == "purge":
|
|
storage.clear_bucket(bucket_name)
|
|
|
|
|
|
def combine_dossier_id_and_file_id_and_extension(dossier_id, file_id, extension):
|
|
return f"{dossier_id}/{file_id}{extension}"
|
|
|
|
|
|
def upload_compressed_response(storage, bucket_name, dossier_id, file_id, result) -> None:
|
|
data = gzip.compress(result.encode())
|
|
path_gz = combine_dossier_id_and_file_id_and_extension(dossier_id, file_id, CONFIG.service.response.extension)
|
|
storage.put_object(bucket_name, path_gz, data)
|