Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
rt-framework / rt / lib / utils / rt-filegen
Size: Mime:
#! /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 with a given size with random content"""

import os
import sys

# Write large files in chunks of this
MAX_WRITE = 64 * 1024


def usage(ret):
    sys.stderr.write('Usage: %s <size> <filename>\n' % sys.argv[0])
    sys.stderr.write('       <size> can be in hex too\n')
    sys.exit(ret)
    return


if not len(sys.argv) == 3:
    usage(-1)

size = int(sys.argv[1], 0)

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