Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/cygwin-apps/calm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2022-06-09 18:20:14 +0300
committerJon Turney <jon.turney@dronecode.org.uk>2022-06-14 18:35:16 +0300
commit1a74d4efd3a4d56d8b42f605f2c4b48afeb2da57 (patch)
tree1f022b99811679052ae186d97795ce0cbb0c6074
parent234c197298d83040db5ebd48628fbda7bd98668c (diff)
Remove empty subdirectories
Remove empty subdirectories in release and upload areas.
-rwxr-xr-xcalm/calm.py8
-rw-r--r--calm/utils.py16
-rw-r--r--test/testdata/process_arch/homedir.expected2
3 files changed, 24 insertions, 2 deletions
diff --git a/calm/calm.py b/calm/calm.py
index 63cdc60..c0d756a 100755
--- a/calm/calm.py
+++ b/calm/calm.py
@@ -126,6 +126,10 @@ def process_relarea(args, state):
logging.error("error while evaluating stale packages")
return None
+ # clean up any empty directories
+ if not args.dryrun:
+ utils.rmemptysubdirs(args.rel_area)
+
return packages
@@ -264,6 +268,10 @@ def process_maintainer_uploads(args, state, all_packages, m):
# use merged package list
state.packages[arch] = merged_packages[arch]
+ # clean up any empty directories
+ if not args.dryrun:
+ utils.rmemptysubdirs(m.homedir())
+
# report what we've done
added = []
for arch in common_constants.ARCHES + ['noarch', 'src']:
diff --git a/calm/utils.py b/calm/utils.py
index 14bd517..f25e5f4 100644
--- a/calm/utils.py
+++ b/calm/utils.py
@@ -58,6 +58,22 @@ def makedirs(name):
#
+# remove any empty subdirectories
+#
+def rmemptysubdirs(path):
+ 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) == '.':
+ continue
+
+ # check whether the directory is now empty after processing any
+ # subdirectories, and if so, remove it
+ if len(os.listdir(dirpath)) == 0:
+ logging.debug('rmdir %s' % dirpath)
+ os.rmdir(dirpath)
+
+
+#
# a wrapper for open() which:
#
# - atomically changes the file contents (atomic)
diff --git a/test/testdata/process_arch/homedir.expected b/test/testdata/process_arch/homedir.expected
index 5804575..0e6408e 100644
--- a/test/testdata/process_arch/homedir.expected
+++ b/test/testdata/process_arch/homedir.expected
@@ -11,13 +11,11 @@
'Blooey McFooey/x86/release/not-on-package-list': ['not-on-package-list-1.0-1.tar.bz2', 'setup.hint'],
'Blooey McFooey/x86/release/not-ready': ['-not-ready-0.9-1.tar.bz2', 'not-ready-1.0-1.tar.bz2', 'setup.hint'],
'Blooey McFooey/x86/release/per-version': ['per-version-5.0-1-src.hint.bak'],
- 'Blooey McFooey/x86/release/per-version-replacement-hint-only': [],
'Blooey McFooey/x86/release/testpackage': ['testpackage-1.0-1-src.hint.bak'],
'Blooey McFooey/x86/release/testpackage-zstd': ['testpackage-zstd-1.0-1-src.hint',
'testpackage-zstd-1.0-1-src.tar.zst',
'testpackage-zstd-1.0-1.hint',
'testpackage-zstd-1.0-1.tar.zst'],
- 'Blooey McFooey/x86/release/testpackage/testpackage-subpackage': [],
'Blooey McFooey/x86/release/testpackage2': ['setup.hint', 'testpackage2-1.0-1.tar.bz2'],
'Blooey McFooey/x86/release/testpackage2/testpackage2-subpackage': ['inprogress.SftpXFR.1234',
'setup.hint',