]> arthur.barton.de Git - bup.git/blob - cmd/random-cmd.py
Configure python, use it, and embed during install
[bup.git] / cmd / random-cmd.py
1 #!/bin/sh
2 """": # -*-python-*-
3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
5 """
6 # end of bup preamble
7 import sys
8 from bup import options, _helpers
9 from bup.helpers import *
10
11 optspec = """
12 bup random [-S seed] <numbytes>
13 --
14 S,seed=   optional random number seed [1]
15 f,force   print random data to stdout even if it's a tty
16 v,verbose print byte counter to stderr
17 """
18 o = options.Options(optspec)
19 (opt, flags, extra) = o.parse(sys.argv[1:])
20
21 if len(extra) != 1:
22     o.fatal("exactly one argument expected")
23
24 total = parse_num(extra[0])
25
26 handle_ctrl_c()
27
28 if opt.force or (not os.isatty(1) and
29                  not atoi(os.environ.get('BUP_FORCE_TTY')) & 1):
30     _helpers.write_random(sys.stdout.fileno(), total, opt.seed,
31                           opt.verbose and 1 or 0)
32 else:
33     log('error: not writing binary data to a terminal. Use -f to force.\n')
34     sys.exit(1)