[Collab-qa-commits] r580 - in svnbuildstat/trunk/lib/SvnBuildStat: . Controller
goneri-guest at alioth.debian.org
goneri-guest at alioth.debian.org
Wed Dec 12 20:28:39 UTC 2007
Author: goneri-guest
Date: 2007-12-12 20:28:39 +0000 (Wed, 12 Dec 2007)
New Revision: 580
Modified:
svnbuildstat/trunk/lib/SvnBuildStat/Common.pm
svnbuildstat/trunk/lib/SvnBuildStat/Controller/Builds.pm
svnbuildstat/trunk/lib/SvnBuildStat/Controller/Packages.pm
Log:
to much changes to do a list
Modified: svnbuildstat/trunk/lib/SvnBuildStat/Common.pm
===================================================================
--- svnbuildstat/trunk/lib/SvnBuildStat/Common.pm 2007-12-12 17:13:54 UTC (rev 579)
+++ svnbuildstat/trunk/lib/SvnBuildStat/Common.pm 2007-12-12 20:28:39 UTC (rev 580)
@@ -3,10 +3,12 @@
use strict;
use warnings;
+use LWP::UserAgent;
+
require Exporter;
our @ISA = "Exporter";
-our @EXPORT = qw(mkTarballFromPackage testUrl mkRootdirectoryFromRepositoryentry getDataFromDebianFtp parseControl parseChangelog);
+our @EXPORT = qw(mkTarballFromPackage checkRepositoryentryWatchfile testUrl mkRootdirectoryFromRepositoryentry getDataFromDebianFtp parseControl parseChangelog createTarballUrlFromTarballlayout);
sub mkTarballFromRepositoryentry {
my $repositoryentry = shift;
@@ -19,6 +21,52 @@
$$repositoryentry->sourcepackage_id->name.'_'.$majorrelease.".orig.tar.gz";
}
+# The name of this function sucks
+sub checkRepositoryentryWatchfile {
+ my ($repositoryentry) = shift;
+ my $cmd;
+
+ # TODO, no ini file access in a shared function
+ my $cfg = Config::IniFiles->new( -file => "../svnbuildstat.ini" ) or die "Can't load config file";
+ my $vcscache = $cfg->val('path', 'vcscache');
+ my $watchfile = $vcscache.'/'.$$repositoryentry->repository_id->id.$$repositoryentry->subdir.'/debian/watch';
+ return unless -f $watchfile;
+
+ my $majorrelease = $$repositoryentry->svndebrelease;
+ return unless $majorrelease;
+
+ $majorrelease =~ s/^\d+://;
+ $majorrelease =~ s/-[0-9A-Za-z\.~]*$//;
+ $majorrelease =~ s/dfsg.*//;
+ $majorrelease =~ s/\d+://;
+ $cmd = "uscan --package ".$$repositoryentry->sourcepackage_id->name." --dehs --upstream-version ".$majorrelease." --watchfile ".$watchfile;
+ my @uscan = `$cmd`;
+ return unless @uscan > 2; # empty output
+
+ my $tarballuri;
+ my $isuptodate = 'f';
+ my $iswatchfilebroken = 'f';
+ my $upstreamrelease;
+ foreach (@uscan) {
+ $tarballuri = $1 if (/^<upstream-url>(.+tar\.gz)<\/upstream-url>$/i);
+ $isuptodate = 't' if (/^<status>up to date<\/status>$/);
+ $upstreamrelease = $1 if (/^<upstream-version>(.+)<\/upstream-version>$/);
+ $iswatchfilebroken = 't' if (/^<errors>/);
+ }
+ $iswatchfilebroken = 't' unless $upstreamrelease;
+
+ $$repositoryentry->upstreamrelease($upstreamrelease);
+ $$repositoryentry->isuptodate($isuptodate);
+ $$repositoryentry->iswatchfilebroken($iswatchfilebroken);
+ if ($isuptodate eq 't' && !$$repositoryentry->isindebian && $tarballuri =~ /(\.tar\.gz|tgz)$/i) {
+ $$repositoryentry->tarballuri($tarballuri);
+ }
+ $$repositoryentry->lastwatchcheck('now');
+
+ $$repositoryentry->update();
+}
+
+
# Return true if the file pointed by the URL exists
sub testUrl {
my $url = shift;
@@ -43,6 +91,21 @@
$$repositoryentry->sourcepackage_id->name.'-'.$majorrelease;
}
+
+
+sub createTarballUrlFromTarballlayout {
+ my ($repositoryentry) = @_;
+
+ return unless $$repositoryentry->repository_id->tarballlayout;
+ my $packagename = $$repositoryentry->sourcepackage_id->name;
+ my $tarball = SvnBuildStat::Common::mkTarballFromPackage($repositoryentry);
+ my $tarballuri = $$repositoryentry->repository_id->tarballlayout;
+ $tarballuri =~ s/\@TARBALL@/$tarball/;
+ $tarballuri =~ s/\@PACKAGE@/$packagename/;
+
+ return $tarballuri;
+}
+
sub getDataFromDebianFtp {
my $repositoryentry = shift;
return unless $$repositoryentry->svndebrelease;
@@ -51,54 +114,50 @@
my $ret = {};
$ret->{isindebian} = 'f';
- $ret->{isnative} = 'f';
$ret->{tarballuri} = '';
my $ua = LWP::UserAgent->new;
$ua->agent("SvnBuildStat/0.1 ");
- if ($$repositoryentry->svndebrelease !~ /-[\d+\.]+$/) {
- $ret->{isnative} = 't';
- } else {
my $debmirror = 'http://ftp.debian.org/debian';
my $debdiff .= $$repositoryentry->sourcepackage_id->name."_".$svndebrelease.".diff.gz";
my $tarball = SvnBuildStat::Common::mkTarballFromRepositoryentry($repositoryentry);
if ($tarball) {
foreach my $section (qw/main contrib non-free/) {
- my $tmp = "$1/".$$repositoryentry->sourcepackage_id->name if $$repositoryentry->sourcepackage_id->name =~ /^(lib.|.)/;
- my $debdiffuri = $debmirror.'/pool/'.$section.'/'.$tmp.'/'.$debdiff;
- my $tmp_tarballuri = $debmirror.'/pool/'.$section.'/'.$tmp.'/'.$tarball;
- if (testUrl($debdiffuri)) {
- $ret->{isindebian} = 't';
- }
- if (testUrl($tmp_tarballuri)) {
- $tmp_tarballuri =~ s/^$debmirror/\@DEBMIRROR@/;
- $ret->{tarballuri} = $tmp_tarballuri;
- }
+ my $tmp = "$1/".$$repositoryentry->sourcepackage_id->name if $$repositoryentry->sourcepackage_id->name =~ /^(lib.|.)/;
+ my $debdiffuri = $debmirror.'/pool/'.$section.'/'.$tmp.'/'.$debdiff;
+ my $tmp_tarballuri = $debmirror.'/pool/'.$section.'/'.$tmp.'/'.$tarball;
+ if (testUrl($debdiffuri)) {
+ $ret->{isindebian} = 't';
+ }
+ if (testUrl($tmp_tarballuri)) {
+ $tmp_tarballuri =~ s/^$debmirror/\@DEBMIRROR@/;
+ $ret->{tarballuri} = $tmp_tarballuri;
+ }
}
- }
}
$ret;
}
sub parseControl {
- my $control = shift;
+ my $controlfile = shift;
my $ret = { maintainers => []};
-
- foreach (@$control) {
+
+ open CONTROL, "<$controlfile" or return;
+ foreach (<CONTROL>) {
$ret->{packagesrc} = $1 if /^Source:\ *(.*)/;
if (/^(Maintainer|Uploaders):\ *(.*)/) {
my $tmp = $2;
foreach (split /,/, $tmp) {
- if (/(.+)<(.+)>/) {
- my $name = $1;
- my $email = $2;
- $name =~ s/^\ *//;
- $name =~ s/\ $//;
- push @{$ret->{maintainers}}, {email=>$email, name => $name};
- }
+ if (/(.+)<(.+)>/) {
+ my $name = $1;
+ my $email = $2;
+ $name =~ s/^\ *//;
+ $name =~ s/\ $//;
+ push @{$ret->{maintainers}}, {email=>$email, name => $name};
+ }
}
} elsif (/^Architecture: (.*)/) {
@@ -109,6 +168,7 @@
$ret->{amd64} = 't' if $arch =~ /(any|all|amd64)/;
}
}
+ close CONTROL;
return unless (exists ($ret->{packagesrc}) && $ret->{packagesrc});
@@ -116,22 +176,24 @@
}
sub parseChangelog {
- my $changelog = shift;
+ my $changelogfile = shift;
my $ret;
- return unless (@$changelog);
- if ($changelog->[0] =~ /^.*\ \((.*)\)/) {
+ open CHANGELOG, "<$changelogfile" or return;
+ my @changelog = <CHANGELOG>;
+ return unless (@changelog);
+ if ($changelog[0] =~ /^.*\ \((.*)\)/) {
$ret->{realsvndebrelease} = $1;
}
- foreach (@$changelog) {
+ foreach (@changelog) {
if (/^\S/ && $ret->{currentchangelogentry}) {
# I ignore svn-bp empty template entry
if ($ret->{currentchangelogentry} =~ /^.*\n\s\s\*\sNOT RELEASED YET\n\n\s--.*/m) {
- $ret->{currentchangelogentry} = '';
+ $ret->{currentchangelogentry} = '';
} else {
- last;
+ last;
}
}
$ret->{currentchangelogentry} .= $_;
Modified: svnbuildstat/trunk/lib/SvnBuildStat/Controller/Builds.pm
===================================================================
--- svnbuildstat/trunk/lib/SvnBuildStat/Controller/Builds.pm 2007-12-12 17:13:54 UTC (rev 579)
+++ svnbuildstat/trunk/lib/SvnBuildStat/Controller/Builds.pm 2007-12-12 20:28:39 UTC (rev 580)
@@ -4,6 +4,8 @@
use warnings;
use base 'Catalyst::Controller';
+use File::Basename;
+
=head1 NAME
SvnBuildStat::Controller::Packages - Catalyst Controller
@@ -20,28 +22,114 @@
=head2 index
=cut
+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 =~ /^(.*?)_/;
+ $ret->{vcsrev} = $2 if $basename =~ /~(git|svn|cvs|hg)(.*?)_/;
+ #^^^^^^^^^^^^^^^ TODO
+
+ return unless $ret->{packagesrc} or $ret->{id};
+
+ return $ret;
+}
+
+
sub index : Private {
my ( $self, $c ) = @_;
$c->response->redirect($c->uri_for('/'));
}
+# TODO purge the files
sub upload : Local {
my ( $self, $c, $param ) = @_;
- my $txt = "ok";
+ 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 $uploaddir = $c->config->{path}->{uploaddir};
- foreach my $upload ( $c->request->upload('files') ) {
- if (!$upload->copy_to($duploaddir.'/'.$upload->filename)) {
- $txt = "ko";
- last;
+
+ my $infofile;
+ if ($target =~ /\.info$/) {
+ $infofile = loadInfofile($target);
+ } else {
+ $c->response->body("ok".$!);
+ }
+
+# just in case a file is missing
+ foreach (split(' ', $uploaddir.'/'.$infofile->{binarypackages})) {
+ next unless -f $uploaddir.'/'.$_;
+ $c->response->body("ko can't find all the binary files");
+ }
+ if (!-f $uploaddir.'/'.$infofile->{logfile}) {
+ $c->response->body("ko can't find all the binary files");
+ }
+
+ 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 it means that seek moved me
+ $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;
}
+ 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_rs = $c->model('SvnBuildStat::Model::DB::Changelogentry')->search(repositoryentry_id => $infofile->{id}, rev => $infofile->{vcsrev});
+ if (!$changelogentry_rs->count) {
+ $c->response->body("can't find such revision in the DB");
+ }
+ my $changelogentry = $changelogentry_rs->first;
+ my $build = $c->model('SvnBuildStat::Model::DB::Build')->find_or_create({
+ changelogentry_id => $changelogentry->id,
+ repositoryentry_id => $infofile->{id},
+ arch_id => $arch->id,
+ });
- $c->response->body($txt);
+ $build->time('now');
+ $build->set_from_related('host_id', $host);
+ $build->svndebrelease ($infofile->{release});
+ $build->buildisok ($infofile->{build} eq "ok"?"true":"false");
+ $build->duration
+ ($infofile->{'stamp_build-end'}-$infofile->{'stamp_build-start'});
+ $build->update;
+ $build->build_log ($log);
+
+ $c->response->body("ok");
+
}
Modified: svnbuildstat/trunk/lib/SvnBuildStat/Controller/Packages.pm
===================================================================
--- svnbuildstat/trunk/lib/SvnBuildStat/Controller/Packages.pm 2007-12-12 17:13:54 UTC (rev 579)
+++ svnbuildstat/trunk/lib/SvnBuildStat/Controller/Packages.pm 2007-12-12 20:28:39 UTC (rev 580)
@@ -189,18 +189,18 @@
# WHERE package.blacklisted = false AND package.issrcinmypool = true AND (package.lastbuildstart IS NULL OR package.lastbuildstart < (now() - '03:00:00'::interval))
# ORDER BY build.id IS NOT NULL, build."time";
- my $package_id = $c->model('SvnBuildStat::Model::DB::Viewtobuild')->search({$arch => 'true' })->first->id;
- my $package = $c->model('SvnBuildStat::Model::DB::Package')->search ({id => $package_id})->first;
+ my $repositoryentry_id = $c->model('SvnBuildStat::Model::DB::Viewtobuild')->search({$arch => 'true' })->first->id;
+ my $repositoryentry = $c->model('SvnBuildStat::Model::DB::Repositoryentry')->search ({id => $repositoryentry_id})->first;
- $package->lastbuildstart('now');
- $package->update();
+ $repositoryentry->lastbuildstart('now');
+ $repositoryentry->update();
- my $dscuri = $package->dscuri;
+ my $dscuri = $repositoryentry->dscuri;
$dscuri =~ s/\@REPOSITORY_URL@/http:\/\/localhost\/debian/;
- $c->response->body("dsc=".$dscuri."\npackage_id=".$package->id);
+ $c->response->body("dsc=".$dscuri."\nid=".$repositoryentry->id);
}
More information about the Collab-qa-commits
mailing list