commit fd8917fba75dfd8d7571bc0262f549b09ea125fa
parent 78570e2920b5067ebe95ba2722443112183f9da5
Author: lash <dev@holbrook.no>
Date: Mon, 23 Mar 2026 08:40:02 -0600
Enable metadata for asset, handle hex digest to binary
Diffstat:
3 files changed, 33 insertions(+), 29 deletions(-)
diff --git a/dummy/requirements.txt b/dummy/requirements.txt
@@ -8,3 +8,4 @@ rencode==1.0.8
wheepy[valkey]~=0.0.3
filemagic~=1.6
PyGObject~=3.52.3
+xdg-base-dirs~=6.0.2
diff --git a/dummy/usawa/asset.py b/dummy/usawa/asset.py
@@ -56,8 +56,10 @@ class Asset(UsawaElement):
Asset.from_tree() - Recreate from an XML tree.
"""
- def __init__(self, digest=None, ref=None, slug=None, mimetype=None):
+ def __init__(self, digest=None, ref=None, slug=None, mimetype=None, extref=None, description=None):
super(Asset, self).__init__(ref=ref)
+ if isinstance(digest, str):
+ digest = bytes.fromhex(digest)
self.digest = digest
self.ext = None
if mimetype == None:
@@ -70,8 +72,8 @@ class Asset(UsawaElement):
if slug == None:
slug = self.get_ref()
self.slug = slug
- self.extref = None
- self.description = None
+ self.extref = extref
+ self.description = description
"""Return the preferred filename with extension for the asset.
@@ -135,7 +137,7 @@ class Asset(UsawaElement):
"""
@staticmethod
- def from_file(filepath, description=None, slug=None, mimetype=None, extref=None):
+ def from_file(filepath, description=None, slug=None, mimetype=None, ref=None, extref=None):
f = open(filepath, "rb")
return Asset.from_io(
f,
@@ -144,6 +146,7 @@ class Asset(UsawaElement):
description=description,
slug=slug,
mimetype=mimetype,
+ ref=ref,
extref=extref,
)
@@ -172,9 +175,9 @@ class Asset(UsawaElement):
@staticmethod
def from_io(
- io, src, closer=None, description=None, slug=None, mimetype=None, extref=None
+ io, src, closer=None, description=None, slug=None, mimetype=None, extref=None, ref=None
):
- o = Asset()
+ o = Asset(ref=ref)
h = hashlib.sha512()
b = io.read(BLOCKSIZE)
if mimetype == None:
diff --git a/dummy/usawa/store.py b/dummy/usawa/store.py
@@ -103,7 +103,8 @@ def pfx_entry_draft(entry):
def pfx_asset(asset):
if not isinstance(asset, Asset):
raise ValueError('invalid asset')
- return PFX_ASSET + asset.get_digest(binary=True)
+ digest = asset.get_digest(binary=True)
+ return PFX_ASSET + digest
def pfx_asset_index(asset):
@@ -132,6 +133,27 @@ class BaseStore(Interface):
return self.db.get(k)
+ """Implements whee.Interface.lock
+ """
+ def lock(self):
+ k = pfx_ledger_lock(self.ledger.topic)
+ v = None
+ # TODO: needs to be an atomic routine
+ try:
+ v = self.db.get(k)
+ except KeyError:
+ raise PermissionError()
+ self.db.put(k, 0x01, exist_ok)
+ # atomic until here
+
+
+ """Implements whee.Interface.unlock
+ """
+ def unlock(self):
+ k = pfx_ledger_lock(self.ledger.topic)
+ v = self.db.delete(k)
+
+
class KeyStore(BaseStore):
"""Add signing key to the store.
@@ -318,26 +340,6 @@ class LedgerStore(EntryStore, AssetStore, KeyStore):
self.ledger.serial = serial
- """Implements whee.Interface.lock
- """
- def lock(self):
- k = pfx_ledger_lock(self.ledger.topic)
- v = None
- # TODO: needs to be an atomic routine
- try:
- v = self.db.get(k)
- except KeyError:
- raise PermissionError()
- self.db.put(k, 0x01, exist_ok)
- # atomic until here
-
-
- """Implements whee.Interface.unlock
- """
- def unlock(self):
- k = pfx_ledger_lock(self.ledger.topic)
- v = self.db.delete(k)
-
"""Load all entries from store, oldest to newest.
Must be called on an unused ledger instance. Using with a ledger that contains or has contains entries is undefined.
@@ -374,8 +376,6 @@ class LedgerStore(EntryStore, AssetStore, KeyStore):
i -= 1
-
-
"""Store all entries in the ledger state.
Errors due to duplicate entry and asset insert attempts will be ignored.