aboutsummaryrefslogtreecommitdiffstats
path: root/URPM/Query.pm
blob: 01548e875da3fcb867b9e28156ec1060ad0633c4 (plain)
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
package URPM;

use strict;

# Olivier Thauvin <thauvin@aerov.jussieu.fr>
# This package extend URPM functions to permit
# URPM low level query on rpm header
# $Id$

# tag2id
# INPUT array of rpm tag name
# Return an array of ID tag

sub tag2id {
	my %taglist = URPM::list_rpm_tag;
	map { $taglist{uc("RPMTAG_$_")} || undef } @_;
}

# id2tag
# INPUT array of rpm id tag
# Return an array of tag name

sub id2tag {
	my @id = @_;
	my %taglist = URPM::list_rpm_tag;
	my @ret;
	foreach my $thisid (@id) {
		my $res = grep { $taglist{$_} == $thisid } keys (%taglist);
		$res =~ s/^RPMTAG_//;
		push (@ret, $res ? $res : undef);
	}
	@ret
}

sub query_pkg {
   my ($urpm, $pkg, $query) = @_;
   my @tags = map {
	   [ $pkg->get_tag(tag2id($_)) ]
   } $query =~ m/\%\{([^{}]*)\}*/g;

   $query =~ s/\%\{[^{}]*\}/%s/g;
   $query =~ s/\\n/\n/g;
   $query =~ s/\\t/\t/g;
   my ($max, @res) = 0;

   foreach (@tags) { $max < $#{$_} and $max = $#{$_} };
   
   foreach my $i (0 .. $max) {
	   push(@res, sprintf($query, map { ${$_}[ $#{$_} < $i ? $#{$_} : $i ] } @tags));
   }
   @res	   
}


1;