extfs: rpm: move misc/* to misc/rpm/*.
[midnight-commander.git] / tests / src / vfs / extfs / helpers-list / misc / rpm / rpm2tags.pl
blobc77640797f32daf99950151c1cd238afc1bd8996
1 use strict;
2 use warnings;
3 use Data::Dumper;
5 my $help = <<EOF;
6 WHAT
7 ----
9 This script converts an RPM package into what we call a "tags file",
10 which is simply an associative array listing all the tags and their
11 values.
13 WHY
14 ---
16 For our rpm helper tests we need an RPM file. But we also want the tests
17 to be able to run on systems where the rpm binary isn't installed. The
18 solution: our tests work on "tags files" instead of real RPM files.
20 HOW
21 ---
23 Use it like this:
25 \$ perl $0 /path/to/some/package.rpm > test.input
27 You can run this script only on systems where 'rpm' is installed.
29 WHEW
30 ----
32 After all was done the author of this script discovered something not
33 mentioned in rpm's manpage: one can do "rpm -qp --xml pkg.rpm" to
34 serialize the metadata and get the same effect. But this would just move
35 the complexity to the test (in handling XML).
36 EOF
38 # Tag variations we're interested in and wish to record as well.
39 my @formatted_tags = qw(
40 BUILDTIME:date
41 CHANGELOGTIME:date
43 REQUIREFLAGS:depflags
44 PROVIDEFLAGS:depflags
45 OBSOLETEFLAGS:depflags
46 CONFLICTFLAGS:depflags
49 # Big tags we want to omit to save space.
50 my %skip = map {$_ => 1} qw(
51 HEADERIMMUTABLE
54 # Make 'rpm' print dates in the format our helper expects.
55 $ENV{'LC_TIME'} = 'C';
57 sub rpm2tags
59 my ($rpm_pkg) = @_;
61 my %tags = ();
63 chomp(my @all_tags = `rpm --querytags`);
64 @all_tags = grep {!$skip{$_}} @all_tags;
66 foreach my $tag (@all_tags, @formatted_tags) {
67 $tags{$tag} = `rpm -qp --qf "%{$tag}" "$rpm_pkg"`;
70 # Add pseudo tags:
71 $tags{'_INFO'} = `rpm -qip "$rpm_pkg"`;
73 return %tags;
76 sub prolog
78 my $cmdline = join(' ', 'perl', $0, @ARGV);
79 return <<EOF;
80 # -*- mode: perl -*-
81 # vim: filetype=perl
83 # This "tags file" was created by running the following command:
85 # \$ $cmdline
87 # This file is used in our tests instead of the corresponding RPM file.
88 # This lets us run the tests on systems where 'rpm' is not installed.
89 EOF
92 sub main
94 if (!$ARGV[0] || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
95 print $help;
96 exit;
98 my %tags = rpm2tags($ARGV[0]);
99 $Data::Dumper::Terse = 1;
100 print(prolog(), "\n", '$tags = ', Dumper(\%tags), ";\n");
103 main();