]> gitweb.michael.orlitzky.com - dead/census-tools.git/commitdiff
Added the FileUtils module.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 7 Oct 2009 14:58:13 +0000 (10:58 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 7 Oct 2009 14:58:13 +0000 (10:58 -0400)
src/FileUtils.py [new file with mode: 0644]

diff --git a/src/FileUtils.py b/src/FileUtils.py
new file mode 100644 (file)
index 0000000..2b89adf
--- /dev/null
@@ -0,0 +1,29 @@
+"""
+Utility functions for working with the filesystem, generally modeled
+after useful shell commands.
+"""
+
+import os
+
+
+def rm_f(path):
+    """
+    Remove (unlink) a file, ignoring any exceptions that may be
+    thrown.
+    """
+    try:
+        os.remove(path)
+    except:
+        pass
+
+
+def mkdir_p(path, mode):
+    """
+    Create a directory hierarchy, ignoring any exceptions that may be
+    thrown.
+    """
+    try:
+        os.makedirs(path, mode)
+    except:
+        pass
+