Wutag tags are currently stored in a way that makes them unique to wutag. They might get picked up by other programs, but they won’t look the same. The reason why is that tags get serialized in cbor and prefixed with wutag. for easier future extraction as can be seen here:
fn hash(&self) -> Result<String> {
serde_cbor::to_vec(&self)
.map(|tag| format!("{}.{}", WUTAG_NAMESPACE, base64::encode(tag)))
.map_err(Error::from)
How can I serialize the tags in python?
import base64
import pytest
import xattr
WUTAG_NAMESPACE = "user.wutag"
def hash(tag: Dict) -> str:
return f"{WUTAG_NAMESPACE}.{pickle.dumps(tag).encode('base64', 'strict')}"
# AttributeError: 'bytes' object has no attribute 'encode'
#return f"{WUTAG_NAMESPACE}.{base64.b64encode(json.dumps(tag))}"
# TypeError: a bytes-like object is required, not 'str'
def test_hash():
tag = {'name': 'tag1', 'color': '#000000'}
assert hash('tag') == 'user.wutag.dGFn'
def hash_tags(tags: List[Dict]) -> List[str]:
return [hash(tag) for tag in tags]
def import_tags_wutag(path: str, tags: List[str]) -> List[str]:
xattr.setxattr(path, WUTAG_NAMESPACE, hash_tags(tags))
Here is another try that doesn’t seem to work either:
def write_wutag_tags(parent_folder: str, tags: List[str]) -> None:
for format in FORMAT_LIST:
filepath = get_filepath(parent_folder, format)
subprocess.run(['wutag', 'set', filepath, *tags])
This last one fails with this error if any of the tags is empty.
error: The argument '<tags>...' requires a value but none was supplied
USAGE:
wutag set <pattern> <tags>...
For more information try --help
Otherwise it works fine.
Still need a test for the rust code to make sure they are the same.