Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/devbot
diff options
context:
space:
mode:
Diffstat (limited to 'devbot')
-rw-r--r--devbot/distro.py54
-rw-r--r--devbot/system.py33
2 files changed, 86 insertions, 1 deletions
diff --git a/devbot/distro.py b/devbot/distro.py
index fe2522d..a08218f 100644
--- a/devbot/distro.py
+++ b/devbot/distro.py
@@ -9,6 +9,51 @@ class FedoraPackageManager:
command.run_with_sudo(args)
+ def remove_packages(self, packages):
+ args = ["rpm", "-e"]
+ args.extend(packages)
+
+ command.run_with_sudo(args)
+
+ def update(self):
+ command.run_with_sudo(["yum", "update"])
+
+ def find_all(self):
+ query_format = "--queryformat=[%{NAME} ]"
+ all = subprocess.check_output(["rpm", "-qa", query_format]).strip()
+ return all.split(" ")
+
+ def find_with_deps(self, packages):
+ result = []
+
+ for package in packages:
+ if package not in result:
+ result.append(package)
+
+ self._find_deps(package, result)
+
+ return result
+
+ def _find_deps(self, package, result):
+ query_format = "--queryformat=[%{REQUIRENAME} ]"
+ capabilities = subprocess.check_output(["rpm", "-q",
+ query_format,
+ package]).strip()
+
+ for capability in capabilities.strip().split(" "):
+ if capability.startswith("rpmlib"):
+ continue
+ query_format = "--queryformat=[%{NAME} ]"
+ deps_packages = subprocess.check_output(["rpm", "-q",
+ query_format,
+ "--whatprovides",
+ capability]).strip()
+
+ for dep_package in deps_packages.split(" "):
+ if dep_package not in result:
+ result.append(dep_package)
+ self._find_deps(dep_package, result)
+
class UbuntuPackageManager:
def install_packages(self, packages):
args = ["apt-get", "install"]
@@ -16,6 +61,15 @@ class UbuntuPackageManager:
command.run_with_sudo(args)
+ def remove_packages(self, packages):
+ raise NotImplementedError
+
+ def update(self):
+ raise NotImplementedError
+
+ def find_with_deps(package_names):
+ raise NotImplementedError
+
def get_package_manager():
name, version = _get_distro_info()
diff --git a/devbot/system.py b/devbot/system.py
index aa8d3f8..48f33a0 100644
--- a/devbot/system.py
+++ b/devbot/system.py
@@ -148,7 +148,31 @@ def warn_if_unsupported(distro_name):
"distributions listed in the README.\n" \
"*********************************************************\n"
-def check():
+def autoremove_packages(packages):
+ package_manager = distro.get_package_manager()
+
+ to_keep = []
+ for package_info in packages.values():
+ if distro_name in package_info:
+ package_list = package_info[distro_name]
+ if not isinstance(package_list, list):
+ package_list = [package_list]
+
+ for package in package_list:
+ if package_info[distro_name] not in to_keep:
+ to_keep.append(package_info[distro_name])
+
+ to_keep = package_manager.find_with_deps(to_keep)
+ all = package_manager.find_all()
+
+ to_remove = []
+ for package in all:
+ if package not in to_keep:
+ to_remove.append(package)
+
+ package_manager.remove_packages(to_remove)
+
+def check(autoremove=False, autoupdate=False):
distro_name = distro.get_distro_name()
packages = config.load_packages()
@@ -165,3 +189,10 @@ def check():
apply_distro_tweaks(distro_name)
stop_xvfb(xvfb_proc, orig_display)
+
+ if autoupdate:
+ package_manager = distro.get_package_manager()
+ package_manager.update()
+
+ if autoremove:
+ autoremove_packages(packages)