From 2b6f8157feaaa81b00604a3f0a383ae06df36e0c Mon Sep 17 00:00:00 2001 From: Olivier Thauvin Date: Sat, 17 Apr 2004 23:31:06 +0000 Subject: - add Query.pm (starting to code) - add fuzzy_parse function, transparency parse hdlist, synthesis, rpms or dir (dir/*.rpm) - add parse_rpms function to have same behaviours than parse_{hdlists,synthesis} --- URPM/Build.pm | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'URPM/Build.pm') diff --git a/URPM/Build.pm b/URPM/Build.pm index 0282c8b..88e6d5b 100644 --- a/URPM/Build.pm +++ b/URPM/Build.pm @@ -65,13 +65,11 @@ sub parse_rpms_build_headers { } } - my $pkg = $urpm->{depslist}[$id]; $filename = $pkg->fullname; "$filename.rpm" eq $pkg->filename or $filename .= ":$key"; - $options{silent} or print STDERR "$dir/$filename\n"; unless (-s "$dir/$filename") { open F, ">$dir/$filename" or die "unable to open $dir/$filename for writing\n"; $pkg->build_header(fileno *F); @@ -85,6 +83,11 @@ sub parse_rpms_build_headers { } else { $pkg->pack_header; } + + # Olivier Thauvin + # isn't this code better, but maybe it will break some tools: + # $options{callback}->($urpm, $id, %options, (file => $_)) if ($options{callback}); + # $pkg->pack_header; } #- keep track of header associated (to avoid rereading rpm filename directly @@ -127,6 +130,47 @@ sub parse_headers { defined $id ? ($start, $id) : @{[]}; } +# parse_rpms, to same bevaviour than parse_{hdlist, synthesis} +# ie: ($start, $end) = parse_*(filestoparse, %options); + +sub parse_rpms { + my ($urpm, $rpms, %options) = @_; + my ($start, $end); + $urpm->parse_rpms_build_headers( + rpms => $rpms, + %options, + callback => sub { + my ($urpm, $id) = @_; + $start = $id if($start > $id || ! defined($start)); + $end = $id if($end < $id || ! defined($end)); + } + ) ? ($start, $end) : (); +} + +# fuzzy_parse is a simple wrapper for parse_rpm* function +# It detect if the file passed is a dir, an hdlist, a synthesis or a rpm +# it call the good function. +sub fuzzy_parse { + my ($urpm, %options) = @_; + my ($start, $end); + foreach my $entry (@{$options{paths} || []}) { + if (-d $entry) { # it is a dir + ($start, $end) = $urpm->parse_rpms([ glob("$entry/*.rpm") ], %options); + defined ($start) and return ($start .. $end); + } else { # we try some methode to load the file + ($start, $end) = $urpm->parse_hdlist($entry); + defined ($start) and return ($start .. $end); + + ($start, $end) = $urpm->parse_synthesis($entry); + defined ($start) and return ($start .. $end); + + ($start, $end) = $urpm->parse_rpms([ $entry ], %options); + defined ($start) and return ($start .. $end); + } + } + () +} + #- compute dependencies, result in stored in info values of urpm. #- operations are incremental, it is possible to read just one hdlist, compute #- dependencies and read another hdlist, and again. -- cgit v1.2.1