Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/11208685 to your computer and use it in GitHub Desktop.
Save anonymous/11208685 to your computer and use it in GitHub Desktop.
/home/romster/var/cwd/remote/projects/sepen-tools/portdb-search
#!/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