# $Id: Bodhi.pm,v 1.5 2008/10/20 11:38:41 thoger Exp $ # This is how do we interface with the Fedora Update System # Lubomir Kundrak package Libexig::Bodhi; use JSON; use Data::Dumper; # Convert the text blob from bodhi to a hash, # dissect some multipart values # # XXX No longer needed with bodhi 0.5.x XXX sub update_to_hashref { my @lines = split /\n/, shift; my %retval; my $line; my $name; # Rougly process all the fields and header while ($line = shift @lines) { # Header if ($line eq "=" x 80) { $retval{'_NVR'} = ''; do { $line = shift @lines; $line =~ /\s+(.*)/ and $retval{'_NVR'} .= $1; } while ($line ne '=' x 80); # Additional comment lines do not have leading : # This causes havoc on comments including : character } elsif ($line =~ /^\s*(Comments): (.*)/) { $name = $1; # always 'Comments' $retval{$name} = $2; # expect comments until blank line $line = shift @lines; while (defined($line) && $line !~ /^$/) { $line =~ s/^\s*//; $retval{$name} .= "\n$line"; $line = shift @lines; } # Blah: blah } elsif ($line =~ /\s*([^:]*): (.*)/) { $name = $1 if ($1); if (defined $retval{$name}) { $retval{$name} .= "\n$2"; } else { $retval{$name} = $2; } # Update URL } elsif ($line =~ /^ (http.*)/) { $retval{'_Update URL'} = "$1"; } } # Grok bug strings if ($retval{'Bugs'}) { my %bugs; my $bug; foreach (split /\n/, $retval{'Bugs'}) { if (/(\d+) - (.*)/) { $bug = $1; $bugs{$bug} = $2; } else { #$bugs{$bug} .= " $2"; } } $retval{'_Bugs'} = \%bugs; } # Grok raw NVR list my @nvrs = split /,\s*/, $retval{'_NVR'}; $retval{'_NVRs'} = \@nvrs; # Parsing comments, not yet implemented, of no use for us return \%retval; } # Get array of all updates for a package sub get_updates { my $pkg = shift or die 'No package name supplied'; # Get updates $json = `wget --post-data 'package=$pkg&tg_paginate_limit=0' -qO - \\ 'https://admin.fedoraproject.org/updates/list?tg_format=json'`; $obj = from_json ($json); return @{$obj->{'updates'}}; } 1;