* Added functions: is_executable_file() and path_split_all().

master
Wirawan Purwanto 11 years ago
parent a33ad3c766
commit 5ce6e86b43
  1. 13
      shell_tools.py

@ -42,6 +42,13 @@ def file_exists_nonempty(path):
nonzero size.""" nonzero size."""
return os.path.isfile(path) and os.stat(path).st_size > 0 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): def provide_link(dest, src):
"""Checks if file `dest' exists. If it does not, provide for it by means """Checks if file `dest' exists. If it does not, provide for it by means
of a softlink from `src'.""" of a softlink from `src'."""
@ -78,6 +85,12 @@ def relpath(p1, p2):
# /// end code snippet # /// 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: # Globbing utilities:

Loading…
Cancel
Save