[llvm-commits] [zorg] r141404 - /zorg/trunk/lnt/lnt/testing/util/commands.py

Daniel Dunbar daniel at zuster.org
Fri Oct 7 12:55:13 PDT 2011


Author: ddunbar
Date: Fri Oct  7 14:55:13 2011
New Revision: 141404

URL: http://llvm.org/viewvc/llvm-project?rev=141404&view=rev
Log:
lnt.testing.util.commands: Add an mkdir_p utility command.

Modified:
    zorg/trunk/lnt/lnt/testing/util/commands.py

Modified: zorg/trunk/lnt/lnt/testing/util/commands.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/testing/util/commands.py?rev=141404&r1=141403&r2=141404&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/testing/util/commands.py (original)
+++ zorg/trunk/lnt/lnt/testing/util/commands.py Fri Oct  7 14:55:13 2011
@@ -31,6 +31,25 @@
         if e.errno != errno.ENOENT:
             raise
 
+def mkdir_p(path):
+    """mkdir_p(path) - Make the "path" directory, if it does not exist; this
+    will also make directories for any missing parent directories."""
+    import errno
+
+    if not path or os.path.exists(path):
+        return
+
+    parent = os.path.dirname(path) 
+    if parent != path:
+        mkdir_p(parent)
+
+    try:
+        os.mkdir(path)
+    except OSError,e:
+        # Ignore EEXIST, which may occur during a race condition.
+        if e.errno != errno.EEXIST:
+            raise
+
 def capture(args, include_stderr=False):
     import subprocess
     """capture(command) - Run the given command (or argv list) in a shell and





More information about the llvm-commits mailing list