Added health check installed packages

This commit is contained in:
Dimitris Zlatanidis 2015-07-16 02:03:52 +03:00
parent b6dc506e14
commit f44d4595c0
5 changed files with 136 additions and 6 deletions

View file

@ -250,9 +250,9 @@ Using pip:
Bbinary packages: Bbinary packages:
Slackware: `slpkg-2.6.1-i486-1_dsw.txz <https://github.com/dslackw/slpkg/releases/download/v2.6.1/slpkg-2.6.1-i486-1_dsw.txz>`_ Slackware: `slpkg-2.6.2-i486-1_dsw.txz <https://github.com/dslackw/slpkg/releases/download/v2.6.2/slpkg-2.6.2-i486-1_dsw.txz>`_
Slackware64: `slpkg-2.6.1-x86_64-1_dsw.txz <https://github.com/dslackw/slpkg/releases/download/v2.6.1/slpkg-2.6.1-x86_64-1_dsw.txz>`_ Slackware64: `slpkg-2.6.2-x86_64-1_dsw.txz <https://github.com/dslackw/slpkg/releases/download/v2.6.2/slpkg-2.6.2-x86_64-1_dsw.txz>`_
Upgrade Upgrade
@ -341,6 +341,7 @@ Command Line Tool Usage
repository. repository.
update slpkg Upgrade the program directly from update slpkg Upgrade the program directly from
repository. repository.
health, --silent Health check installed packages.
Optional arguments: Optional arguments:
-h, --help Print this help message and exit. -h, --help Print this help message and exit.

View file

@ -19,7 +19,8 @@ Usage: slpkg Commands:
[update, --only=[...]] [upgrade, --only=[...]] [update, --only=[...]] [upgrade, --only=[...]]
[repo-add [repository name] [URL]] [repo-add [repository name] [URL]]
[repo-remove [repository]] [repo-list] [repo-remove [repository]] [repo-list]
[repo-info [repository]] [update [slpkg]] [repo-info [repository]] [update [slpkg]]
[health, --silent]
Optional arguments: Optional arguments:
[-h] [-v] [-h] [-v]
@ -93,6 +94,12 @@ View repository information.
.PP .PP
You can check for new versions and update slpkg itself. You can check for new versions and update slpkg itself.
.SS health, health check installed packages
\fBslpkg\fP \fBhealth\fP, \fB--silent\fP
.PP
This command get each file from "/var/log/packages/" directory and read file list from
package to check if installed.
.SH OPTIONS .SH OPTIONS
.PP .PP
The following arguments are available. The following arguments are available.

View file

@ -54,6 +54,7 @@ Commands:
repository. repository.
update slpkg Upgrade the program directly from update slpkg Upgrade the program directly from
repository. repository.
health, --silent Health check installed packages.
Optional arguments: Optional arguments:
-h, --help Print this help message and exit. -h, --help Print this help message and exit.
@ -127,6 +128,7 @@ def usage(repo):
[repo-add [repository name] [URL]] [repo-add [repository name] [URL]]
[repo-remove [repository]] [repo-list] [repo-remove [repository]] [repo-list]
[repo-info [repository]] [update [slpkg]] [repo-info [repository]] [update [slpkg]]
[health, --silent]
Optional arguments: Optional arguments:
[-h] [-v] [-h] [-v]

107
slpkg/health.py Normal file
View file

@ -0,0 +1,107 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# health.py file is part of slpkg.
# Copyright 2014-2015 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
# All rights reserved.
# Slpkg is a user-friendly package manager for Slackware installations
# https://github.com/dslackw/slpkg
# Slpkg 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 3 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, see <http://www.gnu.org/licenses/>.
import os
import sys
from messages import Msg
from __metadata__ import MetaData as _meta_
from pkg.find import find_package
class PackageHealth(object):
"""Health check installed packages
"""
def __init__(self, mode):
self.mode = mode
self.meta = _meta_
self.pkg_path = _meta_.pkg_path
self.installed = []
self.cn = 0
def packages(self):
"""Get all installed packages from /var/log/packages/ path
"""
self.installed = find_package("", self.pkg_path)
def check(self, line, pkg):
line = line.replace("\n", "")
try:
if (not line.endswith("/") and
not line.endswith(".new") and
not line.startswith("dev/") and
not line.startswith("install/") and
"/incoming/" not in line):
if not os.path.isfile("/" + line):
self.cn += 1
print("Not installed: {0}/{1}{2} --> {3}".format(
self.meta.color["RED"], line, self.meta.color["ENDC"],
pkg))
elif not self.mode:
print(line)
except (KeyboardInterrupt, IOError):
print("")
sys.exit(0)
def test(self):
"""Get started test each package and read file list
"""
self.packages()
self.cf = 0
try:
for pkg in self.installed:
self.lf = 0
with open(self.pkg_path + pkg, "r") as fopen:
for line in fopen:
self.cf += 1 # count all files
self.lf += 1 # count each package files
if self.lf > 19:
self.check(line, pkg)
except KeyboardInterrupt:
print("")
sys.exit(0)
self.results()
def results(self):
"""Print results
"""
print("")
per = int(round((float(self.cf) / (self.cf + self.cn)) * 100))
if per > 90:
color = self.meta.color["GREEN"]
elif per < 90 and per > 60:
color = self.meta.color["YELLOW"]
elif per < 60:
color = self.meta.color["RED"]
health = "{0}{1}%{2}".format(color, str(per), self.meta.color["ENDC"])
Msg().template(78)
print("| {0}{1}{2}{3}{4}".format(
"Total files", " " * 7, "Not installed", " " * 40, "Health"))
Msg().template(78)
print("| {0}{1}{2}{3}{4:>4}".format(
self.cf, " " * (18-len(str(self.cf))),
self.cn, " " * (55-len(str(self.cn))),
health))
Msg().template(78)

View file

@ -27,9 +27,9 @@ import sys
import getpass import getpass
from load import Regex from load import Regex
from desc import PkgDesc
from messages import Msg from messages import Msg
from auto_pkg import Auto from auto_pkg import Auto
from desc import PkgDesc
from config import Config from config import Config
from checks import Updates from checks import Updates
from queue import QueuePkgs from queue import QueuePkgs
@ -39,6 +39,7 @@ from repositories import Repo
from tracking import track_dep from tracking import track_dep
from blacklist import BlackList from blacklist import BlackList
from version import prog_version from version import prog_version
from health import PackageHealth
from pkg_find import find_from_repos from pkg_find import find_from_repos
from arguments import options, usage from arguments import options, usage
from slpkg_update import it_self_update from slpkg_update import it_self_update
@ -70,8 +71,8 @@ class ArgParse(object):
# checking if repositories exists # checking if repositories exists
if len(self.args) > 1 and self.args[0] not in [ if len(self.args) > 1 and self.args[0] not in [
"-h", "--help", "-v", "--version", "upgrade", "repo-list", "-h", "--help", "-v", "--version", "upgrade", "repo-list",
"repo-add", "repo-remove", "update", "update-slpkg", "-g", "repo-add", "repo-remove", "update", "update-slpkg",
"--config" "health", "-g", "--config"
]: ]:
check_exists_repositories() check_exists_repositories()
@ -159,6 +160,17 @@ class ArgParse(object):
else: else:
usage("") usage("")
def command_health(self):
"""Check package health
"""
if len(self.args) == 1 and self.args[0] == "health":
PackageHealth(mode="").test()
elif (len(self.args) == 2 and self.args[0] == "health" and
self.args[1] == "--silent"):
PackageHealth(mode=self.args[1]).test()
else:
usage("")
def auto_build(self): def auto_build(self):
"""Auto built tool """Auto built tool
""" """
@ -521,6 +533,7 @@ def main():
"repo-add": argparse.command_repo_add, "repo-add": argparse.command_repo_add,
"repo-remove": argparse.command_repo_remove, "repo-remove": argparse.command_repo_remove,
"repo-info": argparse.command_repo_info, "repo-info": argparse.command_repo_info,
"health": argparse.command_health,
"-a": argparse.auto_build, "-a": argparse.auto_build,
"--autobuild": argparse.auto_build, "--autobuild": argparse.auto_build,
"-l": argparse.pkg_list, "-l": argparse.pkg_list,