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 
    643643tests/src/vfs/Makefile 
    644644tests/src/vfs/extfs/Makefile 
    645645tests/src/vfs/extfs/helpers-list/Makefile 
     646tests/src/vfs/extfs/helpers-list/misc/Makefile 
    646647]) 
    647648 
    648649AC_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  
    11PACKAGE_STRING = "/src/vfs/extfs/helpers-list" 
    22 
     3SUBDIRS = misc 
     4 
    35AM_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) 
    46 
    57# 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 
     2EXTRA_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 
     2use strict; 
     3use warnings; 
     4use Data::Dumper; 
     5 
     6my $help = <<EOF; 
     7WHAT 
     8---- 
     9 
     10This script converts an RPM package into what we call a "tags file", 
     11which is simply an associative array listing all the tags and their 
     12values. 
     13 
     14WHY 
     15--- 
     16 
     17For our rpm helper tests we need an RPM file. But we also want the tests 
     18to be able to run on systems where the rpm binary isn't installed. The 
     19solution: our tests work on "tags files" instead of real RPM files. 
     20 
     21HOW 
     22--- 
     23 
     24Use it like this: 
     25 
     26    $0 /path/to/some/package.rpm > test.input 
     27 
     28You can run this script only on systems where 'rpm' is installed. 
     29 
     30WHEW 
     31---- 
     32 
     33After all was done the author of this script discovered something not 
     34mentioned in rpm's manpage: one can do "rpm -qp --xml pkg.rpm" to 
     35serialize the metadata and get the same effect. But this would just move 
     36the complexity to the test (in handling XML). 
     37EOF 
     38 
     39# Tag variations we're interested in and wish to record as well. 
     40my @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. 
     51my %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 
     58sub 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 
     77sub 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. 
     89EOF 
     90} 
     91 
     92sub 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 
     103main();