1
0
mirror of https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git synced 2025-09-24 15:18:49 +00:00
os-autoinst-distri-fedora/lib/modularity.pm
Adam Williamson f0b9bd3e94 Add a simple perl lint script and fix all the errors it found
This adds a script that checks for common whitespace issues
(per our house style) and can (if run with --write) correct some
of them. It adds a run of the script (without --write) to the
tox config, and includes fixes for all the issues the script
discovered in the existing tests and libs.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
2022-07-27 11:33:29 -07:00

47 lines
1.3 KiB
Perl

package modularity;
use strict;
use base 'Exporter';
use Exporter;
use lockapi;
use testapi;
use utils;
our @EXPORT = qw(parse_module_list is_listed);
# This subroutine takes the output from the dnf module list command
# and deletes all unnecessary stuff and returns an array of hash
# references where each hash consists of (module, stream, profile).
# The subroutine only recognizes one profile but it is enough
# for the sake of the modularity testing.
sub parse_module_list {
my $output = shift;
my @output_lines = split(/\n/, $output);
my @parsed_list;
foreach my $line (@output_lines) {
my ($module, $stream, $profile) = split(/\s+/, $line);
unless ($module =~ /Fedora|Last|Hint|Name|^$/) {
$profile =~ s/,$//;
my %module = ("module" => $module, "stream" => $stream, "profile" => $profile);
push(@parsed_list, \%module);
}
}
return @parsed_list;
}
# This subroutine iterates over the given list of module hashes and returns True
# if it finds it in the list.
sub is_listed {
my ($module, $stream, $listref) = @_;
my $found = 0;
foreach (@{ $listref }) {
if ($_->{module} eq $module and $_->{stream} eq $stream) {
$found = 1;
}
}
return $found;
}