← Back to team overview

pytagsfs team mailing list archive

Re: -o metastore option to pytags ?

 

On Thu, May 19, 2011 at 01:47:35PM +0200, Raphaël wrote:
> 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.

replying myself again:
As I (now) know that multiple metastores can be provided (separated with ';'),
here is an updated patch which use --metastores instead of --metastore

Raph

=== modified file 'modules/pytagsfs/pytags.py'
--- modules/pytagsfs/pytags.py	2011-04-29 20:19:25 +0000
+++ modules/pytagsfs/pytags.py	2011-05-22 12:56:01 +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[;BAR...]',
+            help = 'select the metastore(s) FOO and BAR',
+        )
 
     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