← Back to team overview

pytagsfs team mailing list archive

Re: -o metastore option to pytags ?

 

On Thu, May 19, 2011 at 11:44:45AM +0200, Raphaël wrote:
[...]
> I may be wrong but I think
> that choosing the metastore in use is as useful for pytags as it is for
> pytagsfs isn't ?

replying myself:
quick (and dirty ?) patch attached.

>From what I can see, it means that any subclass of Metastore should not
only implement get() and set() but also tag_class() which AFAIK is
used to check whether or not a file belongs to the selected metastore,
isn't ?

Raph
=== modified file 'modules/pytagsfs/pytags.py'
--- modules/pytagsfs/pytags.py	2011-04-29 20:19:25 +0000
+++ modules/pytagsfs/pytags.py	2011-05-19 11:08:31 +0000
@@ -23,6 +23,7 @@
 from pytagsfs.metastore.mutagen_ import MutagenFileMetaStore
 from pytagsfs import __version__ as version
 
+from pytagsfs.fs import PyTagsFileSystem
 
 def print_tags(filenames):
     failed_filenames = []
@@ -30,7 +31,7 @@
         print filename
 
         try:
-            f = MutagenFileMetaStore.tags_class(filename)
+            f = meta_store.tags_class(filename)
             if f is None:
                 raise IOError('Invalid file: %s' % filename)
         except Exception, e:
@@ -49,13 +50,13 @@
 
 def apply_substitution_pattern(filename, tags, substitution_pattern):
     if substitution_pattern:
-        current_values = MutagenFileMetaStore.extract(tags)
+        current_values = meta_store.extract(tags)
         splitter = substitution_pattern.get_splitter(current_values)
         pattern_tags = splitter.split(filename)
     else:
         pattern_tags = {}
 
-    MutagenFileMetaStore.inject(tags, pattern_tags)
+    meta_store.inject(tags, pattern_tags)
 
 
 def apply_operations(tags, operations):
@@ -84,7 +85,7 @@
         print filename
 
         try:
-            tags = MutagenFileMetaStore.tags_class(filename)
+            tags = meta_store.tags_class(filename)
             if tags is None:
                 raise IOError('Invalid file: %s' % filename)
         except (OSError, IOError), e:
@@ -168,6 +169,15 @@
           metavar = 'FOO=BAR',
           help = 'add value BAR as new value for tag FOO',
         )
+        self.add_option(
+            '--metastores',
+            action = 'store',
+            dest = 'metastores',
+            default = 'pytagsfs.metastore.mutagen_.MutagenFileMetaStore',
+            type = 'str',
+            metavar = 'FOO',
+            help = 'select the metastore FOO',
+        )
 
     def cb_set_format(self, option, opt_str, value, parser):
         if parser.values.operations:
@@ -185,6 +195,8 @@
 
     if len(args) < 1:
         raise CriticalError(1, 'Too few arguments.')
+    global meta_store
+    meta_store = PyTagsFileSystem.get_meta_store(values.metastores)
 
     if not (values.format or values.operations):
         return print_tags(args)


Follow ups

References