From 90cd0480e4820ecd3c81134a7ba2e27dbb9bf849 Mon Sep 17 00:00:00 2001 From: Nathan Denny Date: Mon, 18 Nov 2024 13:11:18 -0500 Subject: [PATCH] Still working through request-receipt/report in CARPs. Maybe look at previous work in Caragols? --- lib/Bastion/CARP.py | 9 +++++++-- lib/Bastion/Model.py | 32 +++++++++++++++++--------------- lib/Bastion/Movers/CARP.py | 1 + 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/Bastion/CARP.py b/lib/Bastion/CARP.py index b607fe9..bc3bc62 100644 --- a/lib/Bastion/CARP.py +++ b/lib/Bastion/CARP.py @@ -151,6 +151,7 @@ def __init__(self, request, status, obj, context = None, **kwargs): if not isinstance(status, ReplyStatus): raise ValueError("status must be of type ReplyStatus") + self.ID = kwargs.get('ID', str(uuid.uuid4())) self.request = request self.status = status self.lede = kwargs.get('lede', status.category) @@ -174,6 +175,7 @@ def toJDN(self, **kwargs): #-- Build result stanza. result = { + 'ID': self.ID, 'status': self.status.code, 'message': self.status.gloss, 'lede': self.lede, @@ -209,9 +211,9 @@ class Receipt(isReceipt): class Report(isReceipt): - def __init__(self, request, status, doc, obj = None, **kwargs): + def __init__(self, request, status, obj = None, **kwargs): isReceipt.__init__(self, request, status, obj, **kwargs) - self.report = doc + self.report = kwargs.get('report', None) def toJDN(self, **kwargs): jdn = isReceipt.toJDN(self, **kwargs) @@ -220,7 +222,10 @@ def toJDN(self, **kwargs): class Request(isRequest): + #-- Subclasses can set their own REPORT. + #-- This is used mostly in the convenience methods: .succeeded, .failed, etc. REPORT = Report + def succeeded(self, doc, data = None, **kwargs): return self.REPORT(self, ReplyStatus.Ok, doc, data, **kwargs) diff --git a/lib/Bastion/Model.py b/lib/Bastion/Model.py index 75fd6f3..747548e 100644 --- a/lib/Bastion/Model.py +++ b/lib/Bastion/Model.py @@ -164,15 +164,14 @@ def pack(self, asset, basis = None, **kwargs): * spool is the absolute path to the folder holding the new archive file. * package is the name of the archive file in the spool folder """ - self.mover.pack(asset, basis, **kwargs) + self.packer.pack(asset, basis, **kwargs) def unpack(self, halo, root, **kwargs): """ Given a local packed archive object (e.g. .tar, .zip, etc.) at halo, I unpack the archive into the given (local) root path. """ - return self.mover.unpack(halo, root, **kwargs) - + return self.packer.unpack(halo, root, **kwargs) def push(self, asset, basis = None, **kwargs): """ @@ -359,18 +358,7 @@ def manifest(self, ark): raise NotImplementedError -class isMover: - """ - abstract class for file movement in to and out of a specific vault type. - """ - def provision(self, *args): - """ - provision(ark) - ensures that the site, zone, and asset folders exist. - provision(site, zone, asset_name) - an alias for provision(ark) - provision(asset) - given an instance of Asset, provision the necessary site, zone, and asset folders. - """ - raise NotImplementedError - +class isPacker: def pack(self, asset, basis = None, **kwargs): """ Given a local asset, I package (.tar, .zip, etc) the asset into my scratch (spool) space. @@ -392,6 +380,20 @@ def unpack(self, halo, root, **kwargs): """ raise NotImplementedError + + +class isMover: + """ + abstract class for file movement in to and out of a specific vault type. + """ + def provision(self, *args): + """ + provision(ark) - ensures that the site, zone, and asset folders exist. + provision(site, zone, asset_name) - an alias for provision(ark) + provision(asset) - given an instance of Asset, provision the necessary site, zone, and asset folders. + """ + raise NotImplementedError + def push(self, asset, basis = None, **kwargs): """ Given an asset, I push a backup of the asset to this vault. diff --git a/lib/Bastion/Movers/CARP.py b/lib/Bastion/Movers/CARP.py index bf8536a..27f937a 100644 --- a/lib/Bastion/Movers/CARP.py +++ b/lib/Bastion/Movers/CARP.py @@ -19,6 +19,7 @@ class PackRequest(Request): REPORT = PackReport + def __init__(self, asset, spooled, basis = None, **kwargs): Request.__init__(self, kwargs.get("action", "pack"))