aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/lib/naming_policy.py
diff options
context:
space:
mode:
Diffstat (limited to 'bsie/lib/naming_policy.py')
-rw-r--r--bsie/lib/naming_policy.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/bsie/lib/naming_policy.py b/bsie/lib/naming_policy.py
index 9b9a45d..ffef7d9 100644
--- a/bsie/lib/naming_policy.py
+++ b/bsie/lib/naming_policy.py
@@ -4,6 +4,9 @@ import abc
import os
import typing
+# external imports
+import urllib.parse
+
# bsie imports
from bsie.utils import bsfs, errors, ns
from bsie.utils.node import Node
@@ -80,14 +83,16 @@ class DefaultNamingPolicy(NamingPolicy):
def handle_node(self, node: Node) -> Node:
if node.uri is not None:
return node
- if node.node_type == ns.bsn.Entity :
- return self.name_file(node)
+ if node.node_type == ns.bsn.Entity:
+ return self.name_entity(node)
if node.node_type == ns.bsn.Preview:
return self.name_preview(node)
- raise errors.ProgrammingError('no naming policy available for {node.node_type}')
+ if node.node_type == ns.bsn.Tag:
+ return self.name_tag(node)
+ raise errors.ProgrammingError(f'no naming policy available for {node.node_type}')
- def name_file(self, node: Node) -> Node:
- """Set a bsfs:File node's uri fragment to its ucid."""
+ def name_entity(self, node: Node) -> Node:
+ """Set a bsn:Entity node's uri fragment to its ucid."""
if 'ucid' in node.hints: # content id
fragment = node.hints['ucid']
else: # random name
@@ -96,7 +101,7 @@ class DefaultNamingPolicy(NamingPolicy):
return node
def name_preview(self, node: Node) -> Node:
- """Set a bsfs:Preview node's uri fragment to its ucid.
+ """Set a bsn:Preview node's uri fragment to its ucid.
Uses its source fragment as fallback. Appends the size if provided.
"""
fragment = None
@@ -112,4 +117,14 @@ class DefaultNamingPolicy(NamingPolicy):
node.uri = getattr(self._prefix.preview(), fragment)
return node
+ def name_tag(self, node: Node) -> Node:
+ # NOTE: Must ensure to produce the same name for that tags with the same label.
+ if 'label' in node.hints: # tag label
+ fragment = urllib.parse.quote(node.hints['label'])
+ else: # random name
+ fragment = self._uuid()
+ # FIXME: match to existing tags in bsfs storage!
+ node.uri = getattr(self._prefix.tag(), fragment)
+ return node
+
## EOF ##