diff options
author | Joel Andres Granados <jgranado@redhat.com> | 2008-07-15 21:53:31 +0200 |
---|---|---|
committer | Joel Andres Granados <jgranado@redhat.com> | 2008-07-15 22:08:47 +0200 |
commit | e22490465c43b9b223a6c5ca945d3a7d271c5717 (patch) | |
tree | 93720d3f46e571c9f9787616a2871c24f9c2d039 /plugins/rpm | |
parent | afa753016f8d43ce2c886e146093470cd5877f7f (diff) | |
download | firstaidkit-e22490465c43b9b223a6c5ca945d3a7d271c5717.tar.gz firstaidkit-e22490465c43b9b223a6c5ca945d3a7d271c5717.tar.xz firstaidkit-e22490465c43b9b223a6c5ca945d3a7d271c5717.zip |
Continue with the name standarization and simplification.
- The "_p" is not needed. Avoiding the suffix makes the names simpler.
- When the plugin needs to be separated into varios subplugins,
use the _ to signify that a subplugin is related to a father
plugin. Like rpm_lowlevel, this say that lowlevel is part of
the rpm plugin.
- When naming a plugin keep the name SHORT and simple.
- Be sure to name all the plugin packages as "plugin-name"
Diffstat (limited to 'plugins/rpm')
-rw-r--r-- | plugins/rpm/__init__.py | 68 | ||||
-rw-r--r-- | plugins/rpm/issue_packages.py | 67 |
2 files changed, 135 insertions, 0 deletions
diff --git a/plugins/rpm/__init__.py b/plugins/rpm/__init__.py new file mode 100644 index 0000000..f5409a1 --- /dev/null +++ b/plugins/rpm/__init__.py @@ -0,0 +1,68 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2007 Martin Sivak <msivak@redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from pyfirstaidkit.plugins import IssuesPlugin,Flow +from pyfirstaidkit.returns import * +from pyfirstaidkit.utils import * +from pyfirstaidkit.reporting import PLUGIN,TASK +from pyfirstaidkit import Config +import rpm + +from issue_packages import RequiredPackages + +class RPMPlugin(IssuesPlugin): + """This plugin provides checks for RPM database.""" + # + # Additional flow defprepareion. + # + flows = Flow.init(IssuesPlugin) + + name = "RPM plugin" + version = "0.0.1" + author = "Martin Sivak" + + issue_tests = [RequiredPackages] + set_flags = ["rpm_consistent"] + + @classmethod + def getDeps(cls): + return set(["root", "experimental", "filesystem", "rpm_lowlevel"]) + + def __init__(self, *args, **kwargs): + IssuesPlugin.__init__(self, *args, **kwargs) + self.rpm = None + + def prepare(self): + self._reporting.info(self.name+" in Prepare task", origin = self, level = PLUGIN) + self.rpm = rpm.ts(Config.system.root) + IssuesPlugin.prepare(self) + + def backup(self): + self._reporting.info(self.name+" in backup task", origin = self, level = PLUGIN) + self._result=ReturnSuccess + + def restore(self): + self._reporting.info(self.name+" in Restore task", origin = self, level = PLUGIN) + self._result=ReturnSuccess + + def clean(self): + self._reporting.info(self.name+" in Clean task", origin = self, level = PLUGIN) + del self.rpm + self._result=ReturnSuccess + +def get_plugin(): + return RPMPlugin diff --git a/plugins/rpm/issue_packages.py b/plugins/rpm/issue_packages.py new file mode 100644 index 0000000..11ed622 --- /dev/null +++ b/plugins/rpm/issue_packages.py @@ -0,0 +1,67 @@ +# File name: issue_filesystem.py +# Date: 2008/03/14 +# Author: Martin Sivak <msivak at redhat dot com> +# +# Copyright (C) Red Hat 2008 +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# in a file called COPYING along with this program; if not, write to +# the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA +# 02139, USA. + +from pyfirstaidkit.issue import Issue +from pyfirstaidkit.reporting import TASK + +class RequiredPackages(Issue): + name = "Required Packages" + description = "There are some very important packages missing. It is likely your instalation could be damaged." + + packages_list = ["filesystem", "initscripts", "glibc", "kernel", "bash", "module-init-tools"] + + def detect(self): + result = Issue.detect(self) + if result is not None: + return result + + architectures = {} + + for p in self.packages_list: + architectures[p] = set() + mi=self._plugin.rpm.dbMatch("name", p) + for hdr in mi: + self._plugin._reporting.debug(level = TASK, origin = self, message = "Found package %s with architecture %s" % (p, hdr["arch"])) + architectures[p].add(hdr["arch"]) + + #is there a common architecture for all the packages? + all = reduce(lambda acc,x: acc.union(x), architectures.values(), set()) + common = reduce(lambda acc,x: acc.intersection(x), architectures.values(), all) + self._plugin._reporting.debug(level = TASK, origin = self, message = "Common architecture for all packages is %s" % ("+".join(common),)) + + if len(common)==0: + self._happened = True + else: + self._happened = False + + self._checked = True + return True + + def fix(self): + result = Issue.fix(self) + if result is not None: + return result + + yum = spawnvch(executable = "/usr/bin/yum", args = ["yum", "install"] + packages_list, chroot = Config.system.root).communicate("y\ny\n") + if yum.returncode==0: + self._fixed = True + + return True |