New gen_misc makedirs/chdir functions
Change-Id: Ib62a2e87d48ddaed58a9ddfe6618bab6d193234f
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/gen_misc.py b/lib/gen_misc.py
index b6851ec..7651937 100755
--- a/lib/gen_misc.py
+++ b/lib/gen_misc.py
@@ -51,6 +51,43 @@
return os.path.normpath(dir_path) + os.path.sep
+def makedirs(path, mode=0o777, quiet=None):
+ r"""
+ Call os.makedirs with the caller's arguments.
+
+ This function offers 2 advantages over the base os.makedirs function:
+ 1) It will not fail if the directory already exists.
+ 2) It will print an "Issuing: os.makedirs" message.
+
+ Description of argument(s):
+ path The path containing the directories to be created.
+ mode The mode or permissions to be granted to the created directories.
+ quiet Indicates whether this function should run the print_issuing() function.
+ """
+ quiet = int(dft(quiet, gp.get_stack_var('quiet', 0)))
+ gp.qprint_issuing("os.makedirs('" + path + "', mode=" + oct(mode) + ")")
+ try:
+ os.makedirs(path, mode)
+ except FileExistsError:
+ pass
+
+
+def chdir(path, quiet=None):
+ r"""
+ Call os.chdir with the caller's arguments.
+
+ This function offers this advantage over the base os.chdir function:
+ - It will print an "Issuing: os.chdir" message.
+
+ Description of argument(s):
+ path The path of the directory to change to.
+ quiet Indicates whether this function should run the print_issuing() function.
+ """
+ quiet = int(dft(quiet, gp.get_stack_var('quiet', 0)))
+ gp.qprint_issuing("os.chdir('" + path + "')")
+ os.chdir(path)
+
+
def which(file_path):
r"""
Find the full path of an executable file and return it.