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

goneri at alioth.debian.org goneri at alioth.debian.org
Sun Sep 7 21:53:19 UTC 2008


Author: goneri
Date: 2008-09-07 21:53:18 +0000 (Sun, 07 Sep 2008)
New Revision: 1232

Modified:
   buildstat/trunk/buildstat-job-manager/buildstat-job-manager
   buildstat/trunk/buildstat-job-manager/examples/lintian.sh
Log:
add the target both and generate a .changes file is needed

Modified: buildstat/trunk/buildstat-job-manager/buildstat-job-manager
===================================================================
--- buildstat/trunk/buildstat-job-manager/buildstat-job-manager	2008-09-07 20:20:17 UTC (rev 1231)
+++ buildstat/trunk/buildstat-job-manager/buildstat-job-manager	2008-09-07 21:53:18 UTC (rev 1232)
@@ -16,8 +16,10 @@
 use LWP::UserAgent;
 use HTTP::Response;
 use Getopt::Long;
-use File::Temp;
+use File::Temp qw/ tempfile /;
 use File::Copy;
+use File::stat;
+use Cwd;
 
 my $hostname = hostname();
 my $server = "http://buildstat.debian.net";
@@ -25,6 +27,9 @@
 my $debmirror = "http://ftp.fr.debian.org/debian";
 #$dscuri =~ s/\@DEB_MIRROR\@/http:\/\/ftp.fr.debian.org\/debian/;
 
+
+chomp (my $arch = `dpkg-architecture -qDEB_HOST_ARCH`); # add --arch for that?
+
 my $params = {
     action => undef,
     qatool => undef,
@@ -64,12 +69,20 @@
 
     my $cachefile = _apt_get_cache($mirror, $distribution, $suite);
 
-    chomp (my $arch = `dpkg-architecture -qDEB_HOST_ARCH`); # add --arch for that?
+    if (-f $cachefile) {
+        my $st = stat($cachefile);
+        if ($st->ctime > time - 3600) {
+            print "No need to refresh the cache\n";
+            return;
+        }
+    }
+
     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) {
+        print "fetching a fresh Package.gz\n";
         getstore ($sourcegzurl, $cachefile.'.gz');
         `zcat $cachefile.gz > $cachefile.tmp`;
         if (0 != $? >> 8 || !move("$cachefile.tmp", "$cachefile")) {
@@ -93,38 +106,79 @@
     my @files;
     my $filename;
     my $source;
+    my $package;
     foreach (<PACKAGESFILE>) {
 
         if (/^Filename:\s(\S+)/) {
             $filename = $1;
         } elsif (/^$/) {
-            push @files, $filename if $source and ($source eq $sourcepackage);
-            $source = $filename = undef;
+            if (($source and ($source eq $sourcepackage)) or ($package and ($package eq $sourcepackage))) {
+                push @files, $filename;
+            }
+            $package = $source = $filename = undef;
+        } elsif (/^Package:\s(\S+)/) {
+            $package = $1;
         } elsif (/^Source:\s(\S+)/) {
             $source = $1;
-
         }
     }
 
     close PACKAGESFILE;
 
+    my @ret;
     foreach(@files) {
         print "Downloading ".basename($_)."\n";
         getstore("$mirror/$_", "./".basename($_));
+        push @ret, basename($_);
     }
+
+    return \@ret;
 }
 
 
+sub createFakeChangesFile {
+    my ($debs, $sourcedir) = @_;
+    print "Creating a fake .changes\n";
 
+    my ($fh, $debianfiles) = tempfile();
 
+    my $source;
+    my $package;
+    my $version;
+    foreach my $deb (@$debs) {
+        my $section;
+        my $priority;  
 
+        foreach (`LC_ALL=C dpkg -I $deb`) {
+            $section = $1 if /^\sSection:\s(\S+)/;
+            $priority = $1 if /^\sPriority:\s(\S+)/;
+            $source = $1 if /^\sSource:\s(\S+)/;
+            $version = $1 if /^\sVersion:\s(\S+)/;
+            $package = $1 if /^\sPackage:\s(\S+)/;
+        }
+        $source = $package unless $source;
+        die "dpkg -I $deb failed" unless $section && $priority && $source && $version;
+        print $fh "$deb $section $priority\n";
 
+    }
 
+    my $basecwd = getcwd;
+    chdir($sourcedir);
+    my $cmd = "dpkg-genchanges -f$debianfiles > ../${source}_${version}_${arch}.changes";
+    `$cmd`;
+    chdir($basecwd);
+    close $fh;
+}
 
 
 
 
 
+
+
+
+
+
 sub postFiles {
     my $files = shift;
 
@@ -198,14 +252,40 @@
         }
     }
 
+
+    my $ok;
+    my $debs;
+    my $sourcedir;
     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";
+        $debs = apt_get($info{'apt'}, $info{'sourcepackage_name'});
+        $ok = 1;
     }
+    if ($info{'dscuri'}) {
+        my $cmd = "LC_ALL=C dget -u -x ".$info{'dscuri'};
+        $cmd =~ s/\@DEB_MIRROR\@/$debmirror/;
+        print $cmd."\n";
+        foreach (`$cmd`) {
+            $sourcedir = $1 if /dpkg-source:\sextracting\s\S+\sin\s(\S+)/;
+        }
 
+
+        # Deb + sources => I create a fake .changes file
+        if (@$debs) {
+            createFakeChangesFile ($debs, $sourcedir); 
+
+        }
+
+        $ok = 1;
+    }
+    if ($info{'changesuri'}) {
+        my $cmd = "LC_ALL=C dget -u -x ".$info{'changesuri'};
+        $cmd =~ s/\@DEB_MIRROR\@/$debmirror/;
+        print $cmd."\n";
+    }
+
+
+    print STDERR "Failed to parse the result\n" unless $ok;
+
     open JOBFILE, '>jobfile' or die "Can't open 'jobfile': $!\n";
     print JOBFILE $response->content;
     close JOBFILE;
@@ -273,7 +353,7 @@
 
 sub usage {
     print "usage:\n";
-    print "\tbuildstat-job-manager --action get --qatool QATOOL --target (source|binary)\n";
+    print "\tbuildstat-job-manager --action get --qatool QATOOL --target (source|binary|both)\n";
     print "\tbuildstat-job-manager --action send --resultfile resultfile (--logfile logfile)\n";
     exit (1);
 }

Modified: buildstat/trunk/buildstat-job-manager/examples/lintian.sh
===================================================================
--- buildstat/trunk/buildstat-job-manager/examples/lintian.sh	2008-09-07 20:20:17 UTC (rev 1231)
+++ buildstat/trunk/buildstat-job-manager/examples/lintian.sh	2008-09-07 21:53:18 UTC (rev 1232)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-BJM="../buildstat-job-manager"
+BJM="../../buildstat-job-manager"
 
 $BJM --action get --qatool lintian --target binary
 lintian *.deb > lintian.result




More information about the Collab-qa-commits mailing list