DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
0 votes

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))
by
edited by
0

What does a "wutag" tag look like?

0

It looks much different than what I had gotten. Should I remove the answer?

❯ wutag set test tag1

/home/user/test:
        + tag1
❯ getfattr --dump test
# file: test
user.wutag.o2l0aW1lc3RhbXB4HjIwMjItMDktMDRUMjI6MDY6NTEuMzcyNDk4MjI2WmRuYW1lZHRhZzFlY29sb3JkQ3lhbg\075\075=""

I can always call wutag from python, it may not be slower than what I'm doing.

1 Answer

0 votes
 
Best answer

Can be done directly using wutag. Since the set subcommand takes a pattern and not a file path as a parameter you can either change to the file directory with subprocess.run(cmd, cwd=parent_folder) or increase the max depth to search for the provided pattern. I think the second approach would be more efficient.

def write_wutag_tags(parent_folder: str, tags: List[str]) -> None:
    for format in FORMAT_LIST:
        filepath = get_filepath(parent_folder, format)
        filepath = os.path.relpath(filepath)
        depth = len(Path(filepath).parents)
        subprocess.run(['wutag', '-m', str(depth), 'set', filepath, *tags])

for format in FORMAT_LIST:
    filename = os.path.basename(parent_folder) + '.' + format
    subprocess.run(['wutag', 'set', filename, *tags], cwd=parent_folder)
by
edited by
Contributions licensed under CC0
...