X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/6e83f4d7c39b981146f57aad8049c5622799dd00..254d99f846f3427d21bc9224cd693bb4806d2d31:/stgit/utils.py diff --git a/stgit/utils.py b/stgit/utils.py index 68b8f58..67431ec 100644 --- a/stgit/utils.py +++ b/stgit/utils.py @@ -109,6 +109,12 @@ def strip_prefix(prefix, string): assert string.startswith(prefix) return string[len(prefix):] +def strip_suffix(suffix, string): + """Return string, without the suffix. Blow up if string doesn't + end with suffix.""" + assert string.endswith(suffix) + return string[:-len(suffix)] + def remove_dirs(basedir, dirs): """Starting at join(basedir, dirs), remove the directory if empty, and try the same with its parent, until we find a nonempty @@ -130,7 +136,7 @@ def remove_file_and_dirs(basedir, file): def create_dirs(directory): """Create the given directory, if the path doesn't already exist.""" - if directory: + if directory and not os.path.isdir(directory): create_dirs(os.path.dirname(directory)) try: os.mkdir(directory)