[Collab-qa-commits] r661 - svnbuildstat/trunk/lib/SvnBuildStat/Controller

goneri-guest at alioth.debian.org goneri-guest at alioth.debian.org
Sat Jan 19 17:51:08 UTC 2008


Author: goneri-guest
Date: 2008-01-19 17:51:08 +0000 (Sat, 19 Jan 2008)
New Revision: 661

Added:
   svnbuildstat/trunk/lib/SvnBuildStat/Controller/Controls.pm
Log:
initial import

Added: svnbuildstat/trunk/lib/SvnBuildStat/Controller/Controls.pm
===================================================================
--- svnbuildstat/trunk/lib/SvnBuildStat/Controller/Controls.pm	                        (rev 0)
+++ svnbuildstat/trunk/lib/SvnBuildStat/Controller/Controls.pm	2008-01-19 17:51:08 UTC (rev 661)
@@ -0,0 +1,186 @@
+package SvnBuildStat::Controller::Controls;
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller';
+
+use File::Basename;
+
+
+sub loadInfofile {
+    my $infofile = shift;
+
+    my $ret = {};
+
+
+    my $endOfFile;
+    if (open (INFOFILE, "<".$infofile)) {
+        foreach (<INFOFILE>) {
+            $ret->{$1} = $2 if /^(.*?)=(.*)$/;
+            if (/^-END-$/) {
+                $endOfFile = 1;
+                last;
+            }
+        }
+        close INFOFILE;
+    } else {
+        print "failed to open ".$infofile."\n";
+        return;
+    }
+    return unless $endOfFile;
+
+    my $basename = basename($infofile);
+    $ret->{packagesrc} = $1 if $basename =~ /^(.*?)_/;
+
+    return unless $ret->{packagesrc} or $ret->{id};
+
+    return $ret;
+}
+
+
+sub getBuildJob : Local {
+    my ( $self, $c, $param ) = @_;
+
+    my $archs = "(i386|m68k|sparc|alpha|powerpc|".
+        "arm|mips|mipsel|hppa|ia64|s390|amd64|".
+        "ppc64|sh|armeb|m32r|hurd-i386|kfreebsd-gnu)";
+
+    my @uploadedFiles;
+    my $uploaddir = $c->config->{path}->{uploaddir};
+    use Data::Dumper;
+    die unless $c->request->body_parameters->{content};
+
+    my $params = {};
+    foreach (split $/, $c->request->body_parameters->{content}) {
+        if (/(\S*)=(\S+)/) {
+            $params->{$1} = $2;
+        }
+
+    }
+
+    if (!(defined ($params->{arch}) && $params->{arch} =~ /$archs/)) {
+        die "unspported arch";
+    }
+
+    my $changelogentry_id = $c->model('SvnBuildStat::Model::DB::Viewtobuild')->search({$params->{arch} => 'true' })->first->changelogentry_id;
+    my $changelogentry = $c->model('SvnBuildStat::Model::DB::Changelogentry')->search ({id => $changelogentry_id})->first;
+
+# lastbuildstart should in changelogentry directly
+    $changelogentry->lastbuildstart('now');
+    $changelogentry->update();
+
+
+    my $dscuri = $changelogentry->dscuri;
+    my $repositoryurl = $c->config->{path}->{repositoryurl};
+    $dscuri =~ s/\@REPOSITORY_URL@/$repositoryurl/;
+
+    $c->response->body("action=build\ndsc=$dscuri\nid=".$changelogentry->id);
+
+
+}
+
+sub getQAJob : Local {
+    my ( $self, $c, $param ) = @_;
+
+    my @uploadedFiles;
+    my $uploaddir = $c->config->{path}->{uploaddir};
+    use Data::Dumper;
+    die unless $c->request->body_parameters->{content};
+
+    my $params = {};
+    foreach (split $/, $c->request->body_parameters->{content}) {
+        if (/(\S*)=(\S+)/) {
+            $params->{$1} = $2;
+        }
+
+    }
+
+
+
+    die "checks key invalid" unless $params->{checks};
+
+    my $tmp = {};
+    $tmp = pickPackageToCheck($self, $c, $params);
+
+    my $ret;
+    foreach (keys %$tmp) {
+        $ret .= $_.'='.$tmp->{$_}."\n";
+    }
+
+    $c->response->body($ret);
+
+}
+
+
+
+# TODO purge the files
+sub sendFile : Local {
+    my ( $self, $c, $param ) = @_;
+
+    my @uploadedFiles;
+    my $uploaddir = $c->config->{path}->{uploaddir};
+    my $upload = $c->request->upload('file');
+    my $target = $uploaddir.'/'.basename($upload->filename);
+    if (!$upload->copy_to($target)) {
+        $c->response->body("ko ".$!);
+    }
+
+
+    my $infofile;
+    if ($target =~ /\.info$/) {
+        $infofile = loadInfofile($target);
+
+# just in case a file is missing  
+        if (exists $infofile->{binarypackages}) {
+            foreach (split(' ', $uploaddir.'/'.$infofile->{binarypackages})) {
+                next unless -f $uploaddir.'/'.$_;
+                die("ko can't find all the binary files");
+            }
+        }
+        if (!-f $uploaddir.'/'.$infofile->{logfile}) { 
+            die("ko can't find the log file");
+        }
+
+        my $log;  
+        if (open LOGFILE, "<".$uploaddir.'/'.$infofile->{logfile}) {
+
+            seek(LOGFILE, -20000, 2); # I just keep the end of the logfile
+# If I'm not at the end of BUILDLOGTMP means that seek moved the cursor
+                $infofile->{log_file} = "(log file truncated) ... " if tell(LOGFILE);
+            foreach (<LOGFILE>) {
+# To avoid strange breakage I do some clean up in the log file
+                s/[[:cntrl:]]//g;
+                $log .= $_;
+            }
+            close LOGFILE;
+        } else {
+            die ("Can't open ".$uploaddir.'/'.$infofile->{logfile});
+        }
+
+# TODO move the files on the correct directoy
+        my $host = $c->model('SvnBuildStat::Model::DB::Host')->find_or_create(name => $infofile->{hostname},
+                arch => $infofile->{arch});
+        my $arch = $c->model('SvnBuildStat::Model::DB::Arch')->find_or_create(name => $infofile->{arch});
+        my $changelogentry = $c->model('SvnBuildStat::Model::DB::Changelogentry')->search(id => $infofile->{id})->first;
+        my $build = $c->model('SvnBuildStat::Model::DB::Build')->find_or_create({
+                changelogentry_id => $changelogentry->id,
+                arch_id => $arch->id,
+                host_id => $host
+                });
+
+        $build->time('now');
+        $build->svndebrelease ($infofile->{release});
+        $build->buildisok ($infofile->{build} eq "ok"?"true":"false");
+        $build->duration
+            ($infofile->{'stamp_build-end'}-$infofile->{'stamp_build-start'});
+
+        $build->build_log ($log);
+        $build->update;
+
+    }
+    $c->response->body("ok");
+}
+
+
+
+1;




More information about the Collab-qa-commits mailing list