Skip to content

Commit

Permalink
Add exception handling. Formatting for pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcarlosrendon authored Jul 27, 2020
1 parent e65647c commit 1ecd2ab
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions delete_archives.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Delete's AWS Glacier archives given a Vault's inventory JSON
Handles step 5 of https://docs.aws.amazon.com/amazonglacier/latest/dev/deleting-an-archive-using-cli.html
Handles step 5 of:
https://docs.aws.amazon.com/amazonglacier/latest/dev/deleting-an-archive-using-cli.html
Usage: delete_archives.py [vault_name] [archive_json_file]
"""
Expand All @@ -14,7 +15,10 @@

argparser = argparse.ArgumentParser()
argparser.add_argument("vault", help="Vault Name")
argparser.add_argument("archive_json_file", help="JSON of Archive Inventory. See step 4 https://docs.aws.amazon.com/amazonglacier/latest/dev/deleting-an-archive-using-cli.html")
help = "JSON of Archive Inventory. See step 4 of " \
"https://docs.aws.amazon.com/amazonglacier/latest/dev/deleting-an-archive-using-cli.html"
argparser.add_argument("archive_json_file",
help=help)
args = argparser.parse_args()

with open(args.archive_json_file) as f:
Expand All @@ -26,8 +30,15 @@

def delete_boto(archive):
client = boto3.client("glacier")
archive_id = archive.get("ArchiveId")
client.delete_archive(vaultName=args.vault, archiveId=archive_id)


Parallel(n_jobs=os.cpu_count(), prefer="threads", verbose=1)(delayed(delete_boto)(archive) for archive in archives)
archive_id = archive.get("ArchiveId")
try:
resp = client.delete_archive(vaultName=args.vault,
archiveId=archive_id)
except Exception as e:
print(resp)
print(e)


Parallel(n_jobs=os.cpu_count(),
prefer="threads",
verbose=1)(delayed(delete_boto)(archive) for archive in archives)

0 comments on commit 1ecd2ab

Please sign in to comment.