URPM-repoclosure 1.4.1: removed obsolete code (including localization).

This commit is contained in:
Andrey Ponomarenko 2012-09-12 19:04:58 +04:00
parent 982a35a1e2
commit 0d74bbef0c

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
########################################################
# URPM Repos Closure Checker 1.4 for Linux
# URPM Repo Closure Checker 1.4.1 for Linux
# A tool for checking closure of a set of RPM packages
#
# Copyright (C) 2012 ROSA Laboratory
@ -36,43 +36,24 @@ use File::Path qw(mkpath rmtree);
use File::Temp qw(tempdir);
use File::Copy qw(copy move);
use Data::Dumper;
use Locale::gettext;
use strict;
my $TOOL_VERSION = "1.4";
my $TOOL_VERSION = "1.4.1";
my $CmdName = get_filename($0);
my ($Help, $ShowVersion, $RPMlist, $RPMdir, $StaticMode,
$DynamicMode, $CheckRelease, $CheckSignature, $SelectRepos,
$NoClean, $Root, $HDlist, $FileDeps, $ResDir, $AddRPMs,
$RTitle, $DepHDlists);
$DynamicMode, $NoClean, $HDlist, $FileDeps, $ReportDir,
$AddRPMs, $RTitle, $DepHDlists);
textdomain("urpm-tools");
sub N_(@)
{
my ($Str, @Params) = @_;
if(not $Str) {
return "";
}
$Str = gettext($Str);
foreach my $N (1 .. $#Params+1)
{
my $P = $Params[$N-1];
$Str=~s/\[_$N\]/$P/g;
}
return $Str;
}
my $ShortUsage = N_("URPM Repos Closure Checker [_1] for Mandriva Linux
my $ShortUsage = "URPM Repo Closure Checker $TOOL_VERSION for Mandriva Linux
A tool for checking closure of a set of RPM packages
Copyright (C) 2012 ROSA Laboratory
License: GNU GPL
Usage: [_2] [options]
Example: [_2] --hdlist=hdlist.txt
Usage: $CmdName [options]
Example: $CmdName --hdlist=hdlist.txt
More info: [_2] --help\n", $TOOL_VERSION, $CmdName);
More info: $CmdName --help\n";
if($#ARGV==-1) {
print $ShortUsage."\n";
@ -88,12 +69,8 @@ GetOptions("h|help!" => \$Help,
"file-deps=s" => \$FileDeps,
"s|static!" => \$StaticMode,
"dynamic!" => \$DynamicMode,
"r|check-release!" => \$CheckRelease,
"sign|check-signature!" => \$CheckSignature,
"media=s" => \$SelectRepos,
"noclean!" => \$NoClean,
"root=s" => \$Root,
"o|res=s" => \$ResDir,
"report-dir=s" => \$ReportDir,
"title=s" => \$RTitle,
"dep-hdlists=s" => \$DepHDlists
) or ERR_MESSAGE();
@ -104,16 +81,15 @@ my %EXIT_CODES = (
"FAILED" => 2
);
my $HelpMessage = N_("
my $HelpMessage = "
NAME:
URPM Repos Closure Checker 1.0 for Mandriva Linux
URPM Repo Closure Checker $TOOL_VERSION for Mandriva Linux
A tool for checking closure of a set of RPM packages
USAGE:
[_1] --hdlist=hdlist.txt
[_1] --hdlist=http://mirror.yandex.ru/mandriva/.../synthesis.hdlist.cz
[_1] --dir=rpms/ --static --file-deps=file-deps.txt
[_1] --list=list.txt --dynamic
$CmdName --hdlist=http://mirror.yandex.ru/mandriva/.../synthesis.hdlist.cz
$CmdName --dir=rpms/ --static --file-deps=file-deps.txt
$CmdName --list=list.txt --dynamic
OPTIONS:
-h|-help
@ -131,9 +107,8 @@ OPTIONS:
-l|-list <path>
The list of packages to check.
-add|-update <path>
The directory with RPM packages that should
be added to the repository or updated.
-updates <path>
The directory with updated RPM packages.
-file-deps <path>
Read file-deps to ignore some unresolved
@ -148,22 +123,17 @@ OPTIONS:
Install a set of RPM packages to the local chroot
and check if extra packages were installed.
-r|-check-release
Check installation media (DVD).
-sign|-check-signature
Validate package signatures.
-noclean
Do not clean urpmi cache.
-root <path>
Where to install packages.
Default:
/tmp/...
-report-dir <dir>
The directory where to generate report(s).
-title <name>
Name of the repository in the title of HTML report.
-dep-hdlists <path>
The list of hdlists that will
The list of HDlists that will
be used to resolve dependencies.
EXIT CODES:
@ -172,7 +142,7 @@ EXIT CODES:
1 - Failed to run the tool
2 - Discovered dependency problems
\n", $CmdName);
\n";
sub HELP_MESSAGE() {
print $HelpMessage;
@ -189,7 +159,6 @@ my $RPM_CACHE = "/var/cache/urpmi/rpms";
my $TMP_DIR = tempdir(CLEANUP=>1);
my %InstalledPackage;
my %RequiredBy;
my $TEST_MEDIA = "test_media";
my %Packages;
my %BrokenSignature;
my %InstallFailed;
@ -202,7 +171,7 @@ sub appendFile($$)
if(my $Dir = get_dirname($Path)) {
mkpath($Dir);
}
open(FILE, ">>".$Path) || die N_("can't open file \'[_1]\': [_2]\n", $Path, $!);
open(FILE, ">>".$Path) || die "can't open file \'$Path\': $!\n";
print FILE $Content;
close(FILE);
}
@ -214,7 +183,7 @@ sub writeFile($$)
if(my $Dir = get_dirname($Path)) {
mkpath($Dir);
}
open (FILE, ">".$Path) || die N_("can't open file \'[_1]\': [_2]\n", $Path, $!);
open (FILE, ">".$Path) || die "can't open file \'$Path\': $!\n";
print FILE $Content;
close(FILE);
}
@ -256,55 +225,16 @@ sub searchRPMs($)
return sort {lc($a) cmp lc($b)} @RPMs;
}
sub addMedia($)
{
my $Dir = $_[0];
if(not $Dir or not -d $Dir) {
return;
}
my %Media = map {$_=>1} split(/\n+/, `urpmq --list-media`);
if($Media{$TEST_MEDIA}) {
removeMedia();
}
$Dir = abs_path($Dir);
system("/usr/sbin/urpmi.addmedia $TEST_MEDIA $Dir");
system("/usr/sbin/urpmi.update $TEST_MEDIA");
}
sub removeMedia() {
system("/usr/sbin/urpmi.removemedia $TEST_MEDIA");
}
sub installPackage($)
{
my $Package = $_[0];
my $Cmd = "/usr/sbin/urpmi";
if($CheckRelease)
{ # from CD or DVD
$Cmd .= " --media=$TEST_MEDIA";
}
elsif($SelectRepos)
{
if(-d $SelectRepos) {
$Cmd .= " --media=$TEST_MEDIA";
}
else {
$Cmd .= " --media=$SelectRepos";
}
}
# create root where to install packages
if(not -d $TMP_DIR."/root") {
mkpath($TMP_DIR."/root");
}
if(not $CheckRelease) {
$Cmd .= " --no-install";
}
if($Root) {
$Cmd .= " --root=\"$Root\"";
}
else {
$Cmd .= " --root=\"$TMP_DIR/root\"";
}
$Cmd .= " --no-install";
$Cmd .= " --root=\"$TMP_DIR/root\"";
$Cmd .= " --noclean --auto --force";
$Cmd .= " $Package";
print "Running $Cmd\n";
@ -319,22 +249,12 @@ sub installPackage($)
$InstallFailed{getPName($Package)}=1;
print " FAILED: due to $Reason $Dep\n";
}
if($CheckRelease)
{ # installed
while($Log=~s/(installing\s+)([^\/\s]+\.rpm)(\s|\Z)/$1/)
{
my $RpmName = $2;
print " $RpmName\n";
}
}
else
{ # downloaded
while($Log=~s/(\/)([^\/\s]+\.rpm)(\s|\Z)/$1$3/)
{
my $RpmName = $2;
print " $RpmName\n";
$RequiredBy{getPName($RPM_CACHE."/".$RpmName)}=getPName($Package);
}
# downloaded
while($Log=~s/(\/)([^\/\s]+\.rpm)(\s|\Z)/$1$3/)
{
my $RpmName = $2;
print " $RpmName\n";
$RequiredBy{getPName($RPM_CACHE."/".$RpmName)} = getPName($Package);
}
}
@ -533,7 +453,7 @@ sub checkSignature($)
sub checkRoot()
{
if(not -w "/usr") {
print STDERR N_("ERROR: you should be root\n");
print STDERR "ERROR: you should be root\n";
exit(1);
}
}
@ -543,12 +463,12 @@ sub readRPMlist($$)
my ($Path, $Type) = @_;
if(not -f $Path)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $Path);
print STDERR "ERROR: cannot access \'$Path\'\n";
exit(1);
}
my @RPMs = split(/\s+/, readFile($Path));
if($#RPMs==-1) {
print STDERR N_("ERROR: the list of packages is empty\n");
print STDERR "ERROR: the list of packages is empty\n";
exit(1);
}
if($Type eq "RPMs")
@ -557,12 +477,12 @@ sub readRPMlist($$)
{
if($P!~/\.rpm\Z/)
{
print STDERR N_("ERROR: file \'[_1]\' is not RPM package\n", $P);
print STDERR "ERROR: file \'$P\' is not RPM package\n";
exit(1);
}
elsif(not -f $P)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $P);
print STDERR "ERROR: cannot access \'$P\'\n";
exit(1);
}
}
@ -570,55 +490,12 @@ sub readRPMlist($$)
return @RPMs;
}
sub checkRelease()
{
checkRoot();
if(not $RPMdir and not $RPMlist)
{
print STDERR N_("ERROR: --dir or --list option should be specified\n");
exit(1);
}
clearCache();
my @RPMs = ();
if($RPMlist)
{
@RPMs = readRPMlist($RPMlist, "RPMs");
$RPMdir = get_dirname($RPMs[0]);
if(not $RPMdir) {
$RPMdir = ".";
}
}
else
{
if(not -d $RPMdir)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $RPMdir);
exit(1);
}
@RPMs = searchRPMs($RPMdir);
}
addMedia($RPMdir);
foreach my $Path (@RPMs)
{ # add to cache
if(not -f $RPM_CACHE."/".get_filename($Path)) {
# copy($Path, $RPM_CACHE);
}
}
foreach my $Path (@RPMs)
{
installPackage($Path);
$Packages{get_filename($Path)} = 1;
}
removeMedia();
checkResult();
}
sub dynamicCheck()
{
checkRoot();
if(not $RPMdir and not $RPMlist)
{
print STDERR N_("ERROR: --dir or --list option should be specified\n");
print STDERR "ERROR: --dir or --list option should be specified\n";
exit(1);
}
clearCache();
@ -627,7 +504,7 @@ sub dynamicCheck()
{ # --dir option
if(not -d $RPMdir)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $RPMdir);
print STDERR "ERROR: cannot access \'$RPMdir\'\n";
exit(1);
}
@RPMs = searchRPMs($RPMdir);
@ -635,33 +512,21 @@ sub dynamicCheck()
{ # add to cache
copy($Path, $RPM_CACHE);
}
if(-d $SelectRepos) {
addMedia($SelectRepos);
}
foreach my $Path (@RPMs)
{
installPackage($Path);
$Packages{get_RPMname($Path)} = 1;
$Packages{get_filename($Path)} = 1;
}
if(-d $SelectRepos) {
removeMedia();
}
}
elsif($RPMlist)
{
@RPMs = readRPMlist($RPMlist, "Names");
if(-d $SelectRepos) {
addMedia($SelectRepos);
}
foreach my $Name (@RPMs)
{
installPackage($Name);
$Packages{$Name} = 1;
}
if(-d $SelectRepos) {
removeMedia();
}
}
checkResult();
}
@ -685,10 +550,8 @@ sub isInstalled($)
if($InstallFailed{$Name}) {
return 0;
}
if(not $CheckRelease) {
if(not $InstalledPackage{$Name}) {
return 0;
}
if(not $InstalledPackage{$Name}) {
return 0;
}
return 1;
}
@ -712,12 +575,12 @@ sub checkResult()
}
if(my @Names = sort {lc($a) cmp lc($b)} keys(%ExtraPackages))
{
my $Report = N_("Extra Packages:\n\n");
my $Report = "Extra Packages:\n\n";
foreach my $Name (@Names)
{
$Report .= $Name;
if(my $Req = $RequiredBy{$Name}) {
$Report .= N_(" (required by: [_1])", $Req);
$Report .= " (required by: $Req)";
}
$Report .= "\n";
}
@ -726,14 +589,14 @@ sub checkResult()
}
if(my @Names = sort {lc($a) cmp lc($b)} keys(%BrokenPackages))
{
my $Report = N_("Broken Packages:\n\n");
my $Report = "Broken Packages:\n\n";
foreach my $Name (@Names) {
$Report .= "$Name\n";
}
print $Report;
writeFile("$RESULTS_DIR/broken-packages.txt", $Report);
}
print N_("Report has been generated to:");
print "Report has been generated to:";
print "\n $RESULTS_DIR/extra-packages.txt\n $RESULTS_DIR/broken-packages.txt\n";
if(keys(%ExtraPackages) or keys(%BrokenPackages))
{
@ -744,53 +607,6 @@ sub checkResult()
}
}
sub sigCheck()
{
if(not $RPMdir and not $RPMlist)
{
print STDERR N_("ERROR: --dir or --list option should be specified\n");
exit(1);
}
print N_("Checking RPMs ...\n");
my @RPMs = ();
if($RPMdir)
{
if(not -d $RPMdir)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $RPMdir);
exit(1);
}
@RPMs = searchRPMs($RPMdir);
}
elsif($RPMlist) {
@RPMs = readRPMlist($RPMlist, "RPMs");
}
foreach my $Path (@RPMs)
{
print N_("Checking [_1]\n", get_filename($Path));
if(not checkSignature($Path)) {
print N_(" FAILED: invalid signature\n");
}
}
if(my @Names = sort {lc($a) cmp lc($b)} keys(%BrokenSignature))
{
my $Report = N_("Broken Signature:\n\n");
foreach my $Name (@Names) {
$Report .= "$Name\n";
}
print $Report;
writeFile("$RESULTS_DIR/report.txt", $Report);
}
print N_("Report has been generated to:");
print "\n $RESULTS_DIR/report.txt\n";
if(keys(%BrokenSignature)) {
exit($EXIT_CODES{"FAILED"});
}
else {
exit($EXIT_CODES{"SUCCESS"});
}
}
sub readLineNum($$)
{
my ($Path, $Num) = @_;
@ -847,7 +663,7 @@ sub readHDlist($$$$)
my $Content = "";
if($Path=~/(http|https|ftp):\/\//)
{
print N_("Downloading HDlist ...\n");
print "Downloading HDlist ...\n";
my $DownloadTo = $TMP_DIR."/extract/".get_filename($Path);
$DownloadTo=~s/\.cz/\.gz/g; # cz == gz
my $Dir = get_dirname($DownloadTo);
@ -856,7 +672,7 @@ sub readHDlist($$$$)
if(not -f $DownloadTo
or not -s $DownloadTo)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $Path);
print STDERR "ERROR: cannot access \'$Path\'\n";
exit(1);
}
@ -874,7 +690,7 @@ sub readHDlist($$$$)
my @Files = cmd_find($Dir, "f", "", "");
if(not @Files)
{
print STDERR N_("ERROR: cannot extract \'[_1]\'\n", $Path);
print STDERR "ERROR: cannot extract \'$Path\'\n";
exit(1);
}
unlink($DownloadTo);
@ -884,7 +700,7 @@ sub readHDlist($$$$)
{
if($Line!~/\A\@\w+\@/)
{
print STDERR N_("ERROR: unknown format of hdlist\n");
print STDERR "ERROR: unknown format of hdlist\n";
exit(1);
}
}
@ -895,12 +711,12 @@ sub readHDlist($$$$)
{
if(not -f $Path)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $Path);
print STDERR "ERROR: cannot access \'$Path\'\n";
exit(1);
}
$Content = readFile($Path);
}
print N_("Checking HDlist ...\n");
print "Checking HDlist ...\n";
my $Name = "";
foreach (reverse(split(/\n/, $Content)))
{
@ -939,7 +755,7 @@ sub staticCheck()
{
if(not $RPMdir and not $HDlist and not $RPMlist)
{
print STDERR N_("ERROR: --hdlist, --dir or --list option should be specified\n");
print STDERR "ERROR: --hdlist, --dir or --list option should be specified\n";
exit(1);
}
my (%Dep, %RPMdep, %AddedRPMs) = ();
@ -948,7 +764,7 @@ sub staticCheck()
{
if(not -d $AddRPMs)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $AddRPMs);
print STDERR "ERROR: cannot access \'$AddRPMs\'\n";
exit(1);
}
if(my @AddedRPMs = searchRPMs($AddRPMs))
@ -964,13 +780,13 @@ sub staticCheck()
}
if($RPMdir or $RPMlist)
{
print N_("Checking RPMs ...\n");
print "Checking RPMs ...\n";
my @RPMs = ();
if($RPMdir)
{
if(not -d $RPMdir)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $RPMdir);
print STDERR "ERROR: cannot access \'$RPMdir\'\n";
exit(1);
}
@RPMs = searchRPMs($RPMdir);
@ -1001,7 +817,7 @@ sub staticCheck()
{
if(not -f $DepHDlists)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $DepHDlists);
print STDERR "ERROR: cannot access \'$DepHDlists\'\n";
exit(1);
}
foreach my $Url (split(/\s+/, readFile($DepHDlists))) {
@ -1014,7 +830,7 @@ sub staticCheck()
{
if(not -f $FileDeps)
{
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $FileDeps);
print STDERR "ERROR: cannot access \'$FileDeps\'\n";
exit(1);
}
%IgnoreDeps = map {$_=>1} split(/\s+/, readFile($FileDeps));
@ -1086,7 +902,7 @@ sub staticCheck()
if(my @Ns = sort {lc($a) cmp lc($b)} keys(%Unresolved))
{
my $Title = N_("Unresolved Dependencies ([_1])", $#Ns+1);
my $Title = "Unresolved Dependencies (".($#Ns+1).")";
$Report .= "\n$Title:\n\n";
$VReport .= "<a name='Unresolved'></a>\n";
@ -1102,7 +918,7 @@ sub staticCheck()
{
my $Dep = showDep($N, $O, $V);
my $Pkg = $Unresolved{$N}{$O}{$V};
$Report .= $Dep." (".N_("required by [_1]", $Pkg).")\n";
$Report .= $Dep." (required by $Pkg)\n";
$VReport .= "<tr><td>$Dep</td><td>$Pkg</td></tr>\n";
}
}
@ -1116,7 +932,7 @@ sub staticCheck()
$Report .= "\n";
}
my $Title = N_("Unresolved Suggests ([_1])", $#Ns+1);
my $Title = "Unresolved Suggests (".($#Ns+1).")";
$Report .= "\n$Title:\n\n";
$VReport .= "<h2>$Title</h2><hr/>\n";
@ -1131,7 +947,7 @@ sub staticCheck()
{
my $Dep = showDep($N, $O, $V);
my $Pkg = $UnresolvedSuggested{$N}{$O}{$V};
$Report .= $Dep." (".N_("required by [_1]", $Pkg).")\n";
$Report .= $Dep." (required by $Pkg)\n";
$VReport .= "<tr><td>$Dep</td><td>$Pkg</td></tr>\n";
}
}
@ -1145,7 +961,7 @@ sub staticCheck()
$Report .= "\n";
}
my $Title = N_("Broken Packages ([_1])", $#Ns+1);
my $Title = "Broken Packages (".($#Ns+1).")";
$Report .= "\n$Title:\n\n";
$VReport .= "<a name='Broken'></a>\n";
@ -1252,7 +1068,7 @@ table.report td {
writeFile("$RESULTS_DIR/debug/rpm-requires.txt", Dumper($RPMdep{"requires"}));
writeFile("$RESULTS_DIR/debug/rpm-suggests.txt", Dumper($RPMdep{"suggests"}));
print N_("Report has been generated to:");
print "Report has been generated to:";
print "\n $RESULTS_DIR/report.txt (html)\n\n";
# exit code
@ -1348,51 +1164,28 @@ sub scenario()
}
if($ShowVersion)
{
print N_("URPM Repos Closure Checker [_1] for Mandriva Linux\nCopyright (C) 2012 ROSA Laboratory\nLicense: GPL <http://www.gnu.org/licenses/>\nThis program is free software: you can redistribute it and/or modify it.\n\nWritten by Andrey Ponomarenko.\n", $TOOL_VERSION);
print "URPM Repo Closure Checker $TOOL_VERSION for Mandriva Linux\nCopyright (C) 2012 ROSA Laboratory\nLicense: GPL <http://www.gnu.org/licenses/>\nThis program is free software: you can redistribute it and/or modify it.\n\nWritten by Andrey Ponomarenko.\n";
exit(0);
}
if($HDlist) {
$StaticMode = 1;
}
if($Root)
{
if(not -d $Root) {
print STDERR N_("ERROR: cannot access \'[_1]\'\n", $Root);
exit(1);
}
}
if($ResDir) {
$RESULTS_DIR = $ResDir;
if($ReportDir) {
$RESULTS_DIR = $ReportDir;
}
if(-d $RESULTS_DIR) {
rmtree($RESULTS_DIR);
}
if($CheckSignature)
{
if(not $ResDir) {
$RESULTS_DIR .= "/signature";
}
sigCheck();
exit(0);
}
if($StaticMode)
{
if(not $ResDir) {
if(not $ReportDir) {
$RESULTS_DIR .= "/static";
}
staticCheck();
}
if($CheckRelease)
{
if(not $ResDir) {
$RESULTS_DIR .= "/release";
}
checkRelease();
exit(0);
}
if($DynamicMode)
{
if(not $ResDir) {
if(not $ReportDir) {
$RESULTS_DIR .= "/dynamic";
}
dynamicCheck();