#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; use XML::Simple; sub parse_repomd { my $repomd_xml = shift; my $referenced_repomd_files = shift; my $referenced_repomd_primary = shift; my $ref = XMLin(IO::File->new($repomd_xml), ForceArray => ['data']); my $d = $ref->{data}; my $F; my $FP; open (F, ">", $referenced_repomd_files) or die "Failed to open $!"; open (FP, ">", $referenced_repomd_primary) or die "Failed to open $!"; foreach my $data (@$d) { my $loc = $data->{location}{href}; my $type = $data->{type}; if($type eq "primary") { print FP "$loc\n"; } print F "$loc\n"; } close FP; close F; } sub parse_primary { my $referenced_repomd_primary = shift; my $referenced_packages = shift; my @primaries; my $F; my $F_packages; open ($F, "<", $referenced_repomd_primary) or die "Failed to open $!"; while (<$F>) { chomp; push @primaries, $_; } close $F; open (F_packages, ">", $referenced_packages) or die "Failed to open $!"; foreach my $primary (@primaries) { open my $fh, '-|', "gzip --decompress --stdout '$primary'" or die "Failed to open $!"; my $packages = XMLin($fh, ForceArray => ["rpm:entry", "package"], KeyAttr => []); close $fh; foreach my $package (@{$packages->{package}}) { my $loc = $package->{location}{href}; print F_packages "$loc\n"; } } close F_packages; } if ($ARGV[0] =~ '--parse-repomd') { parse_repomd($ARGV[1], $ARGV[2], $ARGV[3]); } elsif ($ARGV[0] =~ '--parse-primary') { parse_primary($ARGV[1], $ARGV[2]); } else { print STDERR "$0: Unhandled $ARGV[0]\n"; } exit 0;