[#30] preset: PEP 8 refactor

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-10-25 17:43:20 +03:00 committed by fyrchik
parent eaff41c055
commit 0088fbd7d6
2 changed files with 33 additions and 36 deletions

View file

@ -54,14 +54,14 @@ def main():
for container in container_list:
print(f" > Upload objects for container {container}")
with ProcessPoolExecutor(max_workers=50) as executor:
objects_runs = {executor.submit(upload_object, container, payload_filepath): _ for _ in range(int(args.preload_obj))}
objects_runs = {executor.submit(upload_object, container, payload_filepath): _ for _ in
range(int(args.preload_obj))}
for run in objects_runs:
if run.result() is not None:
objects_struct.append({'container': container, 'object': run.result()})
print(f" > Upload objects for container {container}: Completed")
print("Upload objects to each container: Completed")
data = {'containers': container_list, 'objects': objects_struct, 'obj_size': args.size + " Kb"}
@ -104,6 +104,7 @@ def create_container():
fst_str = output.split('\n')[0]
except Exception:
print(f"Got empty output: {output}")
return
splitted = fst_str.split(": ")
if len(splitted) != 2:
raise ValueError(f"no CID was parsed from command output: \t{fst_str}")
@ -123,6 +124,7 @@ def upload_object(container, payload_filepath):
snd_str = out.split('\n')[1]
except:
print(f"Got empty input: {out}")
return
splitted = snd_str.split(": ")
if len(splitted) != 2:
raise Exception(f"no OID was parsed from command output: \t{snd_str}")

View file

@ -1,14 +1,12 @@
#!/usr/bin/python3
from multiprocessing import Process
import uuid
import shlex
from subprocess import check_output, CalledProcessError, STDOUT
import argparse
import json
import os
import argparse, sys
import shlex
import uuid
from concurrent.futures import ProcessPoolExecutor
from subprocess import check_output, CalledProcessError, STDOUT
parser = argparse.ArgumentParser()
@ -30,7 +28,6 @@ def main():
objects_struct = []
payload_filepath = '/tmp/data_file'
if args.update:
# Open file
with open(args.out) as f:
@ -65,7 +62,6 @@ def main():
objects_struct.append({'bucket': bucket, 'object': run.result()})
print(f" > Upload objects for bucket {bucket}: Completed")
print("Upload objects to each bucket: Completed")
data = {'buckets': bucket_list, 'objects': objects_struct, 'obj_size': args.size + " Kb"}
@ -82,6 +78,7 @@ def random_payload(payload_filepath):
with open('%s' % payload_filepath, 'wb') as fout:
fout.write(os.urandom(1024 * int(args.size)))
def execute_cmd(cmd_line):
args = shlex.split(cmd_line)
output = ""
@ -118,7 +115,7 @@ def create_bucket():
bucket_create_marker = True
print(f"cmd: {cmd_line}")
if (bucket_create_marker == True and args.versioning == "True"):
if bucket_create_marker and args.versioning == "True":
out, success = execute_cmd(cmd_line_ver)
if not success:
print(f" > Bucket versioning has not been applied for bucket {bucket_name}.")
@ -142,5 +139,3 @@ def upload_object(bucket, payload_filepath):
if __name__ == "__main__":
main()