]> arthur.barton.de Git - bup.git/blob - cmd-split.py
bup split: print extra output to stderr if -v or -vv is given.
[bup.git] / cmd-split.py
1 #!/usr/bin/env python
2 import sys, time
3 import hashsplit, git, options
4 from helpers import *
5
6 optspec = """
7 bup split [-tcb] [-n name] [--bench] [filenames...]
8 --
9 b,blobs    output a series of blob ids
10 t,tree     output a tree id
11 c,commit   output a commit id
12 n,name=    name of backup set to update (if any)
13 v,verbose  increase log output (can be used more than once)
14 bench      print benchmark timings to stderr
15 """
16 o = options.Options('bup split', optspec)
17 (opt, flags, extra) = o.parse(sys.argv[1:])
18
19 if not (opt.blobs or opt.tree or opt.commit or opt.name):
20     log("bup split: use one or more of -b, -t, -c, -n\n")
21     o.usage()
22
23 hashsplit.split_verbosely = opt.verbose
24
25 start_time = time.time()
26
27 (shalist,tree) = hashsplit.split_to_tree(hashsplit.autofiles(extra))
28 if opt.blobs:
29     for (mode,name,sum) in shalist:
30         print sum
31 if opt.tree:
32     print tree
33 if opt.commit or opt.name:
34     msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
35     ref = opt.name and ('refs/heads/%s' % opt.name) or None
36     commit = git.gen_commit_easy(ref, tree, msg)
37     if opt.commit:
38         print commit
39
40 secs = time.time() - start_time
41 size = hashsplit.total_split
42 if opt.bench:
43     log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
44         % (size/1024., secs, size/1024./secs))