diff options
author | ben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2002-03-21 07:22:43 +0000 |
---|---|---|
committer | ben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2002-03-21 07:22:43 +0000 |
commit | 8c37a5bdfdd46d5cfad6e9d67925ddef9ca382bf (patch) | |
tree | 8f19be83962ef31d8ad58429d575c6f17d89c0ea /rdiff-backup/misc/init_files.py | |
parent | 8259a0d8a9ad1396a93cd6320943dc33446ac6ed (diff) | |
download | rdiff-backup-8c37a5bdfdd46d5cfad6e9d67925ddef9ca382bf.tar.gz |
First checkin
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@2 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/misc/init_files.py')
-rwxr-xr-x | rdiff-backup/misc/init_files.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/rdiff-backup/misc/init_files.py b/rdiff-backup/misc/init_files.py new file mode 100755 index 0000000..1d8651a --- /dev/null +++ b/rdiff-backup/misc/init_files.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +"""init_smallfiles.py + +This program makes a number of files of the given size in the +specified directory. + +""" + +import os, stat, sys, math + +if len(sys.argv) > 5 or len(sys.argv) < 4: + print "Usage: init_files [directory name] [file size] [file count] [base]" + print + print "Creates file_count files in directory_name of size file_size." + print "The created directory has a tree type structure where each level" + print "has at most base files or directories in it. Default is 50." + sys.exit(1) + +dirname = sys.argv[1] +filesize = int(sys.argv[2]) +filecount = int(sys.argv[3]) +block_size = 16384 +block = "." * block_size +block_change = "." * (filesize % block_size) +if len(sys.argv) == 4: base = 50 +else: base = int(sys.argv[4]) + +def make_file(path): + """Make the file at path""" + fp = open(path, "w") + for i in xrange(int(math.floor(filesize/block_size))): fp.write(block) + fp.write(block_change) + fp.close() + +def find_sublevels(count): + """Return number of sublevels required for count files""" + return int(math.ceil(math.log(count)/math.log(base))) + +def make_dir(dir, count): + """Make count files in the directory, making subdirectories if necessary""" + print "Making directory %s with %d files" % (dir, count) + os.mkdir(dir) + level = find_sublevels(count) + assert count <= pow(base, level) + if level == 1: + for i in range(count): make_file(os.path.join(dir, "file%d" %i)) + else: + files_per_subdir = pow(base, level-1) + full_dirs = int(count/files_per_subdir) + assert full_dirs <= base + for i in range(full_dirs): + make_dir(os.path.join(dir, "subdir%d" % i), files_per_subdir) + + change = count - full_dirs*files_per_subdir + assert change >= 0 + if change > 0: + make_dir(os.path.join(dir, "subdir%d" % full_dirs), change) + +def start(dir): + try: os.stat(dir) + except os.error: pass + else: + print "Directory %s already exists, exiting." % dir + sys.exit(1) + + make_dir(dirname, filecount) + +start(dirname) |