Created
April 23, 2014 09:33
-
-
Save anonymous/11208685 to your computer and use it in GitHub Desktop.
/home/romster/var/cwd/remote/projects/sepen-tools/portdb-search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# | |
# Description: Perl script for browsing Crux portdb | |
# Author: Jose V Beneyto, sepen at users dot sourceforge dot net | |
# License: GNU/GPL (http://www.gnu.org/copyleft/gpl.html) | |
use strict; | |
use XML::Parser; | |
use LWP::UserAgent; | |
use HTTP::Request; | |
use Data::Dumper; | |
if ($#ARGV lt 0) { | |
print "usage: $0 [port]\n"; | |
exit; | |
} | |
my $port = $ARGV[0]; | |
# get url | |
my $lua = new LWP::UserAgent; | |
my $url = "http://crux.nu/~tillb/portdb/index.php?q=$port&a=xmlsearch"; | |
my $request = new HTTP::Request(GET => $url); | |
my $result = $lua->request($request); | |
my $xmlcontent = $result->content(); | |
# read xml | |
my $parser = new XML::Parser; | |
$parser->setHandlers(Start => \&startElement, | |
End => \&endElement, | |
Char => \&characterData, | |
Default => \&default); | |
my $content = $parser->parse($xmlcontent); | |
my $tag; | |
sub startElement { | |
my($parseinst, $element, %attrs) = @_; | |
SWITCH: { | |
if ($element eq "port") { | |
$tag = "port"; | |
last SWITCH; | |
} | |
if ($element eq "name") { | |
$tag = "name"; | |
last SWITCH; | |
} | |
if ($element eq "repo") { | |
$tag = "repo"; | |
last SWITCH; | |
} | |
if ($element eq "type") { | |
$tag = "type"; | |
print " "; | |
last SWITCH; | |
} | |
if ($element eq "downloadcommand") { | |
$tag = "downloadcommand"; | |
last SWITCH; | |
} | |
if ($element eq "pkgfile") { | |
$tag = "pkgfile"; | |
print " "; | |
last SWITCH; | |
} | |
if ($element eq "footprint") { | |
$tag = "footprint"; | |
print " "; | |
last SWITCH; | |
} | |
if ($element eq "md5sum") { | |
$tag = "md5sum"; | |
print " "; | |
last SWITCH; | |
} | |
} | |
} | |
sub endElement { | |
my($parseinst, $element) = @_; | |
SWITCH: { | |
if ($element eq "port") { | |
print "\n"; | |
last SWITCH; | |
} | |
if ($element eq "name") { | |
print " ("; | |
last SWITCH; | |
} | |
if ($element eq "repo") { | |
print ")\n"; | |
last SWITCH; | |
} | |
if ($element eq "type") { | |
print " "; | |
last SWITCH; | |
} | |
if ($element eq "downloadcommand") { | |
print "\n"; | |
last SWITCH; | |
} | |
if ($element eq "pkgfile") { | |
print "\n"; | |
last SWITCH; | |
} | |
if ($element eq "footprint") { | |
print "\n"; | |
last SWITCH; | |
} | |
if ($element eq "md5sum") { | |
print "\n"; | |
last SWITCH; | |
} | |
} | |
} | |
sub characterData { | |
my($parseinst, $data) = @_; | |
if ($data eq "httpup" or $data eq "rsync") { | |
print "\$"; | |
} | |
else { | |
# trim data | |
$data =~ s/^\s+//; # start | |
$data =~ s/\s+$//; # emd | |
print $data; | |
} | |
} | |
sub default { | |
my($parseinst, $data) = @_; | |
# you could do something here | |
} | |
# End of File |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment