summaryrefslogtreecommitdiff
path: root/bin/clean_old_injected_packages
diff options
context:
space:
mode:
authorBlackNoxis <steven.darklight@gmail.com>2014-12-03 03:20:49 +0200
committerBlackNoxis <steven.darklight@gmail.com>2014-12-03 03:20:49 +0200
commit58ae5bbf25835bd30fa385275ff4486dbc31f0a2 (patch)
tree3a68352e09b5cce3a8a33a7eef956e9d254d126e /bin/clean_old_injected_packages
Making public our Kogaion bin
Diffstat (limited to 'bin/clean_old_injected_packages')
-rwxr-xr-xbin/clean_old_injected_packages91
1 files changed, 91 insertions, 0 deletions
diff --git a/bin/clean_old_injected_packages b/bin/clean_old_injected_packages
new file mode 100755
index 0000000..03d4a94
--- /dev/null
+++ b/bin/clean_old_injected_packages
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+
+import sys
+sys.path.insert(0, "/usr/lib/matter")
+sys.path.insert(0, "/usr/lib/entropy/lib")
+
+import os
+
+from entropy.server.interfaces import Server
+from entropy.i18n import _
+
+from matter.spec import SpecParser
+import matter.binpms.entropysrv # plugin registration
+
+
+PARTICLES_DIR = "/particles"
+
+
+if __name__ == "__main__":
+
+ # collect particles
+ particles = []
+ for root, dirs, files in os.walk(PARTICLES_DIR):
+ for name in files:
+ if name.endswith(".particle"):
+ particles.append(os.path.join(root, name))
+
+ packages = set()
+ for particle in particles:
+ with open(particle, "r") as f:
+ spec = SpecParser(f)
+ data = spec.parse()
+ if not data:
+ continue
+
+ if data.get("build-only", "no") != "yes":
+ continue
+
+ drop_injected = data.get("drop-old-injected", "no") == "yes"
+ if not drop_injected:
+ continue
+ for p_packages in data.get("packages", []):
+ packages.update(p_packages)
+
+ packages = sorted(packages)
+
+ srv = Server()
+ for repository in srv.repositories():
+
+ repo = srv.open_repository(repository)
+ for package in packages:
+
+ latest_package_id, _mrc = repo.atomMatch(package)
+ if latest_package_id == -1:
+ continue
+
+ package_ids, _mrc = repo.atomMatch(package, multiMatch=True)
+ if not package_ids:
+ continue
+
+ key_slots = set()
+ for package_id in package_ids:
+ key, slot = repo.retrieveKeySlot(package_id)
+ key_slots.add((key, slot))
+
+ key_slot_package_ids = set()
+ for key, slot in key_slots:
+ ks_package_ids = [x for x in repo.searchKeySlot(key, slot) \
+ if repo.isInjected(x)]
+ key_slot_package_ids.update(ks_package_ids)
+
+ key_slot_package_ids.discard(latest_package_id)
+ if key_slot_package_ids:
+ key_slot_package_ids = sorted(key_slot_package_ids)
+ atoms = [repo.retrieveAtom(x) for x in key_slot_package_ids]
+ atoms.sort()
+
+ latest_atom = repo.retrieveAtom(latest_package_id)
+ srv.output("%s is the latest package" % (latest_atom))
+ srv.output("removing old packages:")
+ for atom in atoms:
+ srv.output(" %s" % (atom,))
+ resp = srv.ask_question("Really remove?")
+ if resp != _("Yes"):
+ continue
+
+ srv.remove_packages(
+ repository, key_slot_package_ids)
+ srv.commit_repositories()
+
+ srv.destroy()