summaryrefslogtreecommitdiffstats
path: root/bin/devel-tools/parseSusePatterns.pl
blob: 8ccc13da78b73ac45fe22cb1a41b766fdba12eff (plain) (blame)
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
#! /usr/bin/perl
# -----------------------------------------------------------------------------
# Copyright (c) 2006, 2007 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# parseSusePatterns.pl
#	- OpenSLX script to extract a package list from a given list of
#	  SUSE-pattern-files (*.pat).
# -----------------------------------------------------------------------------
use strict;

my $abstract = q[
parseSusePatterns.pl
    This script is a tool for OpenSLX developers that allows to extract
    package lists from a given set of SUSE pattern files.
];

use Getopt::Long;
use Pod::Usage;

my (
	$helpReq,
	$versionReq,

	%patternNames,
	%packageNames,
);

GetOptions(
	'help|?' => \$helpReq,
	'version' => \$versionReq,
) or pod2usage(2);
pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq;
if ($versionReq) {
	system('slxversion');
	exit 1;
}

if ($ARGV[0] !~ m[^(\w+)-(.+)$]) {
	die "can't extract architecture from pattern file name '$ARGV[0]'";
}
my $arch = $2;

foreach my $patternFile (@ARGV) {
	parsePatternFile($patternFile, 1);
}

print join("\n", sort keys %packageNames)."\n";

exit;

sub parsePatternFile
{
	my $patternFile = shift;
	my $outmost = shift;

	if (!open(PAT, "<$patternFile")) {
		return unless $outmost;
		die "unable to open $patternFile";
	}
	undef $/;
	my $content = <PAT>;
	close(PAT);
	$patternNames{$patternFile} = 1;

	if ($content =~ m[^\=Sum.de:\s*(.+?)\s*$]ms) {
		print "+ $1\n";
	}
	if ($content =~ m[^\+Sug:\s*?$(.+?)^\-Sug:\s*?$]ms) {
		addSubPatterns($1);
	}
	if ($content =~ m[^\+Req:\s*?$(.+?)^\-Req:\s*?$]ms) {
		addSubPatterns($1);
	}
	if ($content =~ m[^\+Rec:\s*?$(.+?)^\-Rec:\s*?$]ms) {
		addSubPatterns($1);
	}
	if ($content =~ m[^\+Prq:\s*?$(.+?)^\-Prq:\s*?$]ms) {
		addPkgNames($1);
	}
	if ($content =~ m[^\+Prc:\s*?$(.+?)^\-Prc:\s*?$]ms) {
		addPkgNames($1);
	}
}

sub addSubPatterns
{
	my $patternNames = shift;

	my @subPatterns
		= grep { length($_) > 0 }
		  map { $_ =~ s[^\s*(.+?)\s*$][$1]; $_ }
		  split "\n", $patternNames;

	foreach my $subPattern (@subPatterns) {
		my $subPatternFile = "$subPattern-$arch";
		if (!exists $patternNames{$subPatternFile}) {
			parsePatternFile($subPatternFile);
		}
	}
}

sub addPkgNames
{
	my $pkgs = shift;

	my @pkgNames
		= grep { length($_) > 0 }
		  map { $_ =~ s[^\s*(.+?)\s*$][$1]; $_ }
		  split "\n", $pkgs;
	foreach my $pkgName (@pkgNames) {
		$packageNames{$pkgName} = 1;
	}
}

__END__

=head1 NAME

parseSusePatterns.pl - OpenSLX script to extract a package list from
a given list of SUSE-pattern-files (*.pat).

=head1 SYNOPSIS

parseSusePatterns.pl [options] <pattern-file> ...

  Options:
      --help                   brief help message
      --version                show version

=head1 OPTIONS

=over 8

=item B<--help>

Prints a brief help message and exits.

=item B<--version>

Prints the version and exits.

=back

=cut