1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
package App::ArchLinux::PackagerTools;
use v5.24;
use strictures;
our $VERSION = "0.01";
use autodie;
use Function::Parameters;
use Log::Any qw($log);
use List::Util 1.33 qw(any);
use App::ArchLinux::PackagerTools::Pacman;
use App::ArchLinux::PackagerTools::CPAN;
use App::ArchLinux::PackagerTools::Config;
use App::ArchLinux::PackagerTools::Archweb;
=encoding utf-8
=head1 NAME
App::ArchLinux::PackagerTools - It's new $module
=head1 SYNOPSIS
use App::ArchLinux::PackagerTools;
=head1 DESCRIPTION
App::ArchLinux::PackagerTools is ...
=head1 METHODS
=head2 Constructors
=head3 new
App::ArchLinux::PackagerTools->new();
Returns a new instance.
=cut
method new($class: $context = {}, $deps = {}) {
$deps->{config} //= App::ArchLinux::PackagerTools::Config->new($context);
$deps->{cpan} //= App::ArchLinux::PackagerTools::CPAN->new($context);
$deps->{pacman} //= App::ArchLinux::PackagerTools::Pacman->new($context);
$deps->{archweb} //= App::ArchLinux::PackagerTools::Archweb->new($context);
return $class->new_no_defaults($context, $deps);
}
method new_no_defaults($class: $context, $deps = {}) {
my $self = {};
bless $self, $class;
$self->{deps} = $deps;
return $self;
}
=head3 get_distributions_in_repo
my $dists = $app->get_distributions_in_repo();
Return an arrayref of hashrefs with CPAN distribution information. See
L<App::ArchLinux::PackagerTools::Pacman/"get_perl_distributions">.
=cut
method get_distributions_in_repo() {
return $self->{deps}->{pacman}->get_perl_distributions();
}
=head3 get_updateable_packages
my $distribution_names = ['App::ArchLinux::PackagerTools', 'DBI'];
my $packages = $app->get_updateable_packages($distribution_names);
print $packages->[0]->{dist_name};
print $packages->[0]->{pkgname};
print $packages->[0]->{repo_version};
print $packages->[0]->{cpan_version};
Accepts a list of package names and returns a list of packages that can be
updated. The returned packages contain the name of the distribution, the name
of the pacman package, and the versions of each, the pacman package (which is
older) and the CPAN distribution.
=cut
method get_updateable_packages($distribution_names) {
my @packages;
my $cpan = $self->{deps}->{cpan};
my $pacman = $self->{deps}->{pacman};
my $repo_versions = $pacman->get_perl_distribution_versions($distribution_names);
for my $dist_name ($distribution_names->@*) {
my $repo_version = $repo_versions->{$dist_name};
my $dist = $cpan->get_dist($dist_name);
if ($cpan->is_newer_version_available($dist_name, $repo_version)) {
my $pkgname = $pacman->get_perl_pkgname($dist_name);
$log->infof('New version available for dist \'%s\' in package \'%s\': %s -> %s', $dist_name, $pkgname, $repo_version, $dist->{version});
push @packages, {
dist_name => $dist_name,
repo_version => $repo_version,
cpan_version => $dist->{version},
pkgname => $pkgname,
};
} else {
$log->debugf('Dist \'%s\' is already up to date with version %s', $dist_name, $dist->{version});
}
}
return \@packages;
}
=head3 get_maintainers
my $maintainers = $app->get_maintainers($pkgname);
Accepts a package name and returns the maintainers of the package.
=cut
method get_maintainers($pkgname) {
return $self->{deps}->{archweb}->get_maintainers($pkgname);
}
=head3 add_maintainers
my $packages = $app->get_updateable_packages($distribution_names);
my $packages_with_maintainer = $app->add_maintainers($packages);
print $packages_with_maintainer->[0]->{maintainers}->[0]->{name};
Accepts a list of packages (hashes with the pkgname key) and returns a list
with the maintainer key added to each package.
=cut
method add_maintainers($packages) {
my @packages_with_maintainer;
# fetch package maintainer from archweb
for my $package ($packages->@*) {
push @packages_with_maintainer, {
$package->%*,
maintainers => $self->get_maintainers($package->{pkgname}),
};
}
return \@packages_with_maintainer;
}
=head3 filter_by_maintainer
my $filtered_packages = $app->filter_by_maintainer($packages);
Filter a list of packages to the maintainers whitelisted in the config file.
=cut
method filter_by_maintainer($packages) {
my $allowed_maintainers = {map {$_ => 1} $self->{deps}->{config}->get_config()->{allowed_maintainers}->@*};
return [grep { any {$allowed_maintainers->{$_->{name}}} $_->{maintainers}->@*} $packages->@*];
}
=head3 get_filtered_updateable_packages
my $pkgs = $app->get_filtered_updateable_packages();
High-level method that returns a list of packages from the repository that have
updates available. The list is filtered to only include packages of allowed
maintainers.
=cut
method get_filtered_updateable_packages() {
my $dists = $self->get_distributions_in_repo();
my $dist_names = [map {$_->{dist_name}} $dists->@*];
my $updateable = $self->get_updateable_packages($dist_names);
my $pkgs = $self->add_maintainers($updateable);
my $filtered_pkgs = $self->filter_by_maintainer($pkgs);
return $filtered_pkgs;
}
=head1 LICENSE
Copyright (C) 2018 Florian Pritz E<lt>bluewind@xinu.atE<gt>
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 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/>.
=head1 AUTHOR
Florian Pritz E<lt>bluewind@xinu.atE<gt>
=cut
1;
__END__
|