[Collab-qa-commits] r512 - svnbuildstat/trunk/script

goneri-guest at alioth.debian.org goneri-guest at alioth.debian.org
Sun Nov 18 23:13:57 UTC 2007


Author: goneri-guest
Date: 2007-11-18 23:13:56 +0000 (Sun, 18 Nov 2007)
New Revision: 512

Added:
   svnbuildstat/trunk/script/svnbuildstat_update-db.pl
Removed:
   svnbuildstat/trunk/script/svnbuildstat_update-db-git.pl
   svnbuildstat/trunk/script/svnbuildstat_update-db-svn.pl
Log:
merge script/svnbuildstat_update-db-git.pl and
script/svnbuildstat_update-db-svn.pl into one uniq script.


Deleted: svnbuildstat/trunk/script/svnbuildstat_update-db-git.pl
===================================================================
--- svnbuildstat/trunk/script/svnbuildstat_update-db-git.pl	2007-11-18 23:13:04 UTC (rev 511)
+++ svnbuildstat/trunk/script/svnbuildstat_update-db-git.pl	2007-11-18 23:13:56 UTC (rev 512)
@@ -1,98 +0,0 @@
-#!/usr/bin/perl -w
-use File::Temp qw/ tempfile /;
-
-use strict;
-
-use LWP::UserAgent;
-use Data::Dumper;
-use File::Basename;
-use Time::Local 'timelocal_nocheck';
-
-use lib '/home/sites/svnbuildstat.debian.net/svnbuildstat/lib';
-use SvnBuildStat::Schema;
-use SvnBuildStat::Config;
-use SvnBuildStat::Common;
-use Logger::Syslog;
-#use SvnBuildStat::Common::Svn;
-use SvnBuildStat::Vcs::Git;
-
-my $config;
-my $schema;
-
-sub createTarballUrlFromTarballlayout {
-  my ($repository, $package) = @_;
-
-  return unless $$repository->tarballlayout;
-  my $packagename =  $$package->name;
-  my $tarball = SvnBuildStat::Common::mkTarballFromPackage($package);
-  my $tarballuri = $$repository->tarballlayout;
-  $tarballuri =~ s/\@TARBALL@/$tarball/;
-  $tarballuri =~ s/\@PACKAGE@/$packagename/;
-#  print  "\n--->".$tarballuri."\n";
-
-  return $tarballuri;
-}
-
-sub importRepository {
-  my $repository = shift;
-
-
-  my $tarballonrepository;
-  my $reporoot;
-  print "Repository: ".$$repository->name."\n";
-  my $git = new SvnBuildStat::Vcs::Git($$repository->uri);
-
-  my $rev = $git->getCurrentRev();
-
-  if ($$repository->vcsrev eq $rev && $$repository->lastcheck) { 
-    debug ("no need to refresh this repository");
-    return;
-  }
-
-#  GIT_DIR=/srv/git.debian.org/git/kernel/klibc-old.git/ git show HEAD:debian/changelog
-  my $changelog = SvnBuildStat::Common::parseChangelog($git->getChangelog());
-  
-use Data::Dumper;
-print Dumper($changelog);
-#  $$repository->vcsrev($rev);
-#  $$repository->lastcheck('now');
-#  $$repository->update();
-
-  print "end import Repo\n";
-}
-
-###################################################
-###################################################
-###################################################
-###################################################
-###################################################
-############### MAIN ##############################
-###################################################
-###################################################
-
-info ("starting");
-
-$config = new SvnBuildStat::Config();
-$schema = SvnBuildStat::Schema->connect(
-  $config->db_dsn,
-  $config->db_user,
-  $config->db_password,
-  {AutoCommit => 1, debug => 1}
-);
-
-
-# Import packages
-my $repository_rs = $schema->resultset('Repository')->search({enabled => 'true'});
-while (my $repository = $repository_rs->next) {
-  next unless $repository->vcs_id && $repository->vcs_id->name eq "git";
-  importRepository(\$repository) or warn "importRepository failed for ".$repository->name."\n";
-}
-
-# Purge the removed packages
-# This semems to be fucked?
-#my $interval = "< repository_id.lastcheck - interval '1 day'";
-#my $package_rs = $schema->resultset('Package')->search({'me.lastcheck' => \$interval} , {join => => 'repository_id'});
-#$package_rs->delete_all;
-
-info ("stopping");
-

Deleted: svnbuildstat/trunk/script/svnbuildstat_update-db-svn.pl
===================================================================
--- svnbuildstat/trunk/script/svnbuildstat_update-db-svn.pl	2007-11-18 23:13:04 UTC (rev 511)
+++ svnbuildstat/trunk/script/svnbuildstat_update-db-svn.pl	2007-11-18 23:13:56 UTC (rev 512)
@@ -1,331 +0,0 @@
-#!/usr/bin/perl -w
-use File::Temp qw/ tempfile /;
-
-use strict;
-
-use LWP::UserAgent;
-use Data::Dumper;
-use File::Basename;
-use Time::Local 'timelocal_nocheck';
-
-use lib '/home/sites/svnbuildstat.debian.net/svnbuildstat/lib';
-use SvnBuildStat::Schema;
-use SvnBuildStat::Config;
-use Logger::Syslog;
-use SvnBuildStat::Common;
-use SvnBuildStat::Vcs;
-
-my $config;
-my $schema;
-
-
-sub createTarballUrlFromTarballlayout {
-  my ($repository, $package) = @_;
-
-  return unless $$repository->tarballlayout;
-  my $packagename =  $$package->name;
-  my $tarball = SvnBuildStat::Common::mkTarballFromPackage($package);
-  my $tarballuri = $$repository->tarballlayout;
-  $tarballuri =~ s/\@TARBALL@/$tarball/;
-  $tarballuri =~ s/\@PACKAGE@/$packagename/;
-#  print  "\n--->".$tarballuri."\n";
-
-  return $tarballuri;
-}
-
-
-sub getUscanData {
-  my ($package, $watchfile) = shift;
-  my $cmd;
-
-  return unless $watchfile;
-  return unless $$package->svndebrelease;
-
-  my ($fh, $tmpfile) = tempfile(SUFFIX => '.uscan');
-  print $fh @$watchfile;
-  close ($fh);
-
-  my $majorrelease = $$package->svndebrelease;
-  $majorrelease =~ s/^\d+://;
-  $majorrelease =~ s/-[0-9A-Za-z\.~]*$//;
-  $majorrelease =~ s/dfsg.*//;
-  $majorrelease =~ s/\d+://;
-  $cmd = "uscan --package ".$$package->name." --dehs --upstream-version ".$majorrelease." --watchfile ".$tmpfile;
-#  print $cmd."\n";
-  my @uscan = `$cmd`;
-  unlink $tmpfile or warn;
-  return unless @uscan > 2; # empty output
-
-  my $tarballuri;
-  my $isuptodate = 'f';
-  my $iswatchfilebroken = 'f';
-  my $upstreamrelease;
-  foreach (@uscan) {
-#    print;
-    $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;
-  $tarballuri = '' unless $isuptodate eq 't';
-
-  return {tarballuri => $tarballuri, isuptodate => $isuptodate, upstreamrelease => $upstreamrelease, iswatchfilebroken => $iswatchfilebroken};
-}
-
-sub updateVcsChanges {
-  my ($package, $vcschanges) = @_;
-
-  my @added_entry_id;
-  foreach (@$vcschanges) {
-    # TODO Git users put there email address in there login. With it we can link the vcs user
-    # to the package maintainer
-    use Data::Dumper;
-    print Dumper($_);
-    my $userlogin = $schema->resultset('Userlogin')->find_or_create({name=>$_->{login}});
-    my $entry = $schema->resultset('Changelogentry')->create({
-	userlogin_id =>$userlogin->id,
-	package_id => $$package->id,
-	date => $_->{date},
-	rev => $_->{rev},
-      });
-    $entry->log($_->{text});
-    $entry->update;
-    push @added_entry_id, $entry->id;
-  }
-
-  # I remove the old
-  if (@added_entry_id) { 
-    $schema->resultset('Changelogentry')->search({
-	id => { '!=', \@added_entry_id },
-	package_id => $$package->id
-      })->delete;
-  }
-
-}
-
-sub importPkg {
-  my( $repository, $uri, $tarballonrepository) = @_;
-
-  my @maintainer;
-  my $packagesrc;
-  my $tarballuri;
-  my $todo;
-  my $currentpendingbug;
-# arch
-  my $i386 = 'f';
-  my $powerpc = 'f';
-  my $sparc = 'f';
-  my $amd64 = 'f';
-
-  my $vcs;
-
-  my $vcsname = $$repository->vcs_id->name;
-  $vcs = new SvnBuildStat::Vcs($vcsname, $uri);
-
-  my $rev = $vcs->getCurrentRev();
-
-
-  if (!$rev) {
-    info ("Can't get current svn revision");
-    return;
-  }
-
-  my $control = SvnBuildStat::Common::parseControl($vcs->getControl());
-  if (!$control) {
-    info ("Failed to parse $uri/debian/control");
-    return;
-  }
-
-  my $package = $schema->resultset('Package')->find_or_create({name => $control->{packagesrc}});
-
-  if (defined($rev) && defined ($package->vcsrev) && $rev eq $package->vcsrev) {
-    debug ("no need to refresh");
-    return;
-  }
-  print "GO ".$package->name."\n";
-
-  $package->issrcinmypool (0); # deprecated, replaced by dscuri
-  $package->dscuri(undef);
-
-  my $changelog = SvnBuildStat::Common::parseChangelog($vcs->getChangelog);
-  $package->realsvndebrelease($changelog->{realsvndebrelease});
-  $package->svndebrelease ($changelog->{svndebrelease});
-  $package->currentchangelogentry($changelog->{currentchangelogentry});
-  $package->currentpendingbug($changelog->{currentpendingbug});
-
-  my @todo = $vcs->getTODO();
-  if (@todo) {
-    $todo .= $_ foreach @todo;
-  }
-  $package->update_from_related('repository_id',$$repository);
-
-  $package->vcsuri($uri);
-  $package->repository_id($$repository);
-
-  # Delete the current relation betwen the maintainers and the package
-  $schema->resultset('PackageMaintainer')->search({
-      package_id => $package->id
-    })->delete;
-
-  # And recreate them
-  foreach (@{$control->{maintainers}}) {
-    my $maintainer = $schema->resultset('Maintainer')->find_or_create({email=>$_->{email}});
-    $maintainer->name($_->{name});
-    $maintainer->update();
-
-    my $package_maintainer =
-    $package->find_or_create_related('package_maintainers', {
-	'maintainer_id' => $maintainer->id});
-  }
-
-  # I keep the changelog entry since the oldest build, si I need.. ...to
-  # find the oldest build
-  my $vcschangelog_rs = $schema->resultset('Changelogentry')->search({
-      package_id => $package->id,
-    }, {order_by => "rev DESC"});
-  my $last_rev = $vcschangelog_rs->first->rev if ($vcschangelog_rs->first);
-  updateVcsChanges(\$package, $vcs->getLastVcsChanges(5));
-
-
-  # Search for the tarball
-  my $tarball = SvnBuildStat::Common::mkTarballFromPackage(\$package);
-  my $uscandata = getUscanData(\$package, $vcs->getWatchfile);
-  my $dataFromDebianFtp = SvnBuildStat::Common::getDataFromDebianFtp(\$package);
-  use Data::Dumper;
-  print Dumper($dataFromDebianFtp);
-  my $tarballurlfromtarballlayout = createTarballUrlFromTarballlayout($repository,\$package);
-  $package->iswatchfilebroken($uscandata->{iswatchfilebroken});
-  # Is the tarball on a Debian mirror?
-  # TODO, isnative shouldn't be returned by dataFromDebianFtp
-  if ($dataFromDebianFtp->{isnative} eq 't') {
-    $package->isnative(1);
-    $package->tarballuri('');
-    $package->istarballpresent(0);
-  } else {
-    $package->isnative(0);
-    if ($dataFromDebianFtp->{tarballuri}) {
-      $package->tarballuri($dataFromDebianFtp->{tarballuri});
-      $package->istarballpresent(1);
-    }
-    elsif ($uscandata->{tarballuri}) {
-      $package->tarballuri($uscandata->{tarballuri});
-      $package->istarballpresent(1);
-    }
-    # Or on a HTTP/FTP space is a tarball layout exists
-    elsif (SvnBuildStat::Common::testUrl($tarballurlfromtarballlayout)) {
-      $package->tarballuri($tarballurlfromtarballlayout);
-      $package->istarballpresent(1);
-      # Or on the same repository
-    } elsif($tarballonrepository && exists ($tarballonrepository->{$tarball})) {
-      my $t = $tarballonrepository->{$tarball};
-      $t =~ s!svn://svn.debian.org/svn/(.*)!http://svn.debian.org/wsvn/$1?op=file&rev=0&sc=0!;
-    } else {
-      $package->tarballuri('');
-      $package->istarballpresent(0);
-    }
-  } 
-
-  # 
-  $package->isuptodate($uscandata->{isuptodate});
-  $package->upstreamrelease($uscandata->{upstreamrelease});
-  $package->isindebian($dataFromDebianFtp->{isindebian});
-
-  $package->i386($control->{i386});
-  $package->powerpc($control->{powerpc});
-  $package->sparc($control->{sparc});
-  $package->amd64($control->{amd64});
-  $package->todo($todo);
-  $package->lastcheck('now');
-  $package->vcsrev($rev); # at the end since it marks in the new status of the package ins the DB
-  $package->update();
-}
-
-
-sub importRepository {
-  my $repository = shift;
-
-  my $vcs = new SvnBuildStat::Vcs::Svn($$repository->uri);
-  print "Repository: ".$$repository->name."\n";
-  debug ("importing ".$$repository->name);
-  my $rev = $vcs->getCurrentRev();
-  if(! $rev) {
-    print "Failed to get the current revision of ".$$repository->name."\n";
-    return;
-  }
-
-  if ($$repository->vcsrev eq $rev) {
-    debug ("no need to refresh ".$$repository->name);
-    return;
-  }
-
-  my ($uri, $tarballonrepository) = $vcs->scan();
-
-  foreach (@$uri) {
-    # look for packages
-    importPkg($repository,$_,$tarballonrepository);
-  }
-
-  $$repository->vcsrev($rev);
-  $$repository->lastcheck('now');
-  $$repository->update();
-
-  debug ($$repository->name." imported");
-}
-###################################################
-###################################################
-###################################################
-###################################################
-###################################################
-############### MAIN ##############################
-###################################################
-###################################################
-
-info ("starting");
-
-$config = new SvnBuildStat::Config();
-$schema = SvnBuildStat::Schema->connect(
-  $config->db_dsn,
-  $config->db_user,
-  $config->db_password,
-  {AutoCommit => 1, debug => 1}
-);
-
-
-########
-
-# Import packages
-my $repository_rs = $schema->resultset('Repository')->search({enabled => 'true'});
-while (my $repository = $repository_rs->next) {
-  my $vcsname = $repository->vcs_id->name;
-  my $uri = $repository->uri;
-
-  # one repo per team
-  if ($vcsname =~ /^(svn)$/) {
-    print "import Repository". $repository->name."\n";
-    importRepository(\$repository);
-  } else { # or one repo per package
-    # TODO put this in importRepository()
-    my $vcs = new SvnBuildStat::Vcs($vcsname, $uri);
-    my $beginrev = $vcs->getCurrentRev();
-    next if $repository->vcsrev eq $beginrev;
-    print "import Repository as package ". $repository->name."\n";
-    importPkg (\$repository, $uri);
-    my $endrev = $vcs->getCurrentRev();
-    print "$beginrev eq $endrev\n";
-    if ($beginrev eq $endrev) {
-      $repository->vcsrev($endrev);
-      $repository->lastcheck('now');
-    }
-    $repository->update();
-  }
-}
-
-# Purge the removed packages
-# This semems to be fucked?
-#my $interval = "< repository_id.lastcheck - interval '1 day'";
-#my $package_rs = $schema->resultset('Package')->search({'me.lastcheck' => \$interval} , {join => => 'repository_id'});
-#$package_rs->delete_all;
-
-info ("stopping");
-

Copied: svnbuildstat/trunk/script/svnbuildstat_update-db.pl (from rev 511, svnbuildstat/trunk/script/svnbuildstat_update-db-svn.pl)
===================================================================
--- svnbuildstat/trunk/script/svnbuildstat_update-db.pl	                        (rev 0)
+++ svnbuildstat/trunk/script/svnbuildstat_update-db.pl	2007-11-18 23:13:56 UTC (rev 512)
@@ -0,0 +1,331 @@
+#!/usr/bin/perl -w
+use File::Temp qw/ tempfile /;
+
+use strict;
+
+use LWP::UserAgent;
+use Data::Dumper;
+use File::Basename;
+use Time::Local 'timelocal_nocheck';
+
+use lib '/home/sites/svnbuildstat.debian.net/svnbuildstat/lib';
+use SvnBuildStat::Schema;
+use SvnBuildStat::Config;
+use Logger::Syslog;
+use SvnBuildStat::Common;
+use SvnBuildStat::Vcs;
+
+my $config;
+my $schema;
+
+
+sub createTarballUrlFromTarballlayout {
+  my ($repository, $package) = @_;
+
+  return unless $$repository->tarballlayout;
+  my $packagename =  $$package->name;
+  my $tarball = SvnBuildStat::Common::mkTarballFromPackage($package);
+  my $tarballuri = $$repository->tarballlayout;
+  $tarballuri =~ s/\@TARBALL@/$tarball/;
+  $tarballuri =~ s/\@PACKAGE@/$packagename/;
+#  print  "\n--->".$tarballuri."\n";
+
+  return $tarballuri;
+}
+
+
+sub getUscanData {
+  my ($package, $watchfile) = shift;
+  my $cmd;
+
+  return unless $watchfile;
+  return unless $$package->svndebrelease;
+
+  my ($fh, $tmpfile) = tempfile(SUFFIX => '.uscan');
+  print $fh @$watchfile;
+  close ($fh);
+
+  my $majorrelease = $$package->svndebrelease;
+  $majorrelease =~ s/^\d+://;
+  $majorrelease =~ s/-[0-9A-Za-z\.~]*$//;
+  $majorrelease =~ s/dfsg.*//;
+  $majorrelease =~ s/\d+://;
+  $cmd = "uscan --package ".$$package->name." --dehs --upstream-version ".$majorrelease." --watchfile ".$tmpfile;
+#  print $cmd."\n";
+  my @uscan = `$cmd`;
+  unlink $tmpfile or warn;
+  return unless @uscan > 2; # empty output
+
+  my $tarballuri;
+  my $isuptodate = 'f';
+  my $iswatchfilebroken = 'f';
+  my $upstreamrelease;
+  foreach (@uscan) {
+#    print;
+    $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;
+  $tarballuri = '' unless $isuptodate eq 't';
+
+  return {tarballuri => $tarballuri, isuptodate => $isuptodate, upstreamrelease => $upstreamrelease, iswatchfilebroken => $iswatchfilebroken};
+}
+
+sub updateVcsChanges {
+  my ($package, $vcschanges) = @_;
+
+  my @added_entry_id;
+  foreach (@$vcschanges) {
+    # TODO Git users put there email address in there login. With it we can link the vcs user
+    # to the package maintainer
+    use Data::Dumper;
+    print Dumper($_);
+    my $userlogin = $schema->resultset('Userlogin')->find_or_create({name=>$_->{login}});
+    my $entry = $schema->resultset('Changelogentry')->create({
+	userlogin_id =>$userlogin->id,
+	package_id => $$package->id,
+	date => $_->{date},
+	rev => $_->{rev},
+      });
+    $entry->log($_->{text});
+    $entry->update;
+    push @added_entry_id, $entry->id;
+  }
+
+  # I remove the old
+  if (@added_entry_id) { 
+    $schema->resultset('Changelogentry')->search({
+	id => { '!=', \@added_entry_id },
+	package_id => $$package->id
+      })->delete;
+  }
+
+}
+
+sub importPkg {
+  my( $repository, $uri, $tarballonrepository) = @_;
+
+  my @maintainer;
+  my $packagesrc;
+  my $tarballuri;
+  my $todo;
+  my $currentpendingbug;
+# arch
+  my $i386 = 'f';
+  my $powerpc = 'f';
+  my $sparc = 'f';
+  my $amd64 = 'f';
+
+  my $vcs;
+
+  my $vcsname = $$repository->vcs_id->name;
+  $vcs = new SvnBuildStat::Vcs($vcsname, $uri);
+
+  my $rev = $vcs->getCurrentRev();
+
+
+  if (!$rev) {
+    info ("Can't get current svn revision");
+    return;
+  }
+
+  my $control = SvnBuildStat::Common::parseControl($vcs->getControl());
+  if (!$control) {
+    info ("Failed to parse $uri/debian/control");
+    return;
+  }
+
+  my $package = $schema->resultset('Package')->find_or_create({name => $control->{packagesrc}});
+
+  if (defined($rev) && defined ($package->vcsrev) && $rev eq $package->vcsrev) {
+    debug ("no need to refresh");
+    return;
+  }
+  print "GO ".$package->name."\n";
+
+  $package->issrcinmypool (0); # deprecated, replaced by dscuri
+  $package->dscuri(undef);
+
+  my $changelog = SvnBuildStat::Common::parseChangelog($vcs->getChangelog);
+  $package->realsvndebrelease($changelog->{realsvndebrelease});
+  $package->svndebrelease ($changelog->{svndebrelease});
+  $package->currentchangelogentry($changelog->{currentchangelogentry});
+  $package->currentpendingbug($changelog->{currentpendingbug});
+
+  my @todo = $vcs->getTODO();
+  if (@todo) {
+    $todo .= $_ foreach @todo;
+  }
+  $package->update_from_related('repository_id',$$repository);
+
+  $package->vcsuri($uri);
+  $package->repository_id($$repository);
+
+  # Delete the current relation betwen the maintainers and the package
+  $schema->resultset('PackageMaintainer')->search({
+      package_id => $package->id
+    })->delete;
+
+  # And recreate them
+  foreach (@{$control->{maintainers}}) {
+    my $maintainer = $schema->resultset('Maintainer')->find_or_create({email=>$_->{email}});
+    $maintainer->name($_->{name});
+    $maintainer->update();
+
+    my $package_maintainer =
+    $package->find_or_create_related('package_maintainers', {
+	'maintainer_id' => $maintainer->id});
+  }
+
+  # I keep the changelog entry since the oldest build, si I need.. ...to
+  # find the oldest build
+  my $vcschangelog_rs = $schema->resultset('Changelogentry')->search({
+      package_id => $package->id,
+    }, {order_by => "rev DESC"});
+  my $last_rev = $vcschangelog_rs->first->rev if ($vcschangelog_rs->first);
+  updateVcsChanges(\$package, $vcs->getLastVcsChanges(5));
+
+
+  # Search for the tarball
+  my $tarball = SvnBuildStat::Common::mkTarballFromPackage(\$package);
+  my $uscandata = getUscanData(\$package, $vcs->getWatchfile);
+  my $dataFromDebianFtp = SvnBuildStat::Common::getDataFromDebianFtp(\$package);
+  use Data::Dumper;
+  print Dumper($dataFromDebianFtp);
+  my $tarballurlfromtarballlayout = createTarballUrlFromTarballlayout($repository,\$package);
+  $package->iswatchfilebroken($uscandata->{iswatchfilebroken});
+  # Is the tarball on a Debian mirror?
+  # TODO, isnative shouldn't be returned by dataFromDebianFtp
+  if ($dataFromDebianFtp->{isnative} eq 't') {
+    $package->isnative(1);
+    $package->tarballuri('');
+    $package->istarballpresent(0);
+  } else {
+    $package->isnative(0);
+    if ($dataFromDebianFtp->{tarballuri}) {
+      $package->tarballuri($dataFromDebianFtp->{tarballuri});
+      $package->istarballpresent(1);
+    }
+    elsif ($uscandata->{tarballuri}) {
+      $package->tarballuri($uscandata->{tarballuri});
+      $package->istarballpresent(1);
+    }
+    # Or on a HTTP/FTP space is a tarball layout exists
+    elsif (SvnBuildStat::Common::testUrl($tarballurlfromtarballlayout)) {
+      $package->tarballuri($tarballurlfromtarballlayout);
+      $package->istarballpresent(1);
+      # Or on the same repository
+    } elsif($tarballonrepository && exists ($tarballonrepository->{$tarball})) {
+      my $t = $tarballonrepository->{$tarball};
+      $t =~ s!svn://svn.debian.org/svn/(.*)!http://svn.debian.org/wsvn/$1?op=file&rev=0&sc=0!;
+    } else {
+      $package->tarballuri('');
+      $package->istarballpresent(0);
+    }
+  } 
+
+  # 
+  $package->isuptodate($uscandata->{isuptodate});
+  $package->upstreamrelease($uscandata->{upstreamrelease});
+  $package->isindebian($dataFromDebianFtp->{isindebian});
+
+  $package->i386($control->{i386});
+  $package->powerpc($control->{powerpc});
+  $package->sparc($control->{sparc});
+  $package->amd64($control->{amd64});
+  $package->todo($todo);
+  $package->lastcheck('now');
+  $package->vcsrev($rev); # at the end since it marks in the new status of the package ins the DB
+  $package->update();
+}
+
+
+sub importRepository {
+  my $repository = shift;
+
+  my $vcs = new SvnBuildStat::Vcs::Svn($$repository->uri);
+  print "Repository: ".$$repository->name."\n";
+  debug ("importing ".$$repository->name);
+  my $rev = $vcs->getCurrentRev();
+  if(! $rev) {
+    print "Failed to get the current revision of ".$$repository->name."\n";
+    return;
+  }
+
+  if ($$repository->vcsrev eq $rev) {
+    debug ("no need to refresh ".$$repository->name);
+    return;
+  }
+
+  my ($uri, $tarballonrepository) = $vcs->scan();
+
+  foreach (@$uri) {
+    # look for packages
+    importPkg($repository,$_,$tarballonrepository);
+  }
+
+  $$repository->vcsrev($rev);
+  $$repository->lastcheck('now');
+  $$repository->update();
+
+  debug ($$repository->name." imported");
+}
+###################################################
+###################################################
+###################################################
+###################################################
+###################################################
+############### MAIN ##############################
+###################################################
+###################################################
+
+info ("starting");
+
+$config = new SvnBuildStat::Config();
+$schema = SvnBuildStat::Schema->connect(
+  $config->db_dsn,
+  $config->db_user,
+  $config->db_password,
+  {AutoCommit => 1, debug => 1}
+);
+
+
+########
+
+# Import packages
+my $repository_rs = $schema->resultset('Repository')->search({enabled => 'true'});
+while (my $repository = $repository_rs->next) {
+  my $vcsname = $repository->vcs_id->name;
+  my $uri = $repository->uri;
+
+  # one repo per team
+  if ($vcsname =~ /^(svn)$/) {
+    print "import Repository". $repository->name."\n";
+    importRepository(\$repository);
+  } else { # or one repo per package
+    # TODO put this in importRepository()
+    my $vcs = new SvnBuildStat::Vcs($vcsname, $uri);
+    my $beginrev = $vcs->getCurrentRev();
+    next if $repository->vcsrev eq $beginrev;
+    print "import Repository as package ". $repository->name."\n";
+    importPkg (\$repository, $uri);
+    my $endrev = $vcs->getCurrentRev();
+    print "$beginrev eq $endrev\n";
+    if ($beginrev eq $endrev) {
+      $repository->vcsrev($endrev);
+      $repository->lastcheck('now');
+    }
+    $repository->update();
+  }
+}
+
+# Purge the removed packages
+# This semems to be fucked?
+#my $interval = "< repository_id.lastcheck - interval '1 day'";
+#my $package_rs = $schema->resultset('Package')->search({'me.lastcheck' => \$interval} , {join => => 'repository_id'});
+#$package_rs->delete_all;
+
+info ("stopping");
+




More information about the Collab-qa-commits mailing list