Skip to content

Commit

Permalink
debugging mostly; some refactoring, too; work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndenny committed Jan 7, 2025
1 parent decc7cc commit b2a134f
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 221 deletions.
21 changes: 6 additions & 15 deletions bin/bastion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import pathlib
import logging
import traceback
import socket
import json

Expand All @@ -23,14 +22,13 @@
sys.path.insert(0, str(LIB_PATH))


from Bastion.Common import *
from Bastion.Common import Boggle, asPath
from Bastion.Chronology import Quantim
from Bastion.Site import Site
from Bastion.Condo import *
from Bastion.Actions import *
from Bastion.Condo import Condex
from Bastion.Model import ARK
from Bastion.CARP import isRequest, isReceipt
#import Bastion.Vaults.HPSS
from Bastion.CARP import Request, isReceipt
import Bastion.Vaults.HPSS
import Bastion.Vaults.BFD

"""
Expand Down Expand Up @@ -248,7 +246,7 @@ def emit(self, answer, ostream = None):
ostream = ostream if (ostream is not None) else sys.stdout

if 'emit' in answer.request.context:
form = opts['emit'].upper()
form = answer.request['emit'].upper()
else:
form = self.tongue

Expand Down Expand Up @@ -603,18 +601,11 @@ def do_refresh_keytab(self, comargs, comdex, opts):
if sys.argv[1:] != ['shell']:
app.run( )
else:
vehicle = os.environ.get('BASTION_SITE', None)
if vehicle == 'rusina':
if os.environ.get('BASTION_SITE', None) == 'rusina':
rusina = app.site('rusina')
soundscapes = rusina.zone('soundscapes')
asset = soundscapes['HackathonData']
vault = app.vault(asset.policy.vault)
elif vehicle == 'scout':
scout = app.site('scout')
ADS = scout.zone('ADS')
asset = ADS['FSIL']
vault = app.vault(asset.policy.vault)


#-- does a full, level 0 backup
#bastion backup site {site}
Expand Down
1 change: 1 addition & 0 deletions lib/Bastion/Chronology.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,4 @@ def latest(self):
@classmethod
def now(cls):
return cls(datetime.datetime.now())

4 changes: 3 additions & 1 deletion lib/Bastion/Clerks/BFD.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

class Clerk(isClerk):
def __init__(self, vault, root = None, **kwargs):
isClerk.__init__(self, vault)
isClerk.__init__(self)

assert isinstance(vault, isVault), "vault must be an instance of Bastion.Model.isVault"
if root:
assert isinstance(root, pathlib.PosixPath), "root must be an instance of PosixPath"

self.vault = vault
self.root = root if root is not None else vault.bank

#-----------------------------------------
Expand Down
38 changes: 15 additions & 23 deletions lib/Bastion/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,23 @@ def Slug40(text):
return base64.b32encode(bs).decode('utf-8')


class canConStruct:
class canStruct:
"""
I am a trait for constructing instances of self from a given JSON normalized dictionary (JDN)
I am a trait for serialization using JSON and YAML.
"""
def toJDN(self, **kwargs):
raise NotImplementedError(".toJDN is subclass responsibility")

def toJSON(self, **kwargs):
jdn = self.toJDN(**kwargs)
return json.dumps(jdn, indent = 3, sort_keys = True)

def toYAML(self, **kwargs):
jdn = self.toJDN(**kwargs)
return yaml.dump(jdn, default_flow_style = False, indent = 3)


class canConStruct:
@classmethod
def fromJDN(cls, jdn, **kwargs):
raise NotImplementedError(".fromJDN is subclass responsibility")
Expand All @@ -300,27 +313,6 @@ def fromYAML(cls, ydoc, **kwargs):
return cls.fromJDN(jdn, **kwargs)


class canStruct:
"""
I am a trait for creating a data structure of self expressed in JSON dictionary normal (JDN) form.
"""
def toJDN(self, **kwargs):
raise NotImplementedError(".toJDN is subclass responsibility")

#↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
#-- host class protocol. |
#-- host classes must implement the methods, above. |
#-----------------------------------------------------

def toJSON(self, **kwargs):
jdn = self.toJDN(**kwargs)
return json.dumps(jdn, indent = 3, sort_keys = True)

def toYAML(self, **kwargs):
jdn = self.toJDN(**kwargs)
return yaml.dump(jdn, default_flow_style = False, indent = 3)


#-- Used as pre-defined symbol sets for the Boggle function, below.
BOGGLES = {
"Azed9": string.ascii_uppercase + string.ascii_lowercase + string.digits,
Expand Down
4 changes: 2 additions & 2 deletions lib/Bastion/Curator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"""
import datetime

from Bastion.Common import Thing, Boggle, canStruct
from Bastion.Common import Thing, Boggle, canTextify
from Bastion.Model import ARK, isAsset
from Bastion.Chronology import Quantim


class BLONDE:
class BLONDE(canTextify):
"""
BLOb Name and Description Encoding
I am a structured name describing a point in time for a single ARK.
Expand Down
2 changes: 1 addition & 1 deletion lib/Bastion/Humane.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def _humanize_timedelta(elapsed, **kwargs):
return "{:.1f} seconds".format(dt)


humanize.spells.append( (datetime.timedelta, _humanize_timedelta) )
humanize.magic.append( (datetime.timedelta, _humanize_timedelta) )
5 changes: 3 additions & 2 deletions lib/Bastion/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def perform(self, request):
raise NotImplementedError


class isVault(canConfigure):
class isVault:
"""
I am the base class for all storage vaults.
Users of Vaults primarily interact with the vault through the .push and .pull methods.
Expand Down Expand Up @@ -266,9 +266,10 @@ def for_protocol(protocol):
def handling(protocol):
return isVault.PROTOCOLS[protocol]

#-- nickname
#-- legacy name preserved as an alt / nickname
Vault = isVault


class isAsset:
"""
abstract Asset type, describes a local file in both the host file system and the logical (zone) space.
Expand Down
12 changes: 7 additions & 5 deletions lib/Bastion/Movers/BFD.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@


class Mover(isMover):
def __init__(self, vault, bank = None, **kwargs):
isMover.__init__(self, vault)
if bank:
assert isinstance(bank, pathlib.Path), "bank must be an instance of Path"
self.bank = bank if bank is not None else vault.bank
def __init__(self, vault, **kwargs):
isMover.__init__(self)
self.vault = vault
self.bank = kwargs.get('bank', vault.bank)

assert isinstance(self.vault, isVault), "vault must be an instance of Bastion.Model.isVault"
assert isinstance(self.bank, pathlib.PurePosixPath), "bank must be an instance of Path"

#-----------------------------------------
#-- BEGIN Bastion.Model.isMover PROTOCOL |
Expand Down
6 changes: 2 additions & 4 deletions lib/Bastion/Movers/CARP.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import pathlib
import logging

from Bastion.Common import Thing, Unknown, toJDN
from Bastion.Model import isAsset
from Bastion.Curator import Manifest, BLONDE, Snap
from Bastion.CARP import isRequest, isReceipt
from Bastion.Common import Thing, toJDN
from Bastion.CARP import isReceipt, isRequest


logger = logging.getLogger(__name__)
Expand Down
14 changes: 7 additions & 7 deletions lib/Bastion/Packers/CARP.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import logging

from Bastion.Model import isAsset
from Bastion.CARP import isRequest
from Bastion.CARP import isRequest, isReceipt
from Bastion.Curator import BLONDE


logger = logging.getLogger(__name__)


class PackingReceipt:
class PackingReceipt(isReceipt):
def __init__(self, asset, tag, packaged, tarp):
#-- asset:Bastion.Model.isAsset
#-- tag:pathlib.PurePosixPath
Expand All @@ -20,10 +20,10 @@ def __init__(self, asset, tag, packaged, tarp):
assert isinstance(tag, pathlib.PurePosixPath), "tag must be pathlib.PurePosixPath"
assert isinstance(tarp, pathlib.PosixPath), "tarp must be pathlib.PosixPath"

self.asset = asset #-- the asset that was packed
self.tag = tag #-- the full name of the packed object
self.packaged = packaged #-- an inventory of what was packed
self.tarp = tarp #-- the path to the local package (TARfile Path → "tarp")
self.asset = asset #-- the asset that was packed
self.tag = tag #-- the full name of the packed object
self.packaged = packaged #-- an inventory of what was packed
self.tarp = tarp #-- the path to the local package (TARfile Path → "tarp")
self.blonde = BLONDE.decode(tag.stem) #-- the BLONDE for the packed object

def toJDN(self):
Expand All @@ -48,7 +48,7 @@ class PackRequest(isRequest):
"""
def __init__(self, subject, *args, **kwargs):
if isinstance(subject, isRequest):
isRequest.__init__("PackRequest", ID = subject.ID, opened = subject.when, context = subject.context)
isRequest.__init__(self, "PackRequest", ID = subject.ID, opened = subject.when, context = subject.context)

elif isinstance(subject, isAsset):
asset = subject
Expand Down
10 changes: 5 additions & 5 deletions lib/Bastion/Site.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import random
import datetime

from Bastion.Common import entity, Thing, canInStruct, DAYS, RDN, asPath, asLogLevel
from Bastion.Common import entity, Thing, canStruct, DAYS, RDN, asPath, asLogLevel
from Bastion.Condo import CxNode
from Bastion.Model import ARK, isAsset, isZone, isSite
#from .Curator import Asset
Expand All @@ -24,7 +24,7 @@



class Site(isSite, canConfigure):
class Site(isSite, canStruct):
SITES = { }

@staticmethod
Expand Down Expand Up @@ -152,7 +152,7 @@ def asset(self, ark):
# return None


class RetentionPolicy(canConfigure, canInStruct, canConStruct):
class RetentionPolicy(canStruct, canConStruct):
"""
How long to store an object, how many copies, and where the copies are deposited.
"""
Expand Down Expand Up @@ -205,7 +205,7 @@ def fromJDN(cls, jdn):



class Asset(isAsset, canTextify):
class Asset(isAsset, canStruct):
def __init__(self, zone, *args, **kwargs):
"""
Asset(zone:Zone, name:str)
Expand Down Expand Up @@ -372,7 +372,7 @@ def __iter__(self):
return iter(sorted(self.xRDNs.values(), key = lambda x: str(x.halo)))


class Zone(isZone, canConfigure):
class Zone(isZone):
"""
I am a (resource) zone.
A zone is a logical entry point to a collection of assets.
Expand Down
48 changes: 24 additions & 24 deletions lib/Bastion/Vaults/HPSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import logging
import getpass

from Bastion.Common import Thing, Unknown
import Bastion.Model
from Bastion.Curator import BLONDE
from Bastion.Common import Thing
from Bastion.Model import ARK, isVault
from Bastion.Curator import Manifest, BLONDE

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -205,13 +205,13 @@ def __getitem__(self, path):
note = aline[11:].strip()
return note

def __setitem__(self, path, note):
request = 'annotate -A "{}" {}'.format(note, str(path))
proc = self.do(request)
#def __setitem__(self, path, note):
# request = 'annotate -A "{}" {}'.format(note, str(path))
#proc = self.do(request)

def __delitem__(self, path):
request = 'annotate -e {}'.format(str(path))
proc = self.do(request)
#def __delitem__(self, path):
# request = 'annotate -e {}'.format(str(path))
#proc = self.do(request)


class HSI:
Expand All @@ -231,10 +231,10 @@ def do(self, command):
self.procd = subprocess.run(comargs, capture_output = True, check = True)
return self.procd

def mkdirs(self, path):
request = "mkdir -p {}".format( str(path) )
procd = self.do(request)
return True
#def mkdirs(self, path):
#request = "mkdir -p {}".format( str(path) )
#procd = self.do(request)
#return True

def statx(self, target):
"""
Expand All @@ -251,14 +251,14 @@ def statx(self, target):
lines = [line.strip() for line in proc.stdout.decode('utf-8').split('\n')]
line = lines[0]
tokens = [token.strip() for token in line.split()]
size = 0
#size = 0

obj = target.toJDN()

obj['xtype'] = tokens[0]

if obj['xtype'] in ('FILE', 'HARDLINK'):
size = int(tokens[2])
#size = int(tokens[2])
created_mdy = tokens[9]
created_time = tokens[10]

Expand Down Expand Up @@ -320,11 +320,11 @@ def lsx(self, path = None):



class Vault(Bastion.Model.Vault):
class Vault(isVault):
PROTOCOL = 'HTAR'

def __init__(self, name, **kwargs):
Bastion.Model.Vault.__init__(self, name, **kwargs)
isVault.__init__(self, name, **kwargs)

self.server = kwargs.get('server', socket.gethostname())
self.login = kwargs.get('login', getpass.getuser())
Expand Down Expand Up @@ -462,12 +462,12 @@ def push(self, asset, **kwargs):
'stolo': ""
}

exportBastion.Model.Vaults = {
"HPSS_AUTH_METHOD": "keytab",
"HPSS_PRINCIPAL": self.login,
"HPSS_KEYTAB_PATH": str(self.keytab.halo),
"HPSS_HOSTNAME": str(self.client)
}
# exports = {
# "HPSS_AUTH_METHOD": "keytab",
# "HPSS_PRINCIPAL": self.login,
# "HPSS_KEYTAB_PATH": str(self.keytab.halo),
# "HPSS_HOSTNAME": str(self.client)
# }

#-- save the current working directory.
ogdir = os.getcwd( )
Expand Down Expand Up @@ -505,7 +505,7 @@ def _manifest_ark(self, ark):
#-- The manifest a catalog of all of the backup objects for the asset.
fls = self.hsi.ls(self.root / ark.site / ark.zone / ark.asset)
blondes = [fl.path.name for fl in fls]
manifest = Bastion.Curator.Manifest(ark, blondes)
manifest = Manifest(ark, blondes)

return manifest

Expand Down
Loading

0 comments on commit b2a134f

Please sign in to comment.