# HG changeset patch # User Emmanuel Gil Peyrot # Date 1345618974 -7200 # Node ID c40f0eed70cdc88157568991de676dabd1306064 # Parent 880904f1071f7a7dc5181e309c9f22bcb09dc499 Add a symlink mode, for performances reason. diff --git a/danboorufs.py b/danboorufs.py --- a/danboorufs.py +++ b/danboorufs.py @@ -41,7 +41,7 @@ class Danbooru(LoggingMixIn, Operations) Represent a list of images as a filesystem tree, with nice tag filtering. ''' - def __init__(self, tagfiles, root): + def __init__(self, tagfiles, root, use_symlinks): ''' Takes a list of files containing the tags. They have to be named as the image, with ".tags" at the end. @@ -73,6 +73,7 @@ class Danbooru(LoggingMixIn, Operations) print('[%d] Index done.' % (time() - start)) self.root = root + self.use_symlinks = use_symlinks self.rwlock = Lock() def _split_path(self, path): @@ -103,10 +104,18 @@ class Danbooru(LoggingMixIn, Operations) _, filename = self._split_path(path) path = filename if filename else self.root stat = os.lstat(path) - return dict((key, getattr(stat, key)) for key in ('st_atime', + stat = dict((key, getattr(stat, key)) for key in ('st_atime', 'st_ctime', 'st_gid', 'st_mode', 'st_mtime', 'st_nlink', 'st_size', 'st_uid')) + if self.use_symlinks: + # Those modes are respectively for a symlink and a directory. + stat['st_mode'] = 0o120700 if filename else 0o40700 + if filename: + stat['st_size'] = len(filename) + + return stat + getxattr = None listxattr = None @@ -157,7 +166,9 @@ class Danbooru(LoggingMixIn, Operations) self.cache[key] = list(taglist) + list(files) return ['.', '..'] + self.cache[key] - readlink = os.readlink + def readlink(self, path): + _, filename = self._split_path(path) + return filename def release(self, path, file_handle): return os.close(file_handle) @@ -173,12 +184,24 @@ class Danbooru(LoggingMixIn, Operations) utimens = os.utime +def main(args): + mountpoint = args.pop() + + if args[1] == '-s' or args[1] == '--use-symlinks': + use_symlinks = True + filelist = args[2:] + else: + use_symlinks = False + filelist = args[1:] + + FUSE(Danbooru(filelist, os.path.dirname(mountpoint), use_symlinks), + mountpoint, foreground=True) + + if __name__ == '__main__': if len(argv) < 3: - print('usage: %s [...] ' % argv[0]) + print('USAGE: %s' % argv[0], '[-s|--use-symlinks]', + ' [...]', '') exit(1) - mountpoint = argv.pop() - - fuse = FUSE(Danbooru(argv[1:], os.path.dirname(mountpoint)), mountpoint, - foreground=True) + main(argv)