cli/check: Style fixes
This commit is contained in:
+50
-21
@@ -1,6 +1,6 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2005 - 2011, TUBITAK/UEKAE
|
||||
# Copyright (C) 2005-2011, TUBITAK/UEKAE
|
||||
#
|
||||
# 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
|
||||
@@ -19,10 +19,11 @@ _ = __trans.ugettext
|
||||
import pisi.api
|
||||
import pisi.cli.command as command
|
||||
import pisi.context as ctx
|
||||
import pisi.util as util
|
||||
import pisi.db
|
||||
|
||||
class Check(command.Command):
|
||||
__doc__ = _("""Verify installation
|
||||
|
||||
usage = _("""Verify installation
|
||||
|
||||
Usage: check [<package1> <package2> ... <packagen>]
|
||||
|
||||
@@ -34,6 +35,11 @@ Just give the names of packages.
|
||||
|
||||
If no packages are given, checks all installed packages.
|
||||
""")
|
||||
|
||||
|
||||
class Check(command.Command):
|
||||
|
||||
__doc__ = usage
|
||||
__metaclass__ = command.autocommand
|
||||
|
||||
def __init__(self, args):
|
||||
@@ -45,19 +51,29 @@ If no packages are given, checks all installed packages.
|
||||
|
||||
def options(self):
|
||||
group = optparse.OptionGroup(self.parser, _("check options"))
|
||||
group.add_option("-c", "--component", action="store",
|
||||
default=None, help=_("Check installed packages under given component"))
|
||||
group.add_option("--config", action="store_true",
|
||||
default=False, help=_("Checks only changed config files of the packages"))
|
||||
|
||||
group.add_option("-c", "--component",
|
||||
action="store",
|
||||
default=None,
|
||||
help=_("Check installed packages under "
|
||||
"given component"))
|
||||
|
||||
group.add_option("--config",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help=_("Checks only changed config files of "
|
||||
"the packages"))
|
||||
|
||||
self.parser.add_option_group(group)
|
||||
|
||||
def run(self):
|
||||
self.init(database = True, write = False)
|
||||
self.init(database=True, write=False)
|
||||
|
||||
component = ctx.get_option('component')
|
||||
if component:
|
||||
installed = pisi.api.list_installed()
|
||||
component_pkgs = self.componentdb.get_union_packages(component, walk=True)
|
||||
component_pkgs = self.componentdb.get_union_packages(component,
|
||||
walk=True)
|
||||
pkgs = list(set(installed) & set(component_pkgs))
|
||||
elif self.args:
|
||||
pkgs = self.args
|
||||
@@ -79,28 +95,39 @@ If no packages are given, checks all installed packages.
|
||||
for pkg in pkgs:
|
||||
if self.installdb.has_package(pkg):
|
||||
check_results = pisi.api.check(pkg, check_config)
|
||||
ctx.ui.info("%s %s" % ((prefix % pkg), ' ' * (maxpkglen - len(pkg))), noln=True)
|
||||
ctx.ui.info("%s %s" % ((prefix % pkg),
|
||||
' ' * (maxpkglen - len(pkg))),
|
||||
noln=True)
|
||||
|
||||
if check_results['missing'] or check_results['corrupted'] \
|
||||
or check_results['config']:
|
||||
ctx.ui.info(pisi.util.colorize(_("Broken"), 'brightred'))
|
||||
ctx.ui.info(util.colorize(_("Broken"), 'brightred'))
|
||||
elif check_results['denied']:
|
||||
# We can't deduce a result when some files can't be accessed
|
||||
# We can't deduce a result when some files
|
||||
# can't be accessed
|
||||
necessary_permissions = False
|
||||
ctx.ui.info(pisi.util.colorize(_("Unknown"), 'yellow'))
|
||||
ctx.ui.info(util.colorize(_("Unknown"), 'yellow'))
|
||||
else:
|
||||
ctx.ui.info(pisi.util.colorize(_("OK"), 'green'))
|
||||
ctx.ui.info(util.colorize(_("OK"), 'green'))
|
||||
continue
|
||||
|
||||
# Dump per file stuff
|
||||
for fpath in check_results['missing']:
|
||||
ctx.ui.info(pisi.util.colorize(_("Missing file: /%s") % fpath, 'brightred'))
|
||||
ctx.ui.info(util.colorize(
|
||||
_("Missing file: /%s") % fpath, 'brightred'))
|
||||
|
||||
for fpath in check_results['denied']:
|
||||
ctx.ui.info(pisi.util.colorize(_("Access denied: /%s") % fpath, 'yellow'))
|
||||
ctx.ui.info(util.colorize(
|
||||
_("Access denied: /%s") % fpath, 'yellow'))
|
||||
|
||||
for fpath in check_results['corrupted']:
|
||||
ctx.ui.info(pisi.util.colorize(_("Corrupted file: /%s") % fpath, 'brightyellow'))
|
||||
ctx.ui.info(util.colorize(
|
||||
_("Corrupted file: /%s") % fpath, 'brightyellow'))
|
||||
|
||||
for fpath in check_results['config']:
|
||||
ctx.ui.info(pisi.util.colorize(_("Modified configuration file: /%s") % fpath, 'brightyellow'))
|
||||
ctx.ui.info(util.colorize(
|
||||
_("Modified configuration file: /%s") % fpath,
|
||||
'brightyellow'))
|
||||
|
||||
else:
|
||||
# Package is not installed
|
||||
@@ -108,6 +135,8 @@ If no packages are given, checks all installed packages.
|
||||
|
||||
if not necessary_permissions:
|
||||
ctx.ui.info("")
|
||||
ctx.ui.warning(_("Pisi was unable to check the integrity of packages which contain files that you don't have read access.\n"
|
||||
"Running the check under a privileged user may help fixing this problem."))
|
||||
|
||||
ctx.ui.warning(_("Pisi was unable to check the integrity of "
|
||||
"packages which contain files that you don't "
|
||||
"have read access.\n"
|
||||
"Running the check under a privileged user "
|
||||
"may help fixing this problem."))
|
||||
|
||||
Reference in New Issue
Block a user