1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#!/bin/sh
"""": # -*-python-*-
bup_exec="$(dirname "$0")/bup-exec" || exit $?
exec "$bup_exec" "$0" ${1+"$@"}
"""
from __future__ import absolute_import, print_function
from os.path import abspath, dirname
from random import randint
from sys import stderr, stdout
import errno, re, sys
from bup.compat import fsencode, get_argv, get_argvb
argv = get_argv()
def usage(out=stdout):
print('Usage:', argv[0], 'NUM', 'DEST_DIR', file=out)
def misuse():
usage(stderr)
exit(2)
if sys.version_info[0] >= 3:
def bytes_from_ints(ints):
return bytes(ints)
else:
def bytes_from_ints(ints):
return ''.join([chr(x) for x in ints])
invalid_fragments = re.compile(br'(\x00|[./]|\.\.)')
def random_filename():
n = randint(1, 32)
def random_candidate():
return invalid_fragments.sub(b'', bytes_from_ints([randint(1, 255)
for x in range(n)]))
candidate = random_candidate()
while not candidate:
candidate = random_candidate()
return candidate
if len(argv) != 3:
misuse()
count, dest = get_argvb()[1:]
count = int(count)
i = 0
while i < count:
with open(dest + b'/' + random_filename(), 'w') as _:
i += 1
|