From 5ce6e86b43a68ed079af50328df3925a226e40c6 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Wed, 15 Jan 2014 16:37:29 -0500 Subject: [PATCH] * Added functions: is_executable_file() and path_split_all(). --- shell_tools.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/shell_tools.py b/shell_tools.py index 1d2bec4..c7f20d7 100644 --- a/shell_tools.py +++ b/shell_tools.py @@ -42,6 +42,13 @@ def file_exists_nonempty(path): nonzero size.""" return os.path.isfile(path) and os.stat(path).st_size > 0 +def is_executable_file(path): + """Determines whether a file exists and is executable. + This implements the "-x" action of the shell's test command. + """ + # Ref: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python + return os.path.isfile(path) and os.access(path, os.X_OK) + def provide_link(dest, src): """Checks if file `dest' exists. If it does not, provide for it by means of a softlink from `src'.""" @@ -78,6 +85,12 @@ def relpath(p1, p2): # /// end code snippet +def path_split_all(p): + """Completely decompose a filename path into individual components + that can be rejoined later. + """ + return _pathsplit(p) + # Globbing utilities: