From 951bfbe664a19c119c51d5ed6a8c77aaf65138b9 Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Wed, 10 Aug 2022 17:09:21 -0400 Subject: [PATCH] Add basic context manager functionality This change adds a basic content manager that creates the manifest on enter and deletes the allocation on exit. This can certainly be beefed up! --- manifester/manifester.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/manifester/manifester.py b/manifester/manifester.py index cfb79b1..fdaea30 100644 --- a/manifester/manifester.py +++ b/manifester/manifester.py @@ -323,3 +323,13 @@ def get_manifest(self): subscription_data=sub, ) return self.trigger_manifest_export() + + def __enter__(self): + try: + return self.get_manifest() + except: + self.delete_subscription_allocation() + raise + + def __exit__(self, *tb_args): + self.delete_subscription_allocation()