]> arthur.barton.de Git - bup.git/blob - cmd/random-cmd.py
Rename _faster.so to _helpers.so.
[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 """
12 o = options.Options('bup random', optspec)
13 (opt, flags, extra) = o.parse(sys.argv[1:])
14
15 if len(extra) != 1:
16     o.fatal("exactly one argument expected")
17
18 total = parse_num(extra[0])
19
20 handle_ctrl_c()
21
22 if opt.force or (not os.isatty(1) and
23                  not atoi(os.environ.get('BUP_FORCE_TTY')) & 1):
24     _helpers.write_random(sys.stdout.fileno(), total, opt.seed)
25 else:
26     log('error: not writing binary data to a terminal. Use -f to force.\n')
27     sys.exit(1)