def make_files(p, count): for i in range(0, count): name = os.path.join(p, '%d' % (i)) with open(name, 'wb') as f: for _ in range(0, nblocks): f.write(block) if partial_size: f.write(partial_block)
def make_tree(p, d): if d > depth: return if not os.path.isdir(p): os.mkdir(p) if count: make_files(p, count) for i in range(0, width): make_tree('%s/d%d' % (p, i), d + 1)
def create_files(self, path, count=1, size=0, depth=0, width=0, fill='zero'): """ Create a directory tree of test files. path destination path count number of files to create in each directory size size of each file depth sub-directory depth width number of sub-directories in each directory fill test files data pattern Valid fill values: * zero - fill with zero bits * one - fill with one bits * random - fill with pseudo random bits * fixed - fill with repetitions of fixed bits """ BLOCKSIZE = 8192 count = int(count) size = int(size) depth = int(depth) width = int(width) if fill == 'zero': block = bytearray(BLOCKSIZE) elif fill == 'one': block = bytearray(BLOCKSIZE) elif fill == 'random': random.seed(0) # Always make the same psuedo random sequence. block = bytearray(random.getrandbits(8) for _ in range(BLOCKSIZE)) elif fill == 'fixed': hexstring = 'deadbeef' ncopies = BLOCKSIZE // len(hexstring) block = bytearray.fromhex(hexstring * ncopies) else: raise ValueError("Invalid fill type: %s" % fill) nblocks = size // BLOCKSIZE partial_size = size % BLOCKSIZE if partial_size: partial_block = block[0:partial_size] def make_files(p, count): for i in range(0, count): name = os.path.join(p, '%d' % (i)) with open(name, 'wb') as f: for _ in range(0, nblocks): f.write(block) if partial_size: f.write(partial_block) def make_tree(p, d): if d > depth: return if not os.path.isdir(p): os.mkdir(p) if count: make_files(p, count) for i in range(0, width): make_tree('%s/d%d' % (p, i), d + 1) make_tree(path, 0)