]> arthur.barton.de Git - bup.git/blob - cmd/random-cmd.py
cleanup-mounts-under: Don't fail when /proc/mounts isn't readable
[bup.git] / cmd / random-cmd.py
1 #!/usr/bin/env python
2 import sys
3 from bup import options, _helpers
4 from bup.helpers import *
5
6 optspec = """
7 bup random [-S seed] <numbytes>
8 --
9 S,seed=   optional random number seed [1]
10 f,force   print random data to stdout even if it's a tty
11 v,verbose print byte counter to stderr
12 """
13 o = options.Options(optspec)
14 (opt, flags, extra) = o.parse(sys.argv[1:])
15
16 if len(extra) != 1:
17     o.fatal("exactly one argument expected")
18
19 total = parse_num(extra[0])
20
21 handle_ctrl_c()
22
23 if opt.force or (not os.isatty(1) and
24                  not atoi(os.environ.get('BUP_FORCE_TTY')) & 1):
25     _helpers.write_random(sys.stdout.fileno(), total, opt.seed,
26                           opt.verbose and 1 or 0)
27 else:
28     log('error: not writing binary data to a terminal. Use -f to force.\n')
29     sys.exit(1)