Created
January 26, 2012 22:13
-
-
Save admiral0/1685434 to your computer and use it in GitHub Desktop.
lib32 perl
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
use strict; | |
use warnings; | |
use DBI; | |
use SQLite::DB; | |
use LWP::Simple; | |
use Data::Dumper; | |
my $exit=0; | |
my $db=SQLite::DB->new("packages.sqlite"); | |
$db->connect; | |
my $repo_stable = "http://www.chakra-project.org/repo/lib32/x86_64/"; | |
my $repo_testing = "http://www.chakra-project.org/repo/lib32-testing/x86_64/"; | |
#Repos in which we will search for updated packages | |
my @others= ("http://www.chakra-project.org/repo/games/i686/", | |
"http://www.chakra-project.org/repo/kde-unstable/i686/", | |
"http://www.chakra-project.org/repo/platform/i686/", | |
"http://www.chakra-project.org/repo/testing/i686/", | |
"http://www.chakra-project.org/repo/unstable/i686/", | |
"http://www.chakra-project.org/repo/apps/i686/", | |
"http://www.chakra-project.org/repo/core/i686/", | |
"http://www.chakra-project.org/repo/desktop/i686/" | |
); | |
sub searchrepo{ | |
my $url=shift; | |
$url =~ /repo\/(.*?)\//; | |
my $reponame=$1; | |
my $toparse=get($url); | |
while ($toparse =~ /a href="(.*?\.tar.xz)">/g){ | |
my $pkg=$1; | |
$pkg =~ /(.*)-(.*?)-(.*?)-(.*?).pkg.tar.xz/; | |
my $pname=$1; | |
my $pver=$2; | |
my $pbuild=$3; | |
my $parch=$4; | |
$db->exec("INSERT OR REPLACE INTO 'all_packages' VALUES(\"$pname\",\"$reponame\",\"$pver\",\"$pbuild\",\"$parch\")"); | |
} | |
} | |
sub searchtesting{ | |
my $url=shift; | |
my $toparse=get($url); | |
while ($toparse =~ /a href="(.*?\.tar.xz)">/g){ | |
my $pkg=$1; | |
$pkg =~ /(.*)-(.*?)-(.*?)-(.*?).pkg.tar.xz/; | |
my $pname=$1; | |
my $pver=$2; | |
my $pbuild=$3; | |
my $parch=$4; | |
$db->exec("UPDATE 'lib32' SET testing = '$pver' WHERE name = '$pname'"); | |
} | |
} | |
sub initdb{ | |
$db->exec("CREATE TEMP TABLE IF NOT EXISTS 'all_packages' (name TEXT,repo TEXT, version TEXT, buildver TEXT, arch TEXT);"); | |
$db->exec("CREATE TEMP TABLE IF NOT EXISTS 'lib32' (name TEXT, version TEXT, buildver TEXT, arch TEXT, testing TEXT);"); | |
} | |
sub print_header{ | |
my $date=`date`; | |
chomp $date; | |
print <<HEADER | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Status as of $date</title> | |
<style type="text/css"> | |
div.item,div.warning { | |
border-bottom:1px solid black; | |
} | |
div.childItem { | |
margin-left:30px; | |
} | |
.version{ | |
float:right; | |
margin-right:30%; | |
} | |
.warning{ | |
background-color: yellow; | |
border:1px solid red; | |
} | |
.errorstring { | |
border:2px solid black; | |
background-color:red; | |
color:white; | |
font-weight: 500; | |
font-size: large; | |
margin-top:3px; | |
margin-left:auto; | |
margin-right:auto; | |
display: block; | |
width: 50%; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Packages for lib32</h1> | |
HEADER | |
} | |
sub print_footer{ | |
print <<FOOTER | |
</body> | |
</html> | |
FOOTER | |
} | |
sub setFlags{ | |
my $pkg=shift; | |
my $cpkg=shift; | |
my $flags=shift; | |
if($cpkg->[1] eq "testing"){ | |
if(not $pkg->[4] eq $cpkg->[2]){ | |
$flags->{testing}=1; | |
return; | |
} | |
} | |
if(not $pkg->[1] eq $cpkg->[2]){ | |
$flags->{stable}=1; | |
return 2; | |
} | |
return; | |
} | |
sub fucking_query { | |
my @result; | |
my $sql=shift; | |
$db->select("$sql",sub { | |
my $q=shift; | |
while(my @data=$q->fetchrow_array()){ | |
push @result,\@data; | |
} | |
}); | |
return @result; | |
} | |
sub output_html{ | |
print_header(); | |
my @query=fucking_query("SELECT * from lib32;"); | |
foreach my $pkg (@query){ | |
my $pname=$pkg->[0]; | |
my $pver=$pkg->[1]; | |
my $pbuild=$pkg->[2]; | |
my $parch=$pkg->[3]; | |
my $ptest=$pkg->[4]; | |
my $sname= $pname; | |
$sname =~ s/lib32-//; | |
$sname =~ s/-multilib//; | |
my @pkgs=fucking_query("SELECT * from all_packages where name = '$sname';"); | |
my $childHTML=""; | |
# 1 - stable outdated | |
# 2 - testing outdated | |
my %flags; | |
foreach my $childpkg (@pkgs) { | |
my $cname=$childpkg->[0]; | |
my $crepo=$childpkg->[1]; | |
my $cver=$childpkg->[2]; | |
my $cbuild=$childpkg->[3]; | |
my $carch=$childpkg->[4]; | |
setFlags($pkg,$childpkg,\%flags); | |
$childHTML=$childHTML . "<div class='parentItem'>$cname<span class='version'>$cver</span></span> from <span class='repo'>$crepo</div>"; | |
} | |
my $itemclass="item"; | |
my $errorstring=""; | |
if(exists($flags{testing}) or exists($flags{stable})){ | |
$itemclass="warning"; | |
} | |
if(exists($flags{testing})){ | |
$errorstring="Testing is outdated"; | |
} | |
if(exists($flags{stable})){ | |
$errorstring="Stable is outdated"; | |
} | |
if(exists($flags{testing}) and exists($flags{stable})){ | |
$errorstring="ALL PACKAGES ARE OUTDATED"; | |
} | |
print "<div class='$itemclass'>"; | |
print "<div class='errorstring'>$errorstring</div>" unless $errorstring eq ""; | |
print "<span class='parentItem'>$pname<span class='version'>$pver</span></span><br>"; | |
print "<div class='childItem'>"; | |
print $childHTML; | |
print "</div></div>\n"; | |
} | |
print_footer(); | |
} | |
#print Dumper($db->select("SELECT * from 'kde-unstable'",sub { | |
# my $res=shift; | |
# while(my @data=$res->fetchrow_array()){ | |
# print Dumper(@data); | |
# } | |
#})); | |
initdb(); | |
for my $crepo (@others){ | |
searchrepo($crepo); | |
} | |
searchtesting($repo_testing); | |
my $toparse=get($repo_stable); | |
while ($toparse =~ /a href="(.*?\.tar.xz)">/g){ | |
my $pkg=$1; | |
$pkg =~ /(.*)-(.*?)-(.*?)-(.*?).pkg.tar.xz/; | |
my $pname=$1; | |
my $pver=$2; | |
my $pbuild=$3; | |
my $parch=$4; | |
$db->exec("INSERT OR REPLACE INTO 'lib32' VALUES(\"$pname\",\"$pver\",\"$pbuild\",\"$parch\",'');"); | |
} | |
output_html(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment