[Collab-qa-commits] r1180 - in buildstat/trunk/buildstat-job-manager: . examples
goneri at alioth.debian.org
goneri at alioth.debian.org
Thu Aug 28 19:18:40 UTC 2008
Author: goneri
Date: 2008-08-28 19:18:39 +0000 (Thu, 28 Aug 2008)
New Revision: 1180
Added:
buildstat/trunk/buildstat-job-manager/buildstat-job-manager
buildstat/trunk/buildstat-job-manager/examples/
Removed:
buildstat/trunk/buildstat-job-manager/tmp/
Log:
remove the second buildstat-job-manager directory
Copied: buildstat/trunk/buildstat-job-manager/buildstat-job-manager (from rev 1179, buildstat/trunk/buildstat-job-manager/tmp/buildstat-job-manager)
===================================================================
--- buildstat/trunk/buildstat-job-manager/buildstat-job-manager (rev 0)
+++ buildstat/trunk/buildstat-job-manager/buildstat-job-manager 2008-08-28 19:18:39 UTC (rev 1180)
@@ -0,0 +1,198 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+
+use Data::Dumper;
+use Net::FTP;
+use File::Glob ':glob';
+use Sys::Hostname;
+#use SvnBuildStat::Config;
+use LWP::Simple;
+use POSIX ":sys_wait_h";
+use File::Basename;
+use File::stat;
+use HTTP::Request::Common;
+use LWP::UserAgent;
+use HTTP::Response;
+use Getopt::Long;
+use File::Temp;
+
+my $hostname = hostname();
+my $server = "http://buildstat.debian.net";
+my $admin = "Unamed User <unamed.user\@example.net>";
+
+my $params = {
+ action => undef,
+ qatool => undef,
+ jobfile => undef,
+ logfile => undef,
+ result => undef,
+ target => undef,
+ help => undef
+};
+
+sub postFiles {
+ my $files = shift;
+
+ die "File not found" unless -f $files->{'jobfile'} || -f $files->{'resultfile'};
+ my $ua = new LWP::UserAgent;
+
+
+ my $job;
+ open JOBFILE, "<".$params->{'jobfile'} or die "Can't open Jobfile:".$!;
+ foreach (<JOBFILE>) {
+ chomp;
+
+ $job->{$1} = $2 if (/(.*)=(.*)/);
+ }
+ close JOBFILE;
+
+ die "Invalide jobfile" unless $job->{'cookie'};
+ my $timestamp = time."-".$job->{'cookie'};
+ # The 'files' is used by the server to find the related files
+ $job->{'resultfile'} = $timestamp.'.resultfile';
+ if ($job->{'logfile'}) {
+ $job->{'logfile'} = $timestamp.'.logfile';
+ }
+
+
+ my $jobfile_fh = new File::Temp();
+ foreach (keys %$job) {
+ print $jobfile_fh $_."=".$job->{$_}."\n";
+ }
+ close $jobfile_fh;
+ $files->{'jobfile'} = $jobfile_fh->filename;
+ print $jobfile_fh->filename."\n";
+
+
+ # Order is important here since the .jobfile is used at the
+ # server side to start the import task
+ foreach (qw/logfile resultfile jobfile/) {
+ next unless $files->{$_};
+ next unless -f $files->{$_};
+
+ print "upload $_...\n";
+ my $response = $ua->request(POST $server.'/controls/buildInput',
+ Content_Type => 'form-data',
+ Content => ['file' => [ $files->{$_}, $timestamp.'.'.$_ ]]) or die "Upload failed\n";
+
+ #print "report sent: ".$response->as_string()."\n";
+ }
+
+}
+
+
+sub getJob {
+ die unless $params->{'qatool'} && $params->{'jobfile'} && $params->{'target'};
+
+ my $ua = LWP::UserAgent->new();
+ my $req = POST $server."/controls/getQAJob", Content_Type => 'form-data',
+ Content => [
+ submit => 1,
+ content => "qatool=".$params->{'qatool'}."\ntarget=".$params->{'target'},
+ ];
+ 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";
+ print JOBFILE $response->content;
+ close JOBFILE;
+}
+
+
+sub sendJob {
+
+ my ($report, $threadbuildarea) = @_;
+
+ print "sending result\n";
+
+ $report->{'admin'} = $admin;
+ $report->{hostname} = $hostname;
+
+
+# open (BUILDLOGTMP, "<","$threadbuildarea/build.log.tmp") or die;
+# seek(BUILDLOGTMP, -2000000, 2); # I just keep the end of the logfile
+# open (BUILDLOG, ">", "$threadbuildarea/".$logfile) or die;
+# # If I'm not at the end of BUILDLOGTMP it means that seek moved me
+# print BUILDLOG "(log file truncated) ... " if tell(BUILDLOGTMP);
+#
+# foreach (<BUILDLOGTMP>) {
+# # To avoid strange breakage I do some clean up in the log file
+# s/[[:cntrl:]]//g;
+# print BUILDLOG $_."\n";
+# }
+# close BUILDLOGTMP;
+# close BUILDLOG;
+# unlink "$threadbuildarea/build.log.tmp";
+
+# postFile($threadbuildarea."/".$logfile);
+# $report->{logfile} = $logfile;
+# if (bsd_glob($threadbuildarea.'/*.changes')) {
+# print "build is ok\n";
+# $report->{build} = "ok";
+# foreach (bsd_glob($threadbuildarea.'/*.deb'), bsd_glob($threadbuildarea.'/*.udeb')) {
+# $report->{binarypackages} = basename($_).' ';
+# postFile($_);
+# }
+# } else {
+# print "build is nok\n";
+# $report->{build} = "nok";
+# }
+#
+#
+# open (BUILDREPORT,">",$threadbuildarea."/".$infofile) or die "Can't open infofile";
+# foreach (sort keys %$report) {
+# chomp $report->{$_};
+# print BUILDREPORT $_."=".$report->{$_}."\n";
+# }
+# print BUILDREPORT "-END-\n";
+# close BUILDREPORT;
+# postFile ($threadbuildarea."/".$infofile);
+
+postFiles({
+
+ jobfile => $params->{'jobfile'},
+ resultfile => $params->{'resultfile'},
+ logfile => $params->{'logfile'}
+
+ });
+
+}
+
+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";
+ exit (1);
+}
+
+
+my $verbose;
+usage unless GetOptions (
+ "help" => \$params->{'help'},
+ "action=s" => \$params->{'action'},
+ "qatool=s" => \$params->{'qatool'},
+ "jobfile=s" => \$params->{'jobfile'},
+ "logfile=s" => \$params->{'logfile'},
+ "resultfile=s" => \$params->{'resultfile'},
+ "target=s" => \$params->{'target'},
+);
+
+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";
+ usage();
+ }
+ getJob();
+} elsif ($params->{'action'} eq 'send') {
+ if (!$params->{'jobfile'} || !$params->{'resultfile'}) {
+ print "--jobfile=JOBFILE and --resultfile=RESULTFILE are needed\n";
+ }
+ sendJob();
+} else {
+ print "action is 'get' or 'send'.\n";
+ usage();
+}
+
Copied: buildstat/trunk/buildstat-job-manager/examples (from rev 1179, buildstat/trunk/buildstat-job-manager/tmp/examples)
Property changes on: buildstat/trunk/buildstat-job-manager/examples
___________________________________________________________________
Name: svn:mergeinfo
+
More information about the Collab-qa-commits
mailing list