[PATCH 4/9] cr_tests: fs: A tool to re-fill a tree of dirs and files

Matt Helsley matthltc at us.ibm.com
Fri Feb 19 18:18:52 PST 2010


Signed-off-by: Matt Helsley <matthltc at us.ibm.com>
---
 fs/fill_tree.py |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)
 create mode 100755 fs/fill_tree.py

diff --git a/fs/fill_tree.py b/fs/fill_tree.py
new file mode 100755
index 0000000..28a3e55
--- /dev/null
+++ b/fs/fill_tree.py
@@ -0,0 +1,47 @@
+#!/usr/bin/python
+#
+# fill a tree with known contents.
+#
+import optparse
+import sys
+
+# for S_I* (e.g. S_IRWXU)
+from stat import *
+
+# For walk, path.join, open, unlink, close, and O_*
+from os import *
+
+# Root of the tree to check
+root = None
+
+# Like os.walk() but assumes root and followlinks = False
+# (which prevents likely-unwanted removal of files for the
+#  purposes of this test script)
+def rwalk(**kw):
+	kw['followlinks'] = False
+	return walk(root, **kw)
+
+# Alias path.join -> join
+def join(*args):
+	return path.join(*args)
+
+if __name__ == '__main__':
+	parser = optparse.OptionParser()
+	parser.add_option("-r", "--root", dest="root", type="string",
+			action="store", help="root of tree to hold and unlink")
+	parser.add_option("-c", "--content-tag", dest="content", type="string",
+			default="dummy", action="store",
+			help="tag for contents of the files (e.g. \"original\", \"dummy\")")
+	(options, args) = parser.parse_args()
+	root = path.abspath(options.root)
+	content = options.content
+
+	for (dirpath, dirnames, filenames) in rwalk():
+		for dir in dirnames:
+			chmod(join(dirpath, dir), S_IRWXU)
+		for fname in filenames:
+			f = join(dirpath, fname)
+			chmod(f, S_IRUSR|S_IWUSR)
+			fd = open(f, O_WRONLY|O_TRUNC)
+			write(fd, "%s contents of %s\n" % (content, f))
+			close(fd)
-- 
1.6.3.3



More information about the Containers mailing list