]> arthur.barton.de Git - bup.git/blobdiff - cmd/save-cmd.py
Use the new qprogress() function in more places.
[bup.git] / cmd / save-cmd.py
index 62c1e426bb5bad665c41004fb9e71af99d1dc2d5..8c2ba40abe61382ea5a46ebf99f9fee007432842 100755 (executable)
@@ -19,8 +19,9 @@ bwlimit=   maximum bytes/sec to transmit to server
 f,indexfile=  the name of the index file (normally BUP_DIR/bupindex)
 strip      strips the path to every filename given
 strip-path= path-prefix to be stripped when saving
+graft=     a graft point *old_path*=*new_path* (can be used morethan once)
 """
-o = options.Options('bup save', optspec)
+o = options.Options(optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
 
 git.check_repo_or_die()
@@ -42,6 +43,22 @@ else:
 if opt.strip and opt.strip_path:
     o.fatal("--strip is incompatible with --strip-path")
 
+graft_points = []
+if opt.graft:
+    if opt.strip:
+        o.fatal("--strip is incompatible with --graft")
+
+    if opt.strip_path:
+        o.fatal("--strip-path is incompatible with --graft")
+
+    for (option, parameter) in flags:
+        if option == "--graft":
+            splitted_parameter = parameter.split('=')
+            if len(splitted_parameter) != 2:
+                o.fatal("a graft point must be of the form old_path=new_path")
+            graft_points.append((realpath(splitted_parameter[0]),
+                                 realpath(splitted_parameter[1])))
+
 is_reverse = os.environ.get('BUP_SERVER_REVERSE')
 if is_reverse and opt.remote:
     o.fatal("don't use -r in reverse mode; it's automatic")
@@ -90,9 +107,8 @@ def _pop(force_tree):
     return tree
 
 lastremain = None
-lastprint = 0
 def progress_report(n):
-    global count, subcount, lastremain, lastprint
+    global count, subcount, lastremain
     subcount += n
     cc = count + subcount
     pct = total and (cc*100.0/total) or 0
@@ -124,21 +140,12 @@ def progress_report(n):
             remainstr = '%dm%d' % (mins, secs)
         else:
             remainstr = '%ds' % secs
-    if now - lastprint > 0.1:
-        progress('Saving: %.2f%% (%d/%dk, %d/%d files) %s %s\r'
-                 % (pct, cc/1024, total/1024, fcount, ftotal,
-                    remainstr, kpsstr))
-        lastprint = now
-
-
-def vlog(s):
-    global lastprint
-    lastprint = 0
-    log(s)
+    qprogress('Saving: %.2f%% (%d/%dk, %d/%d files) %s %s\r'
+              % (pct, cc/1024, total/1024, fcount, ftotal,
+                 remainstr, kpsstr))
 
 
 indexfile = opt.indexfile or git.repo('bupindex')
-print indexfile
 r = index.Reader(indexfile)
 
 def already_saved(ent):
@@ -154,7 +161,7 @@ total = ftotal = 0
 if opt.progress:
     for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_pre):
         if not (ftotal % 10024):
-            progress('Reading index: %d\r' % ftotal)
+            qprogress('Reading index: %d\r' % ftotal)
         exists = ent.exists()
         hashvalid = already_saved(ent)
         ent.set_sha_missing(not hashvalid)
@@ -186,10 +193,10 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
         else:
             status = ' '
         if opt.verbose >= 2:
-            vlog('%s %-70s\n' % (status, ent.name))
+            log('%s %-70s\n' % (status, ent.name))
         elif not stat.S_ISDIR(ent.mode) and lastdir != dir:
             if not lastdir.startswith(dir):
-                vlog('%s %-70s\n' % (status, os.path.join(dir, '')))
+                log('%s %-70s\n' % (status, os.path.join(dir, '')))
             lastdir = dir
 
     if opt.progress:
@@ -210,6 +217,9 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
         dirp = stripped_base_path.split('/')
     elif opt.strip_path:
         dirp = strip_path(opt.strip_path, dir).split('/')
+    elif graft_points:
+        grafted = graft_path(graft_points, dir)
+        dirp = grafted.split('/')
     else:
         dirp = dir.split('/')
     while parts > dirp: