[Collab-qa-commits] r1170 - in buildstat/trunk/buildstat-server: lib/SvnBuildStat lib/SvnBuildStat/Controller lib/SvnBuildStat/Vcs script

goneri at alioth.debian.org goneri at alioth.debian.org
Thu Aug 28 12:49:11 UTC 2008


Author: goneri
Date: 2008-08-28 12:49:10 +0000 (Thu, 28 Aug 2008)
New Revision: 1170

Modified:
   buildstat/trunk/buildstat-server/lib/SvnBuildStat/Common.pm
   buildstat/trunk/buildstat-server/lib/SvnBuildStat/Controller/Controls.pm
   buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs.pm
   buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs/Git.pm
   buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs/Svn.pm
   buildstat/trunk/buildstat-server/script/svnbuildstat_update-db.pl
Log:
fix svnbuildstat_update-db.pl for git

Modified: buildstat/trunk/buildstat-server/lib/SvnBuildStat/Common.pm
===================================================================
--- buildstat/trunk/buildstat-server/lib/SvnBuildStat/Common.pm	2008-08-28 10:57:23 UTC (rev 1169)
+++ buildstat/trunk/buildstat-server/lib/SvnBuildStat/Common.pm	2008-08-28 12:49:10 UTC (rev 1170)
@@ -225,6 +225,7 @@
   my $localdir = shift;
 
   my $controlfile = $localdir.'/debian/control';
+  print "parseControl(): controlfile is ".$controlfile."\n";
   return unless -f $controlfile;
 
   my $ret = { maintainers => []};
@@ -360,7 +361,7 @@
 sub getBuildResultDirectory {
     my $build = shift;
 
-    my $buildDirectory = '/'.$$build->changelogentry_id->repositoryentry_id->repository_id->team_id->shortname.'/'.$$build->changelogentry_id->repositoryentry_id->sourcepackage_id->name.'/'.$$build->changelogentry_id->repositoryentry_id->changelogentry_id->id.'/build/'.$$build->id;
+    my $buildDirectory = '/'.$$build->changelogentry_id->repositoryentry_id->repository_id->id.'/'.$$build->changelogentry_id->repositoryentry_id->sourcepackage_id->name.'/'.$$build->changelogentry_id->repositoryentry_id->changelogentry_id->id.'/build/'.$$build->id;
 
     return $buildDirectory;
 }
@@ -373,15 +374,15 @@
 
     my $cfg = Config::IniFiles->new( -file => "/etc/buildstat-server/buildstat.ini" ) or die "can't load config file";
     #my $repositoryurl = $cfg->val('path', 'repositoryurl');
-    my $staticdir = $cfg->val('path', 'staticdir');
+    my $repositorydir = $cfg->val('path', 'repositorydir');
 
-    return $staticdir.'/files'.$resultdirectory;
+    return $repositorydir.'/'.$resultdirectory;
 }
 
 sub getQajobResultDirectory {
     my $qajob = shift;
 
-    my $qajobDirectory = '/'.$$qajob->changelogentry_id->repositoryentry_id->repository_id->team_id->shortname.'/'.$$qajob->changelogentry_id->repositoryentry_id->sourcepackage_id->name.'/'.$$qajob->changelogentry_id->repositoryentry_id->changelogentry_id->id.'/qajob/'.$$qajob->id;
+    my $qajobDirectory = '/'.$$qajob->changelogentry_id->repositoryentry_id->repository_id->id.'/'.$$qajob->changelogentry_id->repositoryentry_id->sourcepackage_id->name.'/'.$$qajob->changelogentry_id->repositoryentry_id->changelogentry_id->id.'/qajob/'.$$qajob->id;
 
     return $qajobDirectory;
 }
@@ -393,9 +394,9 @@
     return unless $qajobDirectory;
 
     my $cfg = Config::IniFiles->new( -file => "/etc/buildstat-server/buildstat.ini" ) or die "can't load config file";
-    my $staticdir = $cfg->val('path', 'staticdir');
+    my $repositorydir = $cfg->val('path', 'repositorydir');
 
-    return $staticdir.'/files'.$qajobDirectory;
+    return $repositorydir.'/'.$qajobDirectory;
 }
 
 
@@ -410,9 +411,9 @@
 
     my $cfg = Config::IniFiles->new( -file => "/etc/buildstat-server/buildstat.ini" ) or die "can't load config file";
     #my $repositoryurl = $cfg->val('path', 'repositoryurl');
-    my $staticdir = $cfg->val('path', 'staticdir');
+    my $repositorydir = $cfg->val('path', 'repositorydir');
 
-    my $lastBuilDdir = $staticdir.'/files/'.$$build->changelogentry_id->repositoryentry_id->repository_id->team_id->shortname.'/'.$$build->changelogentry_id->repositoryentry_id->sourcepackage_id->name.'/'.$$build->changelogentry_id->repositoryentry_id->changelogentry_id->id.'/build/lastbuild';
+    my $lastBuilDdir = $repositorydir.'/'.$$build->changelogentry_id->repositoryentry_id->repository_id->id.'/'.$$build->changelogentry_id->repositoryentry_id->sourcepackage_id->name.'/'.$$build->changelogentry_id->repositoryentry_id->changelogentry_id->id.'/build/lastbuild';
     recurseMkdir($lastBuilDdir);
 
     my $lastsymlink = $lastBuilDdir."/last";

Modified: buildstat/trunk/buildstat-server/lib/SvnBuildStat/Controller/Controls.pm
===================================================================
--- buildstat/trunk/buildstat-server/lib/SvnBuildStat/Controller/Controls.pm	2008-08-28 10:57:23 UTC (rev 1169)
+++ buildstat/trunk/buildstat-server/lib/SvnBuildStat/Controller/Controls.pm	2008-08-28 12:49:10 UTC (rev 1170)
@@ -20,7 +20,8 @@
 
 
     my @uploadedFiles;
-    my $uploaddir = $c->config->{path}->{uploaddir};
+    #my $uploaddir = $c->config->{path}->{uploaddir};
+    my $uploaddir = "/var/lib/buildstat-server/uploads";
     die unless $c->request->body_parameters->{content};
 
     my $params = {};
@@ -37,9 +38,9 @@
 
 
     my $dbh = $c->model('DB')->storage->dbh;
-    my $tobuild = $dbh->selectall_arrayref("
+    my $req = "
         SELECT
-          changelogentry.id AS changelogentry_id,
+          changelogentry.id AS changelogentry_id
         FROM
           changelogentry
         LEFT JOIN
@@ -66,7 +67,8 @@
           build.id IS NOT NULL,
           build.time,
           changelogentry.date
-         LIMIT 1");
+         LIMIT 1";
+    my $tobuild = $dbh->selectall_arrayref($req);
 
 
     my $changelogentry_id = $tobuild->[0][0];
@@ -79,8 +81,9 @@
 
 
     my $dscuri = $changelogentry->dscuri;
-    die unless $c->config->{path}->{weburi};
-    my $repositoryuri = $c->config->{path}->{weburi}."/static/files";
+    #die unless $c->config->{path}->{weburi};
+    #my $repositoryuri = $c->config->{path}->{weburi}."/static/files";
+    my $repositoryuri = "http://buildstat.debian.net/repository";
     $dscuri =~ s/\@REPOSITORY_URL@/$repositoryuri/;
 
     # TODO create the qajob entry here!
@@ -140,7 +143,7 @@
     die unless $changelogentry_id && $dscuri && $build_id;
     my $changelogentry = $c->model('SvnBuildStat::Model::DB::Changelogentry')->search({id => $changelogentry_id})->first;
     die unless $changelogentry;
-    die unless $c->config->{path}->{weburi};
+ #   die unless $c->config->{path}->{weburi}; TODO
 
 
     my $ret;
@@ -169,8 +172,9 @@
         $qajob->lastjobstart("NOW");
         $qajob->update;
 
-        my $changesfile = bsd_glob($c->config->{path}->{staticdir}.'/files/'.$changelogentry->repositoryentry_id->repository_id->team_id->shortname.'/'.$changelogentry->repositoryentry_id->sourcepackage_id->name.'/'.$changelogentry->repositoryentry_id->changelogentry_id->id.'/build/'.$build_id."/deb/*.changes");
-        my $changesuri = $c->config->{path}->{weburi}.'/static/files/'.$changelogentry->repositoryentry_id->repository_id->team_id->shortname.'/'.$changelogentry->repositoryentry_id->sourcepackage_id->name.'/'.$changelogentry->repositoryentry_id->changelogentry_id->id.'/build/'.$build_id."/deb/".basename($changesfile);
+        #my $changesfile = bsd_glob($c->config->{path}->{staticdir}.'/files/'.$changelogentry->repositoryentry_id->repository_id->team_id->shortname.'/'.$changelogentry->repositoryentry_id->sourcepackage_id->name.'/'.$changelogentry->repositoryentry_id->changelogentry_id->id.'/build/'.$build_id."/deb/*.changes");
+        my $changesfile = bsd_glob('/var/lib/buildstat-server/repository'.$changelogentry->repositoryentry_id->repository_id->team_id->shortname.'/'.$changelogentry->repositoryentry_id->sourcepackage_id->name.'/'.$changelogentry->repositoryentry_id->changelogentry_id->id.'/build/'.$build_id."/deb/*.changes");
+        my $changesuri = "http://buildstat.debian.net/repository/".$changelogentry->repositoryentry_id->repository_id->team_id->shortname.'/'.$changelogentry->repositoryentry_id->sourcepackage_id->name.'/'.$changelogentry->repositoryentry_id->changelogentry_id->id.'/build/'.$build_id."/deb/".basename($changesfile);
 
         $ret .= "qajob_id=".$qajob->id."\nchangesuri=".$changesuri."\n";
 
@@ -178,7 +182,7 @@
     die unless $qajob;
 
 
-    my $repositoryuri = $c->config->{path}->{weburi}."/static/files";
+    my $repositoryuri = "http://buildstat.debian.net/repository";
     $dscuri =~ s/\@REPOSITORY_URL@/$repositoryuri/;
     $ret .= "cookie=$cookie\n";
 
@@ -203,7 +207,8 @@
 
     die if $host->isblacklisted; 
 
-    my $uploaddir = $c->config->{path}->{uploaddir}."/".$host->ip;
+    #my $uploaddir = $c->config->{path}->{uploaddir}."/".$host->ip;
+    my $uploaddir = "/var/lib/buildstat-server/uploads/".$host->ip;
     SvnBuildStat::Common::recurseMkdir($uploaddir);
     my $upload = $c->request->upload('file');
     if (!$upload || !$upload->filename) {

Modified: buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs/Git.pm
===================================================================
--- buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs/Git.pm	2008-08-28 10:57:23 UTC (rev 1169)
+++ buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs/Git.pm	2008-08-28 12:49:10 UTC (rev 1170)
@@ -4,19 +4,24 @@
 use warnings;
 
 use File::Temp;
+use File::Basename;
 
-# TODO 
-# create a function to generate repodirname
-
 sub new {
 
-    my (undef, $uri, $localdir) = @_;
+    my (undef, $uri, $localdir, $subdir) = @_;
 
     my $self;
 
     $self->{uri} = $uri;
     $self->{localdir} = $localdir;
+    $self->{subdir} = $subdir;
+    if ($uri && !$subdir) {
+	    $self->{subdir} = basename($uri);
+    }
+    print "-> = ".$self->{localdir}.'/'.$self->{subdir}."\n";
+    $self->{finaldir} = $self->{localdir}.'/'.$self->{subdir};
 
+
 #    if ($uri =~ /ssh:\/\/([\w\.-]+)(\/.+)$/) {
 #        # For the moment, I only support Alioth
 #        $self->{reporoot} = $2;
@@ -33,29 +38,23 @@
 sub refresh {
   my ($self) = @_;
 
-  return unless $self->{localdir};
+  return unless $self->{finaldir};
   return unless $self->{uri};
   if ((!-d $self->{localdir}) && !mkdir($self->{localdir}) ) {
     return;
   }
-  my $repodirname;
-  if ($self->{uri} =~ /([-\w_+~]+)\.git$/) {
-    $repodirname = $1;
-  }
-  return unless $repodirname;
 
   my $cmd;
 
-  if (-d $self->{localdir}.'/'.$repodirname) {
-    $cmd = "cd ".$self->{localdir}.'/'.$repodirname."; git pull";
+  if (-d $self->{finaldir}) {
+    $cmd = "cd ".$self->{finaldir}." && git pull";
   } else {
-    $cmd = "cd ".$self->{localdir}."; git clone ".$self->{uri};
+    $cmd = "git-clone ".$self->{uri}." ".$self->{finaldir};
   }
+  print "->".$cmd."\n";
   `$cmd`;
-  $self->currentRev();
+  return $self->currentRev();
 
-  return;
-
 }
 
 
@@ -64,16 +63,14 @@
 
     my ($self,$nbr) = @_;
 
-    my $repodirname;
-    if (!$self->{uri} =~ /\/(\W+)\.git$/) {
-      return;
-    }
-    $repodirname = $1;
     $nbr = 5 unless $nbr =~ /^\d+$/;
 
     my $cmd;
-    if (-d $self->{localdir}.'/'.$repodirname) {
-      $cmd = "cd ".$self->{localdir}.'/'.$repodirname."; git log -n".$nbr;
+    print "->".$self->{finaldir}."\n";
+    if (-d $self->{finaldir}) {
+      $cmd = "cd ".$self->{finaldir}." && git log -n".$nbr;
+    } else {
+      error ($self->{finaldir}.' should exist!');
     }
 
     my $rev;
@@ -113,7 +110,7 @@
       $repodirname = $1;
     }
 
-    my $cmd = "cp -rf ".$self->{localdir}.'/'.$repodirname."/* ".$dir;
+    my $cmd = "cp -rf ".$self->{finaldir}."/* ".$dir;
     `rm -rf $dir/.git`; # remove the git directory from the exported directory
 
 }
@@ -121,15 +118,9 @@
 sub currentRev {
   my ($self) = @_;
 
-  my $repodirname;
-  if ($self->{uri} =~ /([-\w_+~]+)\.git$/) {
-    $repodirname = $1;
-  }
-  return unless $repodirname;
-
-  my $cmd = "cd ".$self->{localdir}.'/'.$repodirname."; git log -n 1 --pretty=oneline";
+  my $cmd = "cd ".$self->{finaldir}." && git log -n 1 --pretty=oneline";
   foreach (`$cmd`) {
-    return $1 if /^(\w+) /;
+    return $1 if /^(^\w+) /;
   }
 }
 

Modified: buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs/Svn.pm
===================================================================
--- buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs/Svn.pm	2008-08-28 10:57:23 UTC (rev 1169)
+++ buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs/Svn.pm	2008-08-28 12:49:10 UTC (rev 1170)
@@ -7,12 +7,16 @@
 
 sub new {
 
-    my (undef, $uri, $localdir) = @_;
+    my (undef, $uri, $localdir, $subdir) = @_;
 
     my $self;
 
     $self->{uri} = $uri;
     $self->{localdir} = $localdir;
+    if ($subdir) {
+    	$self->{subdir} = $subdir;
+	$self->{finaldir} = $localdir.'/'.$subdir;
+    }
 
 
     bless $self;
@@ -42,13 +46,13 @@
 
     my ($self,$nbr) = @_;
 
-    return unless $self->{localdir};
-    return unless -d $self->{localdir};
+    return unless $self->{finaldir};
+    return unless -d $self->{finaldir};
     $nbr = 5 unless $nbr =~ /^\d+$/;
 
     my @changes;
 
-    my $cmd = "cd ".$self->{localdir}."&& LC_ALL=C svn log --limit $nbr";
+    my $cmd = "cd ".$self->{finaldir}."&& LC_ALL=C svn log --limit $nbr";
 
     my $begin;
     my $rev;
@@ -87,7 +91,7 @@
     my ($self, $dir) = @_;
 
     return unless $dir;
-    my $cmd = "cp -r $self->{localdir}/* $dir";
+    my $cmd = "cp -r $self->{finaldir}/* $dir";
     print " ->".$cmd."\n";
     `$cmd`;
     $cmd = "find $dir -type d -name '.svn' -exec rm -Rf {} \\; 2>&1";
@@ -98,7 +102,13 @@
 sub currentRev {
   my ($self) = @_;
 
-  my $cmd = "cd ".$self->{localdir}."; LC_ALL=C svn info";
+  my $cmd;
+
+  if ($self->{finaldir}) {
+	  $cmd = "cd ".$self->{finaldir}."; LC_ALL=C svn info";
+  } else {
+	  $cmd = "cd ".$self->{localdir}."; LC_ALL=C svn info";
+  }
   foreach (`$cmd`) {
     return $1 if /Revision: (\d+)/;
   }

Modified: buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs.pm
===================================================================
--- buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs.pm	2008-08-28 10:57:23 UTC (rev 1169)
+++ buildstat/trunk/buildstat-server/lib/SvnBuildStat/Vcs.pm	2008-08-28 12:49:10 UTC (rev 1170)
@@ -12,9 +12,9 @@
 
     # TODO rewrite this in a more dynamic way
     if ($params->{vcstype} eq "git") {
-       return new SvnBuildStat::Vcs::Git($params->{uri}, $params->{localdir});
+       return new SvnBuildStat::Vcs::Git($params->{uri}, $params->{localdir}, $params->{subdir});
     } elsif ($params->{vcstype} eq "svn") {
-       return new SvnBuildStat::Vcs::Svn($params->{uri}, $params->{localdir});
+       return new SvnBuildStat::Vcs::Svn($params->{uri}, $params->{localdir}, $params->{subdir});
     } else {
        debug ("unknow vcs type: ".$params->{vcstype});
     }

Modified: buildstat/trunk/buildstat-server/script/svnbuildstat_update-db.pl
===================================================================
--- buildstat/trunk/buildstat-server/script/svnbuildstat_update-db.pl	2008-08-28 10:57:23 UTC (rev 1169)
+++ buildstat/trunk/buildstat-server/script/svnbuildstat_update-db.pl	2008-08-28 12:49:10 UTC (rev 1170)
@@ -35,7 +35,7 @@
   });
 
   my $newrev = $vcs->refresh();
-  debug ("new VCS revision: $newrev\n");
+  debug ("new VCS revision: $newrev\n") if $newrev;
 
   if (!$newrev) {
     info ("Failed to refresh repository");
@@ -55,10 +55,10 @@
     $lastcheck = DateTime::Format::Pg->parse_datetime($$repository->lastcheck);
   }
 
-  my $vcs = new SvnBuildStat::Vcs({
-    vcstype => $$repository->vcs_id->name,
-    uri => $$repository->uri
-  });
+#  my $vcs = new SvnBuildStat::Vcs({
+#    vcstype => $$repository->vcs_id->name,
+#    uri => $$repository->uri
+#  });
 
   my $ret;
   foreach (`find $localcache -type f -name 'control'`) {
@@ -107,11 +107,11 @@
   my $repositoryentry = shift;
 
   my $vcscache = $cfg->val('path', 'vcscache');
-  my $localdir = $vcscache.'/'.$$repositoryentry->repository_id->id.$$repositoryentry->subdir;
-
-  my $control = parseControl($localdir);
-  my $changelog = parseChangelog($localdir);
-  my $todo = getTODO($localdir);
+  my $finaldir = $vcscache.'/'.$$repositoryentry->repository_id->id.$$repositoryentry->subdir;
+print "-> finaldir: ".$finaldir."\n";
+  my $control = parseControl($finaldir);
+  my $changelog = parseChangelog($finaldir);
+  my $todo = getTODO($finaldir);
   if (!$control || !$changelog) {
     debug ("repositoryentry ".$$repositoryentry->id.": failed to parse the debian files");
     return;
@@ -159,10 +159,13 @@
   my $repositoryentry = shift;
 
   my $vcscache = $cfg->val('path', 'vcscache');
-  my $localdir = $vcscache.'/'.$$repositoryentry->repository_id->id.$$repositoryentry->subdir;
+  my $localdir = $vcscache.'/'.$$repositoryentry->repository_id->id;
+  my $subdir = $$repositoryentry->subdir;
+  my $finaldir = $localdir.'/'.$subdir;
+  print "finaldir: ".$finaldir."\n";
 
-  my $control = parseControl($localdir);
-  my $changelog = parseChangelog($localdir);
+  my $control = parseControl($finaldir);
+  my $changelog = parseChangelog($finaldir);
   if (!$control || !$changelog) {
     debug ("repositoryentry ".$$repositoryentry->id.": failed to parse the debian files");
     return;
@@ -171,6 +174,7 @@
   my $vcs = new SvnBuildStat::Vcs({
     vcstype => $$repositoryentry->repository_id->vcs_id->name,
     localdir => $localdir,
+    subdir => $subdir,
   });
 
   my $vcschanges = $vcs->getLastVcsChanges(5);
@@ -242,8 +246,9 @@
 while (my $repository = $repository_rs->next) {
   my $begin = DateTime->now;
 
+    debug ("scanning ".$repository->name);
   # Pool repository are not scanned by this script
-  if ($repository->vcs_id->name eq "pool") {
+  if ($repository->vcs_id->name eq "apt") {
     next
   }
   my $currentrev = refreshRepository(\$repository);




More information about the Collab-qa-commits mailing list