]> arthur.barton.de Git - bup.git/commitdiff
fuse: add --verbose argument and use it
authorRob Browning <rlb@defaultvalue.org>
Sun, 28 Feb 2016 16:14:46 +0000 (10:14 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sun, 13 Mar 2016 23:03:19 +0000 (18:03 -0500)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
Documentation/bup-fuse.md
cmd/fuse-cmd.py

index cc2423a9c22b5b4f6188611380ce90e3cfbe49da..ed6f5b8a66f2790f6982aaa82d89dcdef454e848 100644 (file)
@@ -47,6 +47,9 @@ should unmount it with `umount`(8).
     performance, and note that any timestamps before 1970-01-01 UTC
     (i.e. before the Unix epoch) will be presented as 1970-01-01 UTC.
 
+-v, \--verbose
+:   increase verbosity (can be used more than once).
+
 # EXAMPLES
     rm -rf /tmp/buptest
     mkdir /tmp/buptest
index df9bf56fa399739cf9a70c3fe6216e1197ba9448..f2776e54853c60ddc0293ce48911ba4a5b59308c 100755 (executable)
@@ -8,7 +8,7 @@ exec "$bup_python" "$0" ${1+"$@"}
 import sys, os, errno
 
 from bup import options, git, vfs, xstat
-from bup.helpers import log
+from bup.helpers import buglvl, log
 
 try:
     import fuse
@@ -40,33 +40,38 @@ def cache_get(top, path):
     cache[('',)] = top
     c = None
     max = len(parts)
-    #log('cache: %r\n' % cache.keys())
+    if buglvl >= 1:
+        log('cache: %r\n' % cache.keys())
     for i in range(max):
         pre = parts[:max-i]
-        #log('cache trying: %r\n' % pre)
+        if buglvl >= 1:
+            log('cache trying: %r\n' % pre)
         c = cache.get(tuple(pre))
         if c:
             rest = parts[max-i:]
             for r in rest:
-                #log('resolving %r from %r\n' % (r, c.fullname()))
+                if buglvl >= 1:
+                    log('resolving %r from %r\n' % (r, c.fullname()))
                 c = c.lresolve(r)
                 key = tuple(pre + [r])
-                #log('saving: %r\n' % (key,))
+                if buglvl >= 1:
+                    log('saving: %r\n' % (key,))
                 cache[key] = c
             break
     assert(c)
     return c
-        
-    
+
 
 class BupFs(fuse.Fuse):
-    def __init__(self, top, meta=False):
+    def __init__(self, top, meta=False, verbose=0):
         fuse.Fuse.__init__(self)
         self.top = top
         self.meta = meta
+        self.verbose = verbose
     
     def getattr(self, path):
-        log('--getattr(%r)\n' % path)
+        if self.verbose > 0:
+            log('--getattr(%r)\n' % path)
         try:
             node = cache_get(self.top, path)
             st = Stat()
@@ -87,7 +92,8 @@ class BupFs(fuse.Fuse):
             return -errno.ENOENT
 
     def readdir(self, path, offset):
-        log('--readdir(%r)\n' % path)
+        if self.verbose > 0:
+            log('--readdir(%r)\n' % path)
         node = cache_get(self.top, path)
         yield fuse.Direntry('.')
         yield fuse.Direntry('..')
@@ -95,12 +101,14 @@ class BupFs(fuse.Fuse):
             yield fuse.Direntry(sub.name)
 
     def readlink(self, path):
-        log('--readlink(%r)\n' % path)
+        if self.verbose > 0:
+            log('--readlink(%r)\n' % path)
         node = cache_get(self.top, path)
         return node.readlink()
 
     def open(self, path, flags):
-        log('--open(%r)\n' % path)
+        if self.verbose > 0:
+            log('--open(%r)\n' % path)
         node = cache_get(self.top, path)
         accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
         if (flags & accmode) != os.O_RDONLY:
@@ -108,10 +116,12 @@ class BupFs(fuse.Fuse):
         node.open()
 
     def release(self, path, flags):
-        log('--release(%r)\n' % path)
+        if self.verbose > 0:
+            log('--release(%r)\n' % path)
 
     def read(self, path, size, offset):
-        log('--read(%r)\n' % path)
+        if self.verbose > 0:
+            log('--read(%r)\n' % path)
         n = cache_get(self.top, path)
         o = n.open()
         o.seek(offset)
@@ -126,10 +136,11 @@ fuse.fuse_python_api = (0, 2)
 optspec = """
 bup fuse [-d] [-f] <mountpoint>
 --
-d,debug   increase debug level
 f,foreground  run in foreground
+d,debug       run in the foreground and display FUSE debug information
 o,allow-other allow other users to access the filesystem
 meta          report original metadata for paths when available
+v,verbose     increase log output (can be used more than once)
 """
 o = options.Options(optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
@@ -139,7 +150,7 @@ if len(extra) != 1:
 
 git.check_repo_or_die()
 top = vfs.RefList(None)
-f = BupFs(top, meta=opt.meta)
+f = BupFs(top, meta=opt.meta, verbose=opt.verbose)
 f.fuse_args.mountpoint = extra[0]
 if opt.debug:
     f.fuse_args.add('debug')