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()
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")
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
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):
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)
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:
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: