[Collab-qa-commits] r1207 - in buildstat/trunk/buildstat-job-manager: . examples

goneri at alioth.debian.org goneri at alioth.debian.org
Wed Sep 3 21:36:53 UTC 2008


Author: goneri
Date: 2008-09-03 21:36:52 +0000 (Wed, 03 Sep 2008)
New Revision: 1207

Modified:
   buildstat/trunk/buildstat-job-manager/buildstat-job-manager
   buildstat/trunk/buildstat-job-manager/examples/lintian.sh
Log:
change buildstat-job-manager so now it can grab the packages itself

Modified: buildstat/trunk/buildstat-job-manager/buildstat-job-manager
===================================================================
--- buildstat/trunk/buildstat-job-manager/buildstat-job-manager	2008-09-03 21:11:30 UTC (rev 1206)
+++ buildstat/trunk/buildstat-job-manager/buildstat-job-manager	2008-09-03 21:36:52 UTC (rev 1207)
@@ -17,6 +17,7 @@
 use HTTP::Response;
 use Getopt::Long;
 use File::Temp;
+use File::Copy;
 
 my $hostname = hostname();
 my $server = "http://buildstat.debian.net";
@@ -27,23 +28,113 @@
 my $params = {
     action => undef,
     qatool => undef,
-    jobfile => undef,
+#    jobfile => undef,
     logfile => undef,
     result => undef,
     target => undef,
     help => undef
 };
 
+sub _apt_line_parse {
+
+    if ($_[0] =~ /^((http|ftp):\/\/\S+)\s+(\S+)\s+(\S+)$/) {
+        return ($1, $3, $4); 
+    }
+
+
+    return;
+}
+
+sub _apt_get_cache {
+    my ($mirror, $distribution, $suite) = @_;
+
+    my $tmp = "$mirror/$distribution/$suite";
+    $tmp =~ s/\//_/;
+    my $cachedir = $ENV{'HOME'}."/.buildstat-job-manager/$tmp";
+   
+    `mkdir -p $cachedir/`;
+
+    return "$cachedir/Packages";
+}
+
+
+sub apt_update {
+    my ($apt_line) = @_;
+    my ($mirror, $distribution, $suite) = _apt_line_parse($apt_line);
+
+    my $cachefile = _apt_get_cache($mirror, $distribution, $suite);
+
+    chomp (my $arch = `dpkg-architecture -qDEB_HOST_ARCH`); # add --arch for that?
+    my $sourcegzurl = $mirror."/dists/$distribution/$suite/binary-$arch/Packages.gz";
+    my ( undef, $remotesize ) = head($sourcegzurl);
+    my ( undef, undef, undef, undef, undef, undef, undef, $localsize ) = stat($cachefile.'.gz');
+
+    if (!-f "$cachefile" || !$localsize || $remotesize != $localsize) {
+        getstore ($sourcegzurl, $cachefile.'.gz');
+        `zcat $cachefile.gz > $cachefile.tmp`;
+        if (0 != $? >> 8 || !move("$cachefile.tmp", "$cachefile")) {
+            unlink 'Packages' or warn;
+            return;
+        }
+    }
+}
+
+
+sub apt_get {
+    my ($apt_line, $sourcepackage) = @_;
+    my ($mirror, $distribution, $suite) = _apt_line_parse($apt_line);
+        
+    apt_update($apt_line);
+
+    my $cachefile = _apt_get_cache($mirror, $distribution, $suite);
+
+    open PACKAGESFILE, "<$cachefile" or die;
+
+    my @files;
+    my $filename;
+    my $source;
+    foreach (<PACKAGESFILE>) {
+
+        if (/^Filename:\s(\S+)/) {
+            $filename = $1;
+        } elsif (/^$/) {
+            push @files, $filename if $source and ($source eq $sourcepackage);
+            $source = $filename = undef;
+        } elsif (/^Source:\s(\S+)/) {
+            $source = $1;
+
+        }
+    }
+
+    close PACKAGESFILE;
+
+    foreach(@files) {
+        print "Downloading ".basename($_)."\n";
+        getstore("$mirror/$_", "./".basename($_));
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+
 sub postFiles {
     my $files = shift;
 
-    die "File not found" unless -f $files->{'jobfile'} || -f $files->{'resultfile'};
+    die "'./jobfile' File not found" unless -f 'jobfile' || -f $files->{'resultfile'};
     my $ua = new LWP::UserAgent;
     $ua->env_proxy;
 
 
     my $job;
-    open JOBFILE, "<".$params->{'jobfile'} or die "Can't open Jobfile:".$!;
+    open JOBFILE, "<jobfile" or die "Can't open Jobfile:".$!;
     foreach (<JOBFILE>) {
         chomp;
 
@@ -87,7 +178,7 @@
 
 
 sub getJob {
-    die unless $params->{'qatool'} && $params->{'jobfile'} && $params->{'target'};
+    die unless $params->{'qatool'} && $params->{'target'};
 
     my $ua  = LWP::UserAgent->new();
     $ua->env_proxy;
@@ -99,7 +190,23 @@
     my $response = $ua->request($req);
     die "Failed to contact server" unless $response->is_success();
 
-    open JOBFILE, ">".$params->{'jobfile'} or die "Can't open ".$params->{'jobfile'}.":$!\n";
+    my $content = $response->content;
+    my %info;
+    foreach (split ("\n", $content)) {
+        if (/\s*(\S+)\s*=\s*(\S.*)/) {
+            $info{$1} = $2;
+        }
+    }
+
+    if ($info{'apt'} && $info{'sourcepackage_name'}) {
+        apt_get($info{'apt'}, $info{'sourcepackage_name'});
+    } elsif ($info{'dscuri'}) {
+        `dget -u -x $info{'dscuri'}`;
+    } else {
+        print "Failed to parse the result\n";
+    }
+
+    open JOBFILE, '>jobfile' or die "Can't open 'jobfile': $!\n";
     print JOBFILE $response->content;
     close JOBFILE;
 }
@@ -156,7 +263,7 @@
 
     postFiles({
 
-            jobfile => $params->{'jobfile'},
+            #jobfile => $params->{'jobfile'},
             resultfile => $params->{'resultfile'},
             logfile => $params->{'logfile'}
 
@@ -166,8 +273,8 @@
 
 sub usage {
     print "usage:\n";
-    print "\tbuildstat-job-manager --action get --qatool QATOOL --jobfile jobfile --target (source|binary)\n";
-    print "\tbuildstat-job-manager --action send --jobfile jobfile --resultfile resultfile (--logfile logfile)\n";
+    print "\tbuildstat-job-manager --action get --qatool QATOOL --target (source|binary)\n";
+    print "\tbuildstat-job-manager --action send --resultfile resultfile (--logfile logfile)\n";
     exit (1);
 }
 
@@ -177,7 +284,7 @@
     "help"          => \$params->{'help'},
     "action=s"      => \$params->{'action'},
     "qatool=s"      => \$params->{'qatool'},
-    "jobfile=s"     => \$params->{'jobfile'},
+#    "jobfile=s"     => \$params->{'jobfile'},
     "logfile=s"     => \$params->{'logfile'},
     "resultfile=s"  => \$params->{'resultfile'},
     "target=s"      => \$params->{'target'},
@@ -185,14 +292,14 @@
 
 usage () unless $params->{'action'};
 if ($params->{'action'} eq 'get') {
-    if ($params->{'qatool'} !~ /^[\w_\+-]+$/ || !$params->{'jobfile'}|| !$params->{'target'}) {
-        print "--qatool=QATOOL, --jobfile=JOBFILE and --target=TARGET are needed\n";
+    if ($params->{'qatool'} !~ /^[\w_\+-]+$/ || !$params->{'target'}) {
+        print "--qatool=QATOOL and --target=TARGET are needed\n";
         usage();
     }
     getJob();
 } elsif ($params->{'action'} eq 'send') {
-    if (!$params->{'jobfile'} || !$params->{'resultfile'}) {
-        print "--jobfile=JOBFILE and --resultfile=RESULTFILE are needed\n";
+    if (!$params->{'resultfile'}) {
+        print "--resultfile=RESULTFILE are needed\n";
     }
     sendJob();
 } else {

Modified: buildstat/trunk/buildstat-job-manager/examples/lintian.sh
===================================================================
--- buildstat/trunk/buildstat-job-manager/examples/lintian.sh	2008-09-03 21:11:30 UTC (rev 1206)
+++ buildstat/trunk/buildstat-job-manager/examples/lintian.sh	2008-09-03 21:36:52 UTC (rev 1207)
@@ -2,8 +2,6 @@
 
 BJM="../buildstat-job-manager"
 
-$BJM --action get --qatool lintian --jobfile jobfile --target binary
-CHANGESFILE=`cat jobfile |grep changesuri|sed 's/changesuri=//'`
-dget -u $CHANGESFILE
-lintian `basename $CHANGESFILE` > lintian.result
-$BJM --action send --jobfile jobfile --resultfile lintian.result
+$BJM --action get --qatool lintian --target binary
+lintian *.deb > lintian.result
+$BJM --action send --resultfile lintian.result




More information about the Collab-qa-commits mailing list