-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrt-filerandgen
More file actions
executable file
·39 lines (30 loc) · 918 Bytes
/
rt-filerandgen
File metadata and controls
executable file
·39 lines (30 loc) · 918 Bytes
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
#! /usr/bin/env python
#
# Copyright (C) 2016 Rolf Neugebauer <rolf.neugebauer@docker.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
"""Generate a file of random size with random content"""
import os
import sys
import random
# Write large files in chunks of this
MAX_WRITE = 64 * 1024
def usage(ret):
sys.stderr.write('Usage: %s <maxsize> <filename>\n' % sys.argv[0])
sys.stderr.write(' <maxsize> can be in hex too\n')
sys.exit(ret)
return
if not len(sys.argv) == 3:
usage(-1)
max_size = int(sys.argv[1], 0)
size = random.randrange(1, max_size)
with open(sys.argv[2], 'wb') as f:
while size:
b = size if size < MAX_WRITE else MAX_WRITE
f.write(os.urandom(b))
size -= b