Ticket #3751: 3751-0003-extfs-rpm-introduce-the-rpm2tags-tool.patch
File 3751-0003-extfs-rpm-introduce-the-rpm2tags-tool.patch, 4.4 KB (added by mooffie, 8 years ago) |
---|
-
configure.ac
From 0b6ccc0b9009347afb7ea772c03e2aad14fa3017 Mon Sep 17 00:00:00 2001 From: Mooffie <mooffie@gmail.com> Date: Mon, 2 Jan 2017 06:07:34 +0200 Subject: [PATCH 3/4] Ticket #3751: extfs: rpm: introduce the rpm2tags tool. This is a preliminary step before being able to write tests for our rpm helper. We introduce 'rpm2tags', a tool for converting RPM packages to parsable text files. This will enable us to write tests that can run even where the 'rpm' program isn't installed. Signed-off-by: Mooffie <mooffie@gmail.com> --- configure.ac | 1 + tests/src/vfs/extfs/helpers-list/Makefile.am | 2 + tests/src/vfs/extfs/helpers-list/misc/Makefile.am | 2 + tests/src/vfs/extfs/helpers-list/misc/rpm2tags | 103 ++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 tests/src/vfs/extfs/helpers-list/misc/Makefile.am create mode 100755 tests/src/vfs/extfs/helpers-list/misc/rpm2tags diff --git a/configure.ac b/configure.ac index 87576f0..c128c09 100644
a b tests/src/editor/test-data.txt 643 643 tests/src/vfs/Makefile 644 644 tests/src/vfs/extfs/Makefile 645 645 tests/src/vfs/extfs/helpers-list/Makefile 646 tests/src/vfs/extfs/helpers-list/misc/Makefile 646 647 ]) 647 648 648 649 AC_OUTPUT -
tests/src/vfs/extfs/helpers-list/Makefile.am
diff --git a/tests/src/vfs/extfs/helpers-list/Makefile.am b/tests/src/vfs/extfs/helpers-list/Makefile.am index a0a28e9..79d3d2c 100644
a b 1 1 PACKAGE_STRING = "/src/vfs/extfs/helpers-list" 2 2 3 SUBDIRS = misc 4 3 5 AM_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) 4 6 5 7 # This lets mc_parse_ls_l.c override MC's message() without the linker -
new file tests/src/vfs/extfs/helpers-list/misc/Makefile.am
diff --git a/tests/src/vfs/extfs/helpers-list/misc/Makefile.am b/tests/src/vfs/extfs/helpers-list/misc/Makefile.am new file mode 100644 index 0000000..b05f611
- + 1 2 EXTRA_DIST = rpm2tags -
new file tests/src/vfs/extfs/helpers-list/misc/rpm2tags
diff --git a/tests/src/vfs/extfs/helpers-list/misc/rpm2tags b/tests/src/vfs/extfs/helpers-list/misc/rpm2tags new file mode 100755 index 0000000..b3c80cd
- + 1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 use Data::Dumper; 5 6 my $help = <<EOF; 7 WHAT 8 ---- 9 10 This script converts an RPM package into what we call a "tags file", 11 which is simply an associative array listing all the tags and their 12 values. 13 14 WHY 15 --- 16 17 For our rpm helper tests we need an RPM file. But we also want the tests 18 to be able to run on systems where the rpm binary isn't installed. The 19 solution: our tests work on "tags files" instead of real RPM files. 20 21 HOW 22 --- 23 24 Use it like this: 25 26 $0 /path/to/some/package.rpm > test.input 27 28 You can run this script only on systems where 'rpm' is installed. 29 30 WHEW 31 ---- 32 33 After all was done the author of this script discovered something not 34 mentioned in rpm's manpage: one can do "rpm -qp --xml pkg.rpm" to 35 serialize the metadata and get the same effect. But this would just move 36 the complexity to the test (in handling XML). 37 EOF 38 39 # Tag variations we're interested in and wish to record as well. 40 my @formatted_tags = qw( 41 BUILDTIME:date 42 CHANGELOGTIME:date 43 44 REQUIREFLAGS:depflags 45 PROVIDEFLAGS:depflags 46 OBSOLETEFLAGS:depflags 47 CONFLICTFLAGS:depflags 48 ); 49 50 # Big tags we want to omit to save space. 51 my %skip = map {$_ => 1} qw( 52 HEADERIMMUTABLE 53 ); 54 55 # Make 'rpm' print dates in the format our helper expects. 56 $ENV{'LC_TIME'} = 'C'; 57 58 sub rpm2tags 59 { 60 my ($rpm_pkg) = @_; 61 62 my %tags = (); 63 64 chomp(my @all_tags = `rpm --querytags`); 65 @all_tags = grep {!$skip{$_}} @all_tags; 66 67 foreach my $tag (@all_tags, @formatted_tags) { 68 $tags{$tag} = `rpm -qp --qf "%{$tag}" "$rpm_pkg"`; 69 } 70 71 # Add pseudo tags: 72 $tags{'_INFO'} = `rpm -qip "$rpm_pkg"`; 73 74 return %tags; 75 } 76 77 sub prolog 78 { 79 my $cmdline = join(' ', $0, @ARGV); 80 return <<EOF; 81 # -*- Perl -*- 82 # 83 # This "tags file" was created by running the following command: 84 # 85 # \$ $cmdline 86 # 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 90 } 91 92 sub main 93 { 94 if (!$ARGV[0] || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") { 95 print $help; 96 exit; 97 } 98 my %tags = rpm2tags($ARGV[0]); 99 $Data::Dumper::Terse = 1; 100 print(prolog(), "\n", '$tags = ', Dumper(\%tags), ";\n"); 101 } 102 103 main();