X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cmd%2Frandom-cmd.py;h=868c3afd3fcebf2a775bc7e5e5a0b63dfd31239b;hb=00fb1f1b2a53935ca7d5ce95ea4cf56b7f9bcc3d;hp=9a24face2598f27ab81bfee007fa2bef7365315d;hpb=2ff672c48f3dbde761b30775adcdc76a621df527;p=bup.git diff --git a/cmd/random-cmd.py b/cmd/random-cmd.py index 9a24fac..868c3af 100755 --- a/cmd/random-cmd.py +++ b/cmd/random-cmd.py @@ -1,15 +1,24 @@ -#!/usr/bin/env python -import sys -from bup import options, _faster -from bup.helpers import * +#!/bin/sh +"""": # -*-python-*- +bup_python="$(dirname "$0")/bup-python" || exit $? +exec "$bup_python" "$0" ${1+"$@"} +""" +# end of bup preamble + +import os, sys + +from bup import options, _helpers +from bup.helpers import atoi, handle_ctrl_c, log, parse_num + optspec = """ bup random [-S seed] -- S,seed= optional random number seed [1] f,force print random data to stdout even if it's a tty +v,verbose print byte counter to stderr """ -o = options.Options('bup random', optspec) +o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) if len(extra) != 1: @@ -21,7 +30,8 @@ handle_ctrl_c() if opt.force or (not os.isatty(1) and not atoi(os.environ.get('BUP_FORCE_TTY')) & 1): - _faster.write_random(sys.stdout.fileno(), total, opt.seed) + _helpers.write_random(sys.stdout.fileno(), total, opt.seed, + opt.verbose and 1 or 0) else: log('error: not writing binary data to a terminal. Use -f to force.\n') sys.exit(1)