Skip to content

Commit

Permalink
refactoring more with better CARP returns from SFTP mover.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndenny committed Nov 18, 2024
1 parent cae9024 commit 5bf973a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
12 changes: 7 additions & 5 deletions lib/Bastion/CARP.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ def toJDN(self, **kwargs):
jdn = {
'ID': self.ID,
'action': self.action,
'args': list(self.args),
'opened': self.when.isoformat(),
'context': { }
}
if args:
jdn['args'] = list(args)

for k, v in self.context.items():
jdn['context'][k] = v
Expand Down Expand Up @@ -219,14 +220,15 @@ def toJDN(self, **kwargs):


class Request(isRequest):
REPORT = Report
def succeeded(self, doc, data = None, **kwargs):
return Report(self, ReplyStatus.Ok, doc, data, **kwargs)
return self.REPORT(self, ReplyStatus.Ok, doc, data, **kwargs)

def failed(self, doc, data = None, **kwargs):
return Report(self, ReplyStatus.Failed, doc, data, **kwargs))
return self.REPORT(self, ReplyStatus.Failed, doc, data, **kwargs))

def crashed(self, doc, data = None, **kwargs):
return Report(self, ReplyStatus.Crashed, doc, data, **kwargs))
return self.REPORT(self, ReplyStatus.Crashed, doc, data, **kwargs))

def inconclusive(self, doc, data = None, **kwargs)
return Report(self, ReplyStatus.Inconclusive, doc, data, **kwargs)
return self.REPORT(self, ReplyStatus.Inconclusive, doc, data, **kwargs)
49 changes: 49 additions & 0 deletions lib/Bastion/Movers/CARP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import pathlib
import subprocess
import operator
import datetime
import json
import socket
import logging
import getpass
import shutil
import tarfile
import logging

from Bastion.Common import Thing, Unknown
import Bastion.Model
from Bastion.Curator import Manifest, BLONDE, Snap
from Bastion.CARP import Request, Receipt


class PackRequest(Request):
REPORT = PackReport
def __init__(self, asset, spooled, basis = None, **kwargs):
Request.__init__(self, kwargs.get("action", "pack"))

self.context['asset'] = str(asset.CURIE)
self.context['halo'] = str(asset.halo)

if basis:
self.context['detail'] = 'D'
self.context['basis'] = str(kwargs['basis'])
self.context['whence'] = kwargs['whence'].isoformat()
if 'genus' in kwargs:
self.context['genus'] = kwargs['genus']
else:
self.context['detail'] = 'F'


class PackReport(Receipt):
def __init__(self, request, status, doc, obj = None, **kwargs):
Report.__init__(self, request, status, doc, obj, **kwargs)



class PutRequest(Request):
pass


class PutReceipt(Receipt):
pass
9 changes: 3 additions & 6 deletions lib/Bastion/Movers/SFTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from Bastion.Common import Thing, Unknown
import Bastion.Model
from Bastion.Curator import Manifest, BLONDE, Snap
from Bastion.CARP import Request, Receipt


logger = logging.getLogger(__name__)
Expand All @@ -26,6 +27,8 @@ def asPurePath(x):
return pathlib.PurePosixPath(x)




class Mover(Bastion.Model.isMover):
def __init__(self, vault, **kwargs):
isClerk.__init__(self)
Expand Down Expand Up @@ -113,12 +116,6 @@ def pack(self, asset, basis = None, **kwargs):
#-- use the built-in python tar archiver, using "pax" (POSIX.1-2001) extensions.
pax((self.scratch / tag), asset.halo, **opts)

#-- start a receipt for packing the asset.
receipt = Bastion.Model.PackingReceipt(asset, blonded, spooled)

#-- some optional information that might be of use...
receipt['size'] = spooled.stat().st_size
receipt['tag'] = str(tag)

#-- Answer the receipt.
return receipt
Expand Down

0 comments on commit 5bf973a

Please sign in to comment.