]> arthur.barton.de Git - bup.git/blob - cmd-split.py
Initial version of 'bup save'.
[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 bench      print benchmark timings to stderr
14 """
15 o = options.Options('bup split', optspec)
16 (opt, flags, extra) = o.parse(sys.argv[1:])
17
18 if not (opt.blobs or opt.tree or opt.commit or opt.name):
19     log("bup split: use one or more of -b, -t, -c, -n\n")
20     o.usage()
21
22 start_time = time.time()
23
24 (shalist,tree) = hashsplit.split_to_tree(hashsplit.autofiles(extra))
25 if opt.blobs:
26     for (mode,name,sum) in shalist:
27         print sum
28 if opt.tree:
29     print tree
30 if opt.commit or opt.name:
31     msg = 'Generated by command:\n%r' % sys.argv
32     ref = opt.name and ('refs/heads/%s' % opt.name) or None
33     commit = git.gen_commit_easy(ref, tree, msg)
34     if opt.commit:
35         print commit
36
37 secs = time.time() - start_time
38 if opt.bench:
39     log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
40         % (ofs/1024., secs, ofs/1024./secs))