]> arthur.barton.de Git - bup.git/blob - cmd-split.py
Refactored client stuff into client.py; now cmd-save and cmd-init use it too.
[bup.git] / cmd-split.py
1 #!/usr/bin/env python2.5
2 import sys, time, struct
3 import hashsplit, git, options, client
4 from helpers import *
5 from subprocess import PIPE
6
7
8 optspec = """
9 bup split [-tcb] [-n name] [--bench] [filenames...]
10 --
11 r,remote=  remote repository path
12 b,blobs    output a series of blob ids
13 t,tree     output a tree id
14 c,commit   output a commit id
15 n,name=    name of backup set to update (if any)
16 v,verbose  increase log output (can be used more than once)
17 bench      print benchmark timings to stderr
18 """
19 o = options.Options('bup split', optspec)
20 (opt, flags, extra) = o.parse(sys.argv[1:])
21
22 git.check_repo_or_die()
23 if not (opt.blobs or opt.tree or opt.commit or opt.name):
24     log("bup split: use one or more of -b, -t, -c, -n\n")
25     o.usage()
26
27 hashsplit.split_verbosely = opt.verbose
28 if opt.verbose >= 2:
29     git.verbose = opt.verbose - 1
30     opt.bench = 1
31
32 start_time = time.time()
33
34 if opt.remote:
35     cli = client.Client(opt.remote)
36     cli.sync_indexes()
37     w = cli.new_packwriter()
38 else:
39     cli = None
40     w = git.PackWriter()
41     
42 (shalist,tree) = hashsplit.split_to_tree(w, hashsplit.autofiles(extra))
43
44 if opt.verbose:
45     log('\n')
46 if opt.blobs:
47     for (mode,name,bin) in shalist:
48         print bin.encode('hex')
49 if opt.tree:
50     print tree.encode('hex')
51 if opt.commit or opt.name:
52     msg = 'bup split\n\nGenerated by command:\n%r' % sys.argv
53     ref = opt.name and ('refs/heads/%s' % opt.name) or None
54     commit = w.new_commit(ref, tree, msg)
55     if opt.commit:
56         print commit.encode('hex')
57
58 w.close()
59 if cli:
60     cli.close()
61
62 secs = time.time() - start_time
63 size = hashsplit.total_split
64 if opt.bench:
65     log('\nbup: %.2fkbytes in %.2f secs = %.2f kbytes/sec\n'
66         % (size/1024., secs, size/1024./secs))