From c5de3e646723a91ed2a71c5e2d4e1742d9345fab Mon Sep 17 00:00:00 2001 From: synkd Date: Thu, 3 Nov 2022 10:35:30 -0400 Subject: [PATCH 1/2] Add manifest filename as attribute In some scenarios, it will be useful to have the filename of the manifest archive immediately accessible as an attribute of the object returned by manifester. This commit assigns a manifest name based on the subscription allocation name to the Manifester object during instantiation and subsequently assigns that name to the response object containing the manifest returned by the API's export job. --- manifester/manifester.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manifester/manifester.py b/manifester/manifester.py index 6d8946a..cd7112b 100644 --- a/manifester/manifester.py +++ b/manifester/manifester.py @@ -22,6 +22,7 @@ def __init__(self, manifest_category, allocation_name=None, **kwargs): self.allocation_name = allocation_name or "".join( random.sample(string.ascii_letters, 10) ) + self.manifest_name = f'{self.allocation_name}_manifest.zip' self.offline_token = kwargs.get("offline_token", self.manifest_data.offline_token) self.subscription_data = self.manifest_data.subscription_data self.token_request_data = { @@ -306,7 +307,7 @@ def trigger_manifest_export(self): "proxies": self.manifest_data.get("proxies", settings.proxies), } # Should this use the XDG Base Directory Specification? - local_file = Path(f"manifests/{self.allocation_name}_manifest.zip") + local_file = Path(f"manifests/{self.manifest_name}") local_file.parent.mkdir(parents=True, exist_ok=True) logger.info( f"Triggering manifest export job for subscription allocation {self.allocation_name}" @@ -362,6 +363,7 @@ def trigger_manifest_export(self): ) local_file.write_bytes(manifest.content) manifest.path = local_file + manifest.name = self.manifest_name return manifest def get_manifest(self): From ac82e3bb71b55236e4017825ac7e88e02abfcbff Mon Sep 17 00:00:00 2001 From: synkd Date: Thu, 3 Nov 2022 10:51:03 -0400 Subject: [PATCH 2/2] Assign manifest name as a path object --- manifester/manifester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifester/manifester.py b/manifester/manifester.py index cd7112b..04bd002 100644 --- a/manifester/manifester.py +++ b/manifester/manifester.py @@ -22,7 +22,7 @@ def __init__(self, manifest_category, allocation_name=None, **kwargs): self.allocation_name = allocation_name or "".join( random.sample(string.ascii_letters, 10) ) - self.manifest_name = f'{self.allocation_name}_manifest.zip' + self.manifest_name = Path(f'{self.allocation_name}_manifest.zip') self.offline_token = kwargs.get("offline_token", self.manifest_data.offline_token) self.subscription_data = self.manifest_data.subscription_data self.token_request_data = {