diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2020-07-19 18:02:59 +0300 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2020-07-19 19:47:15 +0300 |
commit | e79064972edfad6a12fe0a27e8dceb63fe5550dc (patch) | |
tree | 42b4a812d87abaabf49da029b0ecc1ca68e9f04c | |
parent | 2f15254c8bfb477a78ab15102c9844d542f42e36 (diff) |
package.delete() also deletes empty packages
Once a Package object no longer contains any files (archives or hints),
it can be removed from the package set.
(This fixes calm complaining when it wants to vault a stale package
which had source, but no kept version does. Otherwise it complains that
the source package has no versions)
Also remove removed hints from version_hints, since we iterate over that
in some places. This also prevents removed versions from bogusly
appearing in packages.json, so update test data appropriately.
-rwxr-xr-x | calm/package.py | 12 | ||||
-rw-r--r-- | test/testdata/process_arch/packages.json.expected | 5 |
2 files changed, 12 insertions, 5 deletions
diff --git a/calm/package.py b/calm/package.py index a1fed9a..2d115c2 100755 --- a/calm/package.py +++ b/calm/package.py @@ -1290,7 +1290,9 @@ def merge(a, *l): # def delete(packages, path, fn): + ex_packages = [] (_, _, pkgpath) = path.split(os.sep, 2) + for p in packages: if packages[p].pkgpath == pkgpath: for vr in packages[p].tars: @@ -1306,8 +1308,18 @@ def delete(packages, path, fn): for h in packages[p].hints: if packages[p].hints[h].fn == fn: del packages[p].hints[h] + del packages[p].version_hints[h] break + # if nothing remains, also remove from package set + if not packages[p].vermap and not packages[p].hints: + ex_packages.append(p) + + # (modify package set outside of iteration over it) + for p in ex_packages: + logging.info("removing package '%s' for package set" % (p)) + del packages[p] + # # verify that the package path starts with a package in the list of packages diff --git a/test/testdata/process_arch/packages.json.expected b/test/testdata/process_arch/packages.json.expected index f639e3c..05e4168 100644 --- a/test/testdata/process_arch/packages.json.expected +++ b/test/testdata/process_arch/packages.json.expected @@ -282,7 +282,6 @@ ' "summary": "Perl distribution Net-SMTP-SSL",\n' ' "versions": {\n' ' "stable": [\n' - ' "1.01-1",\n' ' "1.02-1",\n' ' "1.03-1",\n' ' "1.03-2"\n' @@ -330,13 +329,10 @@ ' "summary": "Test package for stale version removal",\n' ' "versions": {\n' ' "stable": [\n' - ' "240-1",\n' - ' "242-0",\n' ' "243-0",\n' ' "250-0"\n' ' ],\n' ' "test": [\n' - ' "251-0",\n' ' "260-0"\n' ' ]\n' ' }\n' @@ -430,7 +426,6 @@ ' "summary": "A test package",\n' ' "versions": {\n' ' "stable": [\n' - ' "0.1-1",\n' ' "1.0-1"\n' ' ]\n' ' }\n' |