diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2022-07-02 22:29:08 +0300 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2022-07-02 23:23:46 +0300 |
commit | 130b929a2c7d4fbc28bedcbdbac7214acdacf328 (patch) | |
tree | f108c485a2463e3a99524c5d5625a8d059d30a52 | |
parent | 78dc0051e7f53830f72c219c437a5b175906dfd2 (diff) |
Only remove empty subdirectories below a certain depth
'cygport upload/stage' assumes the existence of the '<arch>/release'
directories, so don't remove those, even if empty.
-rw-r--r-- | calm/utils.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/calm/utils.py b/calm/utils.py index f25e5f4..bafc5ff 100644 --- a/calm/utils.py +++ b/calm/utils.py @@ -58,12 +58,12 @@ def makedirs(name): # -# remove any empty subdirectories +# remove any empty subdirectories below a given depth # -def rmemptysubdirs(path): +def rmemptysubdirs(path, depth=3): for (dirpath, _subdirs, _files) in os.walk(path, topdown=False, followlinks=True): - # don't remove the given directory, only subdirectories - if os.path.relpath(dirpath, path) == '.': + # don't do anything while above the given depth + if len(os.path.relpath(dirpath, path).split(os.sep)) < depth: continue # check whether the directory is now empty after processing any |