summaryrefslogtreecommitdiffstats
path: root/lib/App/ArchLinux/PackagerTools
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-11-19 00:57:11 +0100
committerFlorian Pritz <bluewind@xinu.at>2018-11-19 00:57:11 +0100
commitdf8f04661d46f03f7c2dd4041c520c479179ed8a (patch)
tree10c42c6537cc0ec46877412e1997b91ff04a94bb /lib/App/ArchLinux/PackagerTools
parenta01c7719bc535092ce3a6e83bb26159d3f117d72 (diff)
downloadApp-ArchLinux-PackagerTools-df8f04661d46f03f7c2dd4041c520c479179ed8a.tar.gz
App-ArchLinux-PackagerTools-df8f04661d46f03f7c2dd4041c520c479179ed8a.tar.xz
Batch calls to expac for performance
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib/App/ArchLinux/PackagerTools')
-rw-r--r--lib/App/ArchLinux/PackagerTools/Pacman.pm68
1 files changed, 66 insertions, 2 deletions
diff --git a/lib/App/ArchLinux/PackagerTools/Pacman.pm b/lib/App/ArchLinux/PackagerTools/Pacman.pm
index ec4f991..b9fe988 100644
--- a/lib/App/ArchLinux/PackagerTools/Pacman.pm
+++ b/lib/App/ArchLinux/PackagerTools/Pacman.pm
@@ -131,6 +131,30 @@ method get_package_version($pkgname) {
return $version;
}
+=head3 get_packages_versions
+
+ my $versions = $pacman->get_packages_versions($package_names);
+
+Return a hash that maps each package name to the version of that package in the
+pacman repository.
+
+=cut
+
+method get_packages_versions($package_names) {
+ my %versions;
+
+ open my $fh, '-|', qw(expac -S -1), '%n %v', '--', $package_names->@*;
+ while (<$fh>) {
+ my ($pkgname, $version) = split /\s/;
+ $versions{$pkgname} = $version;
+ $log->debugf("Package '%s' has version '%s' in repository", $pkgname, $version);
+ }
+ if ($package_names->@* != keys %versions) {
+ croak $log->error("Failed to find version for all packages. Got %d packages and %d versions were detected", scalar($package_names->@*), scalar(keys %versions));
+ }
+ return \%versions;
+}
+
=head3 get_perl_pkgname
my $pkgname = $pacman->get_perl_pkgname($dist_name);
@@ -162,12 +186,52 @@ pacman-specific information from the pacman's package version.
method get_perl_distribution_version($dist_name) {
my $pkgname = $self->get_perl_pkgname($dist_name);
my $version = $self->get_package_version($pkgname);
+ $version = $self->_clean_version($version);
+
+ $log->tracef("Found version '%s' for package '%s'", $version, $pkgname);
+ return $version;
+}
+
+=head3 get_perl_distribution_versions
+
+ my $distribution_names = ['App::ArchLinux::PackagerTools', 'DBI'];
+ my $versions = $pacman->get_perl_distribution_versions($distribution_names);
+ print $versions->{'DBI'}; # prints "1.642"
+
+Return a hash that maps a CPAN distribution name to the respective version of
+the CPAN distribution of the pacman repository package.
+
+=cut
+
+method get_perl_distribution_versions($distribution_names) {
+ my %pkgname_dist;
+ for my $dist_name ($distribution_names->@*) {
+ $pkgname_dist{$self->get_perl_pkgname($dist_name)} = $dist_name;
+ }
+
+ my $versions = $self->get_packages_versions([keys %pkgname_dist]);
+ my %dist_versions;
+ for my $key (keys $versions->%*) {
+ $dist_versions{$pkgname_dist{$key}} = $self->_clean_version($versions->{$key});
+ $log->debugf("Cleaned version of package '%s' is now '%s'", $key, $versions->{$key});
+ }
+ return \%dist_versions;
+
+}
+
+=head3 _clean_version
+
+ my $version = $self->_clean_version($version);
+
+Strip pacman-specific information (pkgrel, epoch) from a version string.
+
+=cut
+
+method _clean_version($version) {
# remove pkgrel
$version =~ s/-\d+(\.\d+)?$//;
# remove epoch
$version =~ s/^\d+://;
-
- $log->tracef("Found version '%s' for package '%s'", $version, $pkgname);
return $version;
}