← Back to team overview

pytagsfs team mailing list archive

multivalued tags

 

AFAIK, mutagen_.py and maildir.py rely on the following scheme:
- multiple tags are possible
- in the case of mutagen, tag's value is usable
- in the case of maildir, tags do not have value

In the case of xattr, one may perfectly want a multivalued field.
Eg, you want to tag a video with:
'subjects' = [ 'holiday', 'family' ]

instead of:
'subject1' = 'holiday'
'subject2' = 'family'

I still fail to see how I *should* properly implement base classes, but
here is what I currently do:

In my		class _XattrMetaStore(MetaStore),
the 		def get(self, path)
contains:
	values1 = dict ( xattr.get_all(path, namespace=xattr.NS_USER) )
	values2 = Values.from_flat_dict ( values1 )

The problem of separating multivalued tags lies in:
class Values(dict):
	def from_flat_dict(cls, d):
            if v is None:
                result[k] = []
            else:
                result[k] = [v]


that I would like to change to:
            if v is None:
                result[k] = []
            elif isinstance(v, (list, tuple)):
	            result[k] = v
            else:
                result[k] = [v]

(patch attached)

Then, back in _XattrMetaStore:get(self, path),
      between "values1 = ..." and "values2 = ...",
I can use:
   for k, v in values1.iteritems():
            if re.search(",", v):
	       values1[k] = v.split(",")	# hardcoded xattr split scheme

without having the value nested twice in a list.


what do you think about this ?

Raph
=== modified file 'modules/pytagsfs/values.py'
--- modules/pytagsfs/values.py	2009-12-05 21:32:29 +0000
+++ modules/pytagsfs/values.py	2011-05-22 16:23:26 +0000
@@ -29,6 +29,8 @@
         for k, v in d.items():
             if v is None:
                 result[k] = []
+            elif isinstance(v, (list, tuple)):
+                result[k] = v
             else:
                 result[k] = [v]
         return result


Follow ups