summaryrefslogtreecommitdiffstats
path: root/iutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'iutil.py')
-rw-r--r--iutil.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/iutil.py b/iutil.py
index 0cca8728a..5dd6e74d3 100644
--- a/iutil.py
+++ b/iutil.py
@@ -26,12 +26,8 @@ def getfd(filespec, readOnly = 0):
def execWithRedirect(command, argv, stdin = 0, stdout = 1, stderr = 2,
searchPath = 0, root = '/'):
stdin = getfd(stdin)
- if stdout == stderr:
- stdout = getfd(stdout)
- stderr = stdout
- else:
- stdout = getfd(stdout)
- stderr = getfd(stderr)
+ stdout = getfd(stdout)
+ stderr = getfd(stderr)
if not os.access (root + command, os.X_OK):
raise RuntimeError, command + " can not be run"
@@ -52,8 +48,7 @@ def execWithRedirect(command, argv, stdin = 0, stdout = 1, stderr = 2,
os.close(stdin)
if stdout != 1:
os.dup2(stdout, 1)
- if stdout != stderr:
- os.close(stdout)
+ os.close(stdout)
if stderr != 2:
os.dup2(stderr, 2)
os.close(stderr)
@@ -125,3 +120,26 @@ def memInstalled():
fields = string.split(mem)
return int(fields[1]) / 1024
+
+# this is a mkdir that won't fail if a directory already exists and will
+# happily make all of the directories leading up to it.
+def mkdirChain(dir):
+ if (os.path.isdir(dir)): return
+ elements = string.splitfields(dir, "/")
+
+ if (len(elements[0])):
+ which = 1
+ path = elements[0]
+ else:
+ which = 2
+ path = "/" + elements[1]
+
+ if (not os.path.isdir(path)):
+ os.mkdir(path, 0755)
+
+ while (which < len(elements)):
+ path = path + "/" + elements[which]
+ which = which + 1
+
+ if (not os.path.isdir(path)):
+ os.mkdir(path, 0755)