changeset 6:2c81cc41de2d draft

Allow only a base directory for the tags, which will be recursively walked to find the actual tags files.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 02 Dec 2012 19:15:17 +0100
parents a422e75bf464
children 09945ce42e28
files danboorufs.py
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/danboorufs.py
+++ b/danboorufs.py
@@ -59,11 +59,13 @@ class Danbooru(LoggingMixIn, Operations)
             self.paths[basename] = filename
             tags = []
             self.files[basename] = tags
-            with open(name, 'r') as tagfile:
+            with open(name, 'rb') as tagfile:
                 for line in tagfile:
                     for tag in line.split():
                         try:
                             tag = tag.decode('UTF-8')
+                        except UnicodeDecodeError:
+                            continue
                         except AttributeError:
                             pass
                         tag = tag.replace('/', '�') #XXX
@@ -189,10 +191,17 @@ def main(args):
 
     if args[1] == '-n' or args[1] == '--no-symlinks':
         use_symlinks = False
-        filelist = args[1:]
+        directory = args[2]
     else:
         use_symlinks = True
-        filelist = args[2:]
+        directory = args[1]
+
+    filelist = []
+    start = time()
+    for (path, _, files) in os.walk(directory):
+        filelist.extend(os.path.join(path, filename) for filename in files
+                        if filename.endswith('.tags'))
+    print('[%d] Walk done.' % (time() - start))
 
     FUSE(Danbooru(filelist, os.path.dirname(mountpoint), use_symlinks),
          mountpoint, foreground=True)
@@ -201,7 +210,7 @@ def main(args):
 if __name__ == '__main__':
     if len(argv) < 3:
         print('USAGE: %s' % argv[0], '[-n|--no-symlinks]',
-              '<tag file> [<tag file>...]', '<mountpoint>')
+              '<tags directory>', '<mountpoint>')
         exit(1)
 
     main(argv)