From mboxrd@z Thu Jan 1 00:00:00 1970 From: Robin Roevens To: development@lists.ipfire.org Subject: [PATCH v2 09/10] pakfire: Add getmetadata function Date: Thu, 28 Jul 2022 13:21:35 +0200 Message-ID: <20220728112136.30218-10-robin.roevens@disroot.org> In-Reply-To: <20220728112136.30218-1-robin.roevens@disroot.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6255058614274403724==" List-Id: --===============6255058614274403724== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable - Added new getmetadata function for easy access to all available metadata of a pak without knowledge about or need to parse pakfire internal db files. - Added new 'pakfire info' functionality for displaying all available metadata of (a) pak(s) to the user, using the new getmetadata. Signed-off-by: Robin Roevens --- src/pakfire/lib/functions.pl | 55 ++++++++++++++++++++++++++++++++++ src/pakfire/pakfire | 58 ++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index f87589bc4..1ebf98775 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -115,6 +115,7 @@ sub usage { &Pakfire::message(" - Contacts the servers for new = lists of paks."); &Pakfire::message(" - Installs the latest version = of all paks."); &Pakfire::message(" [installed/notinstalled/upgrade] = - Outputs a list with all, installed, available or upgradeable paks."); + &Pakfire::message(" [ ...] - Output pak me= tadata."); &Pakfire::message(" - Outputs a summary about avail= able core upgrades, updates and a required reboot"); &Pakfire::message(""); &Pakfire::message(" Global options:"); @@ -706,6 +707,60 @@ sub parsemetafile { return %metadata; } =20 +sub getmetadata { + ### This subroutine returns a hash of available info for a package + # Pass package name and type of info as argument: Pakfire::getmetadata(pa= ckage, type_of_info)=20 + # Type_of_info can be "latest" or "installed" + # Usage is always with two argument. + my ($pak, $type) =3D @_; + + my %metadata =3D ( + Name =3D> $pak,=20 + Installed =3D> "no", + Available =3D> "no"); + my %installed_metadata =3D (); + + my @templine; + my @file; + + ### Get available version information + if ("$type" eq "latest") { + ### Check if package is in packages_list and get latest available version + my %db =3D Pakfire::dblist("all"); + =09 + if (defined $db{$pak}) { + ### Get and parse latest available metadata + if (getmetafile("$pak")) { + %metadata =3D parsemetafile("$Conf::dbdir/meta/meta-$pak"); + + $metadata{'Available'} =3D "yes"; + ### Rename version info fields + $metadata{'AvailableProgVersion'} =3D delete $metadata{'ProgVersion'}; + $metadata{'AvailableRelease'} =3D delete $metadata{'Release'}; + } + } + } +=09 + ### Parse installed pak metadata + if (&isinstalled($pak) =3D=3D 0) { + %installed_metadata =3D parsemetafile("$Conf::dbdir/installed/meta-$pak= "); + + if ("$type" eq "latest" && exists($metadata{'AvailableProgVersion'})) { + ### Add installed version info to latest metadata + $metadata{'ProgVersion'} =3D $installed_metadata{'ProgVersion'}; + $metadata{'Release'} =3D $installed_metadata{'Release'}; + } else { + ### Use metadata of installed pak + %metadata =3D %installed_metadata; + } + $metadata{'Installed'} =3D 'yes'; + } else { + $metadata{'Installed'} =3D 'no'; + } + + return %metadata; +} + sub decryptpak { my $pak =3D shift; =20 diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 331204a00..389c1399d 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -393,6 +393,64 @@ exit 1; } } + } elsif ("$ARGV[0]" eq "info") { + shift; + + my @paks; + my $pak; + foreach $pak (@ARGV) { + unless ("$pak" =3D~ "^-") { + push(@paks,$pak); + } + } + + unless ("@paks") { + Pakfire::message("PAKFIRE ERROR: missing package name"); + Pakfire::usage; + exit 1; + } + + foreach $pak (@paks) { + my %metadata =3D Pakfire::getmetadata($pak, "latest"); + + ### Check if pakfile was actually found + if ($metadata{'Installed'} eq "no" && $metadata{'Available'} eq "no") { + Pakfire::message("PAKFIRE WARN: Pak '$pak' not found."); + last; + } + + unless (defined $metadata{'Available'}) { + Pakfire::message("PAKFIRE WARN: Unable to retrieve latest metadata for $= pak. Information may be outdated.") + } + + ### Printout metadata in a user friendly format + print "Name: $metadata{'Name'}\n"; + print "Summary: $metadata{'Summary'}\n"; + if ($metadata{'Available'} eq "yes") { + print "Version: $metadata{'AvailableProgVersion'}-$metadata{'AvailableRe= lease'}\n"; + } else { + print "Version: $metadata{'ProgVersion'}-$metadata{'Release'}\n"; + } + print "Size: " . Pakfire::beautifysize("$metadata{'Size'}") . "\n"; + print "Dependencies: $metadata{'Dependencies'}\n"; + print "Pakfile: $metadata{'File'}\n"; + print "Service InitScripts: $metadata{'Services'}\n"; + print "Installed: $metadata{'Installed'}\n"; + ### Generate a pak status message + if (! defined $metadata{'Available'}) { + print "Status: unknown (an error occured retrieving latest pak metadata)= "; + } elsif ($metadata{'Available'} eq "no") { + print "Status: obsolete (version $metadata{'ProgVersion'}-$metadata{'Rel= ease'} is installed)\n"; + } elsif ($metadata{'Installed'} eq "yes" && "$metadata{'Release'}" < "$me= tadata{'AvailableRelease'}") { + print "Status: outdated (version $metadata{'ProgVersion'}-$metadata{'Rel= ease'} is installed)\n"; + } elsif ($metadata{'Installed'} eq "yes") { + print "Status: up-to-date\n"; + } else { + print "Status: not installed\n"; + } + print "\n"; + } + } elsif ("$ARGV[0]" eq "resolvedeps") { foreach (@ARGV) { next if ("$_" eq "resolvedeps"); --=20 2.36.1 --=20 Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn. --===============6255058614274403724==--