[pkg-bioc] svn commit r344 r344 - in /branches/tools-ng: pkgbioc.pm r_pkg_update.pl storage.pm
psychedelys-guest at users.alioth.debian.org
psychedelys-guest at users.alioth.debian.org
Sat Oct 13 12:57:14 UTC 2007
Author: psychedelys-guest
Date: Sat Oct 13 12:57:13 2007
New Revision: 344
URL: http://svn.debian.org/wsvn/pkg-bioc/?sc=1&rev=344
Log:
first sql commit ;)
Added:
branches/tools-ng/storage.pm
Modified:
branches/tools-ng/pkgbioc.pm
branches/tools-ng/r_pkg_update.pl
Modified: branches/tools-ng/pkgbioc.pm
URL: http://svn.debian.org/wsvn/pkg-bioc/branches/tools-ng/pkgbioc.pm?rev=344&op=diff
==============================================================================
--- branches/tools-ng/pkgbioc.pm (original)
+++ branches/tools-ng/pkgbioc.pm Sat Oct 13 12:57:13 2007
@@ -21,6 +21,7 @@ use CRAN2DEB;
# providing the building methods
use PBuilder;
use CowBuilder;
+use storage;
our @ISA = qw(Exporter); # make these symbols known
our @EXPORT = qw(check_requierment
@@ -290,10 +291,11 @@ sub readListListList($) {
return %list;
}
-sub populate_source($$$$$) {
- my ( $repo, $directory, $sources, $repoof, $global ) = @_;
+sub populate_source($$$$) {
+ my ( $repo, $directory, $sources, $sth ) = @_;
my $ori = cwd();
print "populate source $repo\n" if $main::verbose;
+ my $repo_id = insert_if_not_found_repository($repo);
chdir( "../" . $directory . "/$sources" );
my @ary = glob("*.tar.gz");
print "Found " . ( $#ary + 1 ) . " patterns in the repository $repo.\n"
@@ -301,14 +303,15 @@ sub populate_source($$$$$) {
foreach my $cur (@ary) {
next unless defined($cur);
my ( $head_pkg, $version_pkg, $tail_pkg ) = decomposition($cur);
- push( @{ $global->{srcavailable}->{ lc($head_pkg) } }, $repo );
- if ( !exists $repoof->{ lc($head_pkg) } ) {
- $repoof->{ lc($head_pkg) } = $repo;
+ my $pkg_id = insert_if_not_found_packagesname( $sth, $head_pkg );
+ my $size = stat($cur)->size;
+
+ $pkg_id =
+ insert_update_packagesupdate( $sth, $pkg_id, $head_pkg, $repo_id,
+ $repo, $version_pkg, $size );
if ( !-s $cur ) {
- push(
- @{ $global->{cannotbuild}->{$head_pkg} },
- "problem during mirroing, empty archive"
- );
+ insert_update_cannotbuild( $sth, $pkg_id,
+ "problem during mirroing, empty archive" );
print $directory
. "/sources/"
. $cur
@@ -317,21 +320,16 @@ sub populate_source($$$$$) {
}
#checking the size of the package if > $main::maxsize MB -> too big
- if ( stat($cur)->size > $main::maxsize ) {
- push(
- @{ $global->{cannotbuild}->{$head_pkg} },
+ if ( $size > $main::maxsize ) {
+ insert_update_cannotbuild( $sth, $pkg_id,
"too big "
. humansize( stat($cur)->size ) . " > "
- . humansize($main::maxsize)
- );
- print $directory
- . "/sources/"
- . $cur
- . " is too big too be build\n"
+ . humansize($main::maxsize) );
+ print $directory . "/sources/" . $cur . " is too big too be build\n"
if $main::verbose;
}
}
- }
+
chdir($ori);
}
Modified: branches/tools-ng/r_pkg_update.pl
URL: http://svn.debian.org/wsvn/pkg-bioc/branches/tools-ng/r_pkg_update.pl?rev=344&op=diff
==============================================================================
--- branches/tools-ng/r_pkg_update.pl (original)
+++ branches/tools-ng/r_pkg_update.pl Sat Oct 13 12:57:13 2007
@@ -148,6 +148,7 @@ use LWP::Simple;
use CRAN2DEB;
use pkgbioc;
use debtag;
+use storage;
# unbuffered output:
$| = 1;
@@ -159,6 +160,15 @@ $VERSION = $1;
($name = $0) =~ s|.*/||;
print("$name rev:$VERSION\n");
+# SQL Stuff
+my $ip = '192.168.44.33';
+my $dbname = "pkgbioc";
+my $username = "pkgbioc";
+my $user_password = "pkgbioc";
+
+init_storage( "DBI:mysql:dbname=$dbname;host=$ip", $username, $user_password );
+start_tracking( $name, $VERSION );
+
my %options = (
"help" => \$help,
"man" => \$man,
@@ -271,6 +281,11 @@ check_requierment( $installMethods, $vs,
&debtag_update()
if ($dotagupdate);
+stop_tracking($name);
+close_storage();
+
+##### Just sub functions ####
+
sub remove_directory($) {
my ($dir) = @_;
@@ -719,4 +734,21 @@ sub main {
chdir $origpath;
}
+ my %sth_hash = ();
+
+ prepare_store_source( \%sth_hash );
+
+ # this assures that the resulting priority will be "cran > bioc > omegahat"
+ populate_source( "cran", "cran", $sources, \%sth_hash )
+ if ( $RepositoryListFlat =~ /cran/ );
+
+ populate_source( "bioc", $bioccurrent, $sources, \%sth_hash )
+ if ( $RepositoryListFlat =~ /bioc/ );
+
+ populate_source( "omegahat", "omegahat", $sources, \%sth_hash )
+ if ( $RepositoryListFlat =~ /omegahat/ );
+
+ finish_store_source( \%sth_hash );
+
+ clean_cannotbuild_since_last_updated($name);
}
Added: branches/tools-ng/storage.pm
URL: http://svn.debian.org/wsvn/pkg-bioc/branches/tools-ng/storage.pm?rev=344&op=file
==============================================================================
--- branches/tools-ng/storage.pm (added)
+++ branches/tools-ng/storage.pm Sat Oct 13 12:57:13 2007
@@ -0,0 +1,650 @@
+# $Id: $
+#
+# This modules is used in providing a standart storage mecanism
+#
+package storage;
+
+use strict;
+use warnings;
+require Exporter;
+
+use DBI;
+
+our @ISA = qw(Exporter); # make these symbols known
+our @EXPORT = qw(
+ init_storage
+ start_tracking
+ stop_tracking
+ insert_if_not_found_repository
+ prepare_store_source
+ insert_if_not_found_packagesname
+ insert_update_packagesupdate
+ insert_update_cannotbuild
+ clean_cannotbuild_since_last_updated
+ finish_store_source
+ close_storage
+);
+
+our @EXPORT_OK = qw( );
+our %EXPORT_TAGS = ( all => [@EXPORT_OK] );
+
+my $dbh = ();
+my $sth;
+my @vetor;
+my $field;
+
+# mysql -h ${ip} -u ${rootuser} -p -e "create database ${db}; grant ALL on ${db}.* to ${user}@${ipname} identified by '${passwd}'; FLUSH PRIVILEGES; "
+
+sub insert_if_not_found_arch($) {
+ my (@arch) = @_;
+ print "adding " . join( ",", @arch ) . " to architectures\n";
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+
+ my $sthselect =
+ $dbh->prepare("SELECT count(*) from architectures where name = ?");
+ my $sthinsert =
+ $dbh->prepare("INSERT INTO architectures (name) VALUES( ? )");
+ $dbh->prepare("BEGIN TRANSACTION ");
+
+ foreach my $k (@arch) {
+ $sthselect->execute($k)
+ or die "Couldn't execute statement: " . $sthselect->errstr;
+ my ($l) = @{ $sthselect->fetchrow_arrayref };
+ if ( $l == 0 ) {
+ print "inserting $k\n";
+ $sthinsert->execute($k)
+ or die "Couldn't execute statement: " . $sthinsert->errstr;
+
+ }
+
+ }
+ $dbh->prepare("COMMIT TRANSACTION ");
+
+ $sthselect->finish();
+ $sthinsert->finish();
+}
+
+# we want to use transactions, so we will turn AutoCommit off, RaiseError on, and leave PrintError
+sub init_storage($$$) {
+ my ( $dbchain, $username, $user_password ) = @_;
+ $dbh =
+ DBI->connect( $dbchain, $username, $user_password,
+ { RaiseError => 1, AutoCommit => 0 } )
+ or die "Could not create database '$dbchain'.\n'";
+
+ if ($dbh) {
+ print "connected\n";
+ }
+ else {
+ print "Cannot connect to server: $DBI::errstr\n";
+ print " db connection failed\n";
+ }
+ my $sql;
+
+ # Howto support the any category ?
+ $sql = qq{ CREATE TABLE IF NOT EXISTS architectures (
+ id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
+ name VARCHAR(10) UNIQUE
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for architectures.\n";
+
+ $sql = qq{ CREATE TABLE IF NOT EXISTS tracking (
+ id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
+ deamon VARCHAR(50) UNIQUE,
+ version TEXT,
+ last_start TIMESTAMP,
+ last_stop TIMESTAMP,
+ toberun BOOLEAN
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for tracking.\n";
+
+ #every packages name is getting an uniq id
+ $sql = qq{ CREATE TABLE IF NOT EXISTS packagesname (
+ id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
+ name VARCHAR(70) UNIQUE
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for packagesname.\n";
+
+ # each repository is getting an uniq id,
+ # ext will refer to Debian package
+ $sql = qq{ CREATE TABLE IF NOT EXISTS repository (
+ id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
+ name VARCHAR(20) UNIQUE,
+ url TEXT
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for repository.\n";
+
+ $sql = qq{ CREATE TABLE IF NOT EXISTS anomalies (
+ id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
+ name VARCHAR(100) UNIQUE
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for anomalies.\n";
+
+ #=== done in r_pkg_update ===
+
+ # updated during the r_pkg_update.pl parsing
+ # create a uniq id for each couple (packages_name.id, repository.id).
+ # I just index, (repository, version)
+ # last seen just tell me when last time I saw this revision on this repository.
+ # size is the trunk of the size, who care about decimals!
+ $sql = qq{ CREATE TABLE IF NOT EXISTS packagesupdate (
+ id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
+ packagesname_id INTEGER NOT NULL,
+ repository_id INTEGER NOT NULL,
+ version TEXT,
+ size INTEGER,
+ lastseen TIMESTAMP,
+ UNIQUE (packagesname_id, repository_id),
+ FOREIGN KEY (packagesname_id) REFERENCES packagesname(id),
+ FOREIGN KEY (repository_id) REFERENCES repository(id)
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for packagesupdate.\n";
+
+ $sql = qq{ CREATE TABLE IF NOT EXISTS cannotbuild (
+ id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
+ packagesupdate_id INTEGER NOT NULL,
+ anomalies_id INTEGER NOT NULL,
+ lastcheck TIMESTAMP,
+ UNIQUE (packagesupdate_id, anomalies_id),
+ FOREIGN KEY (packagesupdate_id) REFERENCES packagesupdate(id),
+ FOREIGN KEY (anomalies_id) REFERENCES anomalies(id)
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for cannotbuild.\n";
+
+ # === done in r_pkg_ordering ===
+
+# updated during r_pkg_ordering.
+# parsing all the Descriptions file.
+# status: 'error'|'clean'|'unclean'
+# error : something happen before which block the package from being buildable.
+# clean : everything goes without problem, parsed dependencies,....
+# unclean: something happen during the parsing, check the log to see what
+#
+ $sql = qq{ CREATE TABLE IF NOT EXISTS packages (
+ id INTEGER PRIMARY KEY NOT NULL,
+ Author TEXT,
+ Package TEXT,
+ Date TEXT,
+ Description TEXT,
+ License TEXT,
+ Title TEXT,
+ Imports TEXT,
+ URL TEXT,
+ biocViews TEXT,
+ isBinary BOOLEAN,
+ status ENUM('error','clean','unclean'),
+ FOREIGN KEY (id) REFERENCES packagesupdate(id)
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for packages.\n";
+
+ #list of dependencies of a package
+ $sql = qq{ CREATE TABLE IF NOT EXISTS dependencies (
+ id INTEGER PRIMARY KEY NOT NULL,
+ depend_id INTEGER NOT NULL,
+ FOREIGN KEY (id) REFERENCES packagesupdate(id),
+ FOREIGN KEY (depend_id) REFERENCES packagesupdate(id)
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for dependencies.\n";
+
+ # list of suggestion for a package.
+ $sql = qq{ CREATE TABLE IF NOT EXISTS suggested (
+ id INTEGER PRIMARY KEY NOT NULL,
+ suggest_id INTEGER NOT NULL,
+ FOREIGN KEY (id) REFERENCES packagesupdate(id),
+ FOREIGN KEY (suggest_id) REFERENCES packagesupdate(id)
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for suggested.\n";
+
+ # list of recommanded for a package.
+ $sql = qq{ CREATE TABLE IF NOT EXISTS recommended (
+ id INTEGER PRIMARY KEY NOT NULL,
+ recommend_id INTEGER NOT NULL,
+ FOREIGN KEY (id) REFERENCES packagesupdate(id),
+ FOREIGN KEY (recommend_id) REFERENCES packagesupdate(id)
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for recommended.\n";
+
+ # === done in r_pkg_import_cran.pl ===
+
+ # information extracted from r_pkg_import_cran.pl
+ $sql = qq{ CREATE TABLE IF NOT EXISTS externals_information (
+ id INTEGER PRIMARY KEY NOT NULL,
+ status_32 TEXT NOT NULL,
+ url_32 TEXT,
+ status_64 TEXT NOT NULL,
+ url_64 TEXT,
+ FOREIGN KEY (id) REFERENCES packagesupdate(id)
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for externals_information.\n";
+
+ #=== done in r_pkg_builder ===
+
+# updated by r_pkg_builder
+# debianized(name, version, date, status, scriptversion, current) unique(name,version)
+# * date= date where the packages pass the last time.
+# * scriptversion= version of the script which build it.
+# * debversion = current debian version of the package.
+# * baseversion = based on the following source package version.
+# * current = 'nil'|'last'|'depreciated'
+# * status_pkg = 'donotpackage'|'failed'|'deb'
+# * status_qa = 'ok'|'warning'|'error'
+# * motif = motif, if any.
+
+ # This table is needed to generate r_pkg_web
+ $sql = qq{ CREATE TABLE IF NOT EXISTS debianized (
+ id INTEGER PRIMARY KEY NOT NULL,
+ debversion TEXT,
+ baseversion TEXT,
+ date TIMESTAMP,
+ scriptversion TEXT,
+ current ENUM('nil','last','depreciated') NOT NULL,
+ status_pkg ENUM('donotpackage','failed','deb') NOT NULL,
+ status_qa ENUM('ok','warning','error') NOT NULL,
+ motif TEXT,
+ FOREIGN KEY (id) REFERENCES packagesupdate(id)
+ ) };
+ $dbh->do($sql)
+ or die "Could not create table for debianized.\n";
+
+ # prestore arch if they do not exist.
+ &insert_if_not_found_arch( "ext", "i386", "amd64", "ppc" );
+}
+
+sub start_tracking($$) {
+ my ( $deamon, $version ) = @_;
+
+ print "adding $deamon to start_time to tracking\n";
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+
+ my $sthselect =
+ $dbh->prepare("SELECT count(*) FROM tracking WHERE deamon = ?");
+ my $sthselectversion = $dbh->prepare(
+ "SELECT count(*) FROM tracking WHERE deamon = ? AND VERSION = ?");
+ my $sthinsert = $dbh->prepare(
+ "INSERT INTO tracking (deamon,version,last_start) VALUES( ?, ?, ? )");
+ my $sthupdate =
+ $dbh->prepare("UPDATE tracking SET last_start = ? where deamon = ?");
+ my $sthupdateversion = $dbh->prepare(
+ "UPDATE tracking SET last_start = ?, version = ? where deamon = ?");
+
+ $dbh->prepare("BEGIN TRANSACTION ");
+
+ $sthselect->execute($deamon)
+ or die "Couldn't execute statement: " . $sthselect->errstr;
+ my ($l) = @{ $sthselect->fetchrow_arrayref };
+ if ( $l == 0 ) {
+ print "inserting $deamon\n";
+ $sthinsert->execute( $deamon, $version, "now()" )
+ or die "Couldn't execute statement: " . $sthinsert->errstr;
+
+ }
+ else {
+ $sthselectversion->execute( $deamon, $version )
+ or die "Couldn't execute statement: " . $sthselectversion->errstr;
+ my ($j) = @{ $sthselectversion->fetchrow_arrayref };
+ if ( $j == 0 ) {
+ $sthupdateversion->execute( "now()", $version, $deamon )
+ or die "Couldn't execute statement: " . $sthupdateversion->errstr;
+ }
+ else {
+ $sthupdate->execute( "now()", $deamon )
+ or die "Couldn't execute statement: " . $sthupdate->errstr;
+ }
+
+ }
+ $dbh->prepare("COMMIT TRANSACTION ");
+
+ $sthselect->finish();
+ $sthselectversion->finish();
+ $sthinsert->finish();
+ $sthupdate->finish();
+ $sthupdateversion->finish();
+}
+
+sub stop_tracking($) {
+ my ($deamon) = @_;
+
+ print "adding $deamon to stop_time to tracking\n";
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+
+ my $sthupdate =
+ $dbh->prepare("UPDATE tracking SET last_stop = ? where deamon = ?");
+
+ $dbh->prepare("BEGIN TRANSACTION ");
+ $sthupdate->execute( "now()", $deamon )
+ or die "Couldn't execute statement: " . $sthupdate->errstr;
+ $dbh->prepare("COMMIT TRANSACTION ");
+
+ $sthupdate->finish();
+}
+
+sub close_storage () {
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+ $dbh->disconnect();
+}
+
+sub insert_if_not_found_repository($) {
+ my ($repo) = @_;
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+ my $repo_id = -1;
+ my $sth = $dbh->prepare("SELECT id from repository where name = ?");
+ my $sthinsert =
+ $dbh->prepare("INSERT INTO repository (name,url) VALUES( ?, ? )");
+
+ $sth->execute($repo);
+
+ my $l = $sth->rows();
+ if ( $l == 1 ) {
+ ($repo_id) = @{ $sth->fetchrow_arrayref() };
+ }
+ elsif ( $l == 0 ) {
+ print "inserting repository $repo\n";
+
+ # TODO: do it in an other way, .... hard values are not nice...
+ my $url = "";
+ $url = "http://www.bioconductor.org" if $repo =~ /bioc/m;
+ $url = "http://cran.r-project.org" if $repo =~ /cran/m;
+ $url = "http://www.omegahat.org" if $repo =~ /omegahat/m;
+ $url = "http://www.debian.org" if $repo =~ /ext/m;
+
+ $sthinsert->execute( $repo, $url )
+ or die "Couldn't execute statement: " . $sthinsert->errstr;
+
+ $sth->execute($repo);
+ ($repo_id) = @{ $sth->fetchrow_arrayref() };
+ }
+ else {
+ die
+"Should not have severals line, this is excluded by the SQL constraint for repository $repo\n";
+ }
+ $sth->finish();
+ $sthinsert->finish();
+
+ print "repo_id for $repo is $repo_id\n";
+ return $repo_id;
+}
+
+sub prepare_store_source($) {
+ my ($hash) = @_;
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+
+ $hash->{packagesname}->{sthselect} =
+ $dbh->prepare("SELECT id from packagesname where name = ?");
+ $hash->{packagesname}->{sthinsert} =
+ $dbh->prepare("INSERT INTO packagesname (name) VALUES( ? )");
+
+ $hash->{packagesupdate}->{sthselect} =
+ $dbh->prepare(
+"SELECT version, size FROM packagesupdate WHERE packagesname_id = ? AND repository_id = ? "
+ );
+ $hash->{packagesupdate}->{sthinsert} =
+ $dbh->prepare(
+"INSERT INTO packagesupdate (packagesname_id, repository_id, version, size, lastseen) VALUES( ?,?,?,?,? )"
+ );
+ $hash->{packagesupdate}->{sthupdateseen} =
+ $dbh->prepare(
+"UPDATE packagesupdate SET lastseen = ? WHERE packagesname_id = ? AND repository_id = ?"
+ );
+ $hash->{packagesupdate}->{sthupdateversion} =
+ $dbh->prepare(
+"UPDATE packagesupdate SET version = ?, size = ?, lastseen = ? WHERE packagesname_id = ? AND repository_id = ?"
+ );
+ $hash->{packagesupdate}->{sthselectid} =
+ $dbh->prepare(
+"SELECT id FROM packagesupdate WHERE packagesname_id = ? AND repository_id = ? "
+ );
+
+ $hash->{cannotbuild}->{sthselect} =
+ $dbh->prepare(
+"SELECT count(*) FROM cannotbuild WHERE packagesupdate_id = ? AND anomalies_id = ? "
+ );
+ $hash->{cannotbuild}->{sthinsert} =
+ $dbh->prepare(
+"INSERT INTO cannotbuild (packagesupdate_id, anomalies_id, lastcheck) VALUES( ?,?,? )"
+ );
+ $hash->{cannotbuild}->{sthupdateseen} =
+ $dbh->prepare(
+"UPDATE cannotbuild SET lastcheck = ? WHERE packagesupdate_id = ? AND anomalies_id = ?"
+ );
+
+ $hash->{anomalies}->{sthselect} =
+ $dbh->prepare("SELECT id FROM anomalies WHERE name = ?");
+ $hash->{anomalies}->{sthinsert} =
+ $dbh->prepare("INSERT INTO anomalies (name) VALUES( ? )");
+
+}
+
+sub insert_if_not_found_packagesname($$) {
+ my ( $sth, $name ) = @_;
+ my $pkg_id = -1;
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+ $dbh->prepare("BEGIN TRANSACTION ");
+
+ $sth->{packagesname}->{sthselect}->execute($name)
+ or die "Couldn't execute statement: "
+ . $sth->{packagesname}->{sthselect}->errstr;
+ my $l = $sth->{packagesname}->{sthselect}->rows();
+ if ( $l == 0 ) {
+ print "inserting $name\n";
+
+ $sth->{packagesname}->{sthinsert}->execute($name)
+ or die "Couldn't execute statement: "
+ . $sth->{packagesname}->{sthinsert}->errstr;
+ $sth->{packagesname}->{sthselect}->execute($name)
+ or die "Couldn't execute statement: "
+ . $sth->{packagesname}->{sthselect}->errstr;
+ ($pkg_id) = @{ $sth->{packagesname}->{sthselect}->fetchrow_arrayref() };
+ }
+ elsif ( $l == 1 ) {
+ ($pkg_id) = @{ $sth->{packagesname}->{sthselect}->fetchrow_arrayref() };
+ }
+ else {
+ die
+"Should not have severals line, this is excluded by the SQL constraint\n";
+ }
+
+ $dbh->prepare("COMMIT TRANSACTION ");
+ print "pkg_id for $name is $pkg_id\n";
+ return $pkg_id;
+}
+
+sub insert_update_packagesupdate ($$$$$$$) {
+ my ( $sth, $pkg_id, $name, $repo_id, $repo, $version, $size ) = @_;
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+ $dbh->prepare("BEGIN TRANSACTION ");
+
+ $sth->{packagesupdate}->{sthselect}->execute( $pkg_id, $repo_id )
+ or die "Couldn't execute statement: "
+ . $sth->{packagesupdate}->{sthselect}->errstr;
+ my $l = $sth->{packagesupdate}->{sthselect}->rows();
+ if ( $l == 0 ) {
+ print "inserting $name ($pkg_id)\n";
+
+ $sth->{packagesupdate}->{sthinsert}
+ ->execute( $pkg_id, $repo_id, $version, $size, "now()" )
+ or die "Couldn't execute statement: "
+ . $sth->{packagesupdate}->{sthinsert}->errstr;
+ }
+ elsif ( $l == 1 ) {
+ print "updating $name ($pkg_id)\n";
+ my ( $store_version, $store_size ) =
+ @{ $sth->{packagesupdate}->{sthselect}->fetchrow_arrayref() };
+ if ( ( $store_version =~ /$version/ ) || ( $store_size != $size ) ) {
+ $sth->{packagesupdate}->{sthupdateversion}
+ ->execute( $version, $size, "now()", $pkg_id, $repo_id )
+ or die "Couldn't execute statement: "
+ . $sth->{packagesupdate}->{sthupdateversion}->errstr;
+ }
+ else {
+ $sth->{packagesupdate}->{sthupdateseen}
+ ->execute( "now()", $pkg_id, $repo_id )
+ or die "Couldn't execute statement: "
+ . $sth->{packagesupdate}->{sthupdateseen}->errstr;
+ }
+ }
+ else {
+ die
+"Should not have severals line, this is excluded by the SQL constraint\n";
+ }
+ $dbh->prepare("COMMIT TRANSACTION ");
+
+ $sth->{packagesupdate}->{sthselectid}->execute( $pkg_id, $repo_id )
+ or die "Couldn't execute statement: "
+ . $sth->{packagesupdate}->{sthselectid}->errstr;
+ my ($id) = @{ $sth->{packagesupdate}->{sthselectid}->fetchrow_arrayref() };
+
+ return $id;
+}
+
+sub insert_if_not_found_anomalies ($$) {
+ my ( $sth, $name ) = @_;
+ my $anomaly_id = -1;
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+ $dbh->prepare("BEGIN TRANSACTION ");
+
+ $sth->{anomalies}->{sthselect}->execute($name)
+ or die "Couldn't execute statement: "
+ . $sth->{anomalies}->{sthselect}->errstr;
+ my $l = $sth->{anomalies}->{sthselect}->rows();
+ if ( $l == 0 ) {
+ print "inserting $name\n";
+
+ $sth->{anomalies}->{sthinsert}->execute($name)
+ or die "Couldn't execute statement: "
+ . $sth->{anomalies}->{sthinsert}->errstr;
+ $sth->{anomalies}->{sthselect}->execute($name)
+ or die "Couldn't execute statement: "
+ . $sth->{anomalies}->{sthselect}->errstr;
+ ($anomaly_id) =
+ @{ $sth->{anomalies}->{sthselect}->fetchrow_arrayref() };
+ }
+ elsif ( $l == 1 ) {
+ ($anomaly_id) =
+ @{ $sth->{anomalies}->{sthselect}->fetchrow_arrayref() };
+ }
+ else {
+ die
+"Should not have severals line, this is excluded by the SQL constraint\n";
+ }
+
+ $dbh->prepare("COMMIT TRANSACTION ");
+ print "anomaly_id for $name is $anomaly_id\n";
+
+ return $anomaly_id;
+}
+
+sub insert_update_cannotbuild ($$$) {
+ my ( $sth, $pkg_id, $motif ) = @_;
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+ $dbh->prepare("BEGIN TRANSACTION ");
+
+ my $motif_id = insert_if_not_found_anomalies( $sth, $motif );
+
+ $sth->{cannotbuild}->{sthselect}->execute( $pkg_id, $motif_id )
+ or die "Couldn't execute statement: "
+ . $sth->{cannotbuild}->{sthselect}->errstr;
+ my $l = $sth->{cannotbuild}->{sthselect}->rows();
+ if ( $l == 0 ) {
+ print "inserting $motif ($motif_id) for $pkg_id\n";
+
+ $sth->{cannotbuild}->{sthinsert}->execute( $pkg_id, $motif_id, "now()" )
+ or die "Couldn't execute statement: "
+ . $sth->{cannotbuild}->{sthinsert}->errstrd;
+ }
+ elsif ( $l == 1 ) {
+ print "updating $motif ($motif_id) for $pkg_id\n";
+ $sth->{cannotbuild}->{sthupdateseen}
+ ->execute( "now()", $pkg_id, $motif_id )
+ or die "Couldn't execute statement: "
+ . $sth->{cannotbuild}->{sthupdateseen}->errstr;
+ }
+ else {
+ die
+"Should not have severals line, this is excluded by the SQL constraint\n";
+ }
+ $dbh->prepare("COMMIT TRANSACTION ");
+
+}
+
+
+sub finish_store_source($) {
+ my ($hash) = @_;
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+
+ $hash->{packagesname}->{sthselect}->finish();
+ $hash->{packagesname}->{sthinsert}->finish();
+
+ $hash->{packagesupdate}->{sthselect}->finish();
+ $hash->{packagesupdate}->{sthinsert}->finish();
+ $hash->{packagesupdate}->{sthupdateseen}->finish();
+ $hash->{packagesupdate}->{sthupdateversion}->finish();
+ $hash->{packagesupdate}->{sthselectid}->finish();
+
+ $hash->{cannotbuild}->{sthselect}->finish();
+ $hash->{cannotbuild}->{sthinsert}->finish();
+ $hash->{cannotbuild}->{sthupdateseen}->finish();
+
+ $hash->{anomalies}->{sthselect}->finish();
+ $hash->{anomalies}->{sthinsert}->finish();
+
+}
+
+sub clean_cannotbuild_since_last_updated($)
+{
+ my ( $name ) = @_;
+ if ( !$dbh ) {
+ print "Cannot work, I am not connected\n";
+ }
+
+ my $sthselect =
+ $dbh->prepare(
+"SELECT * FROM cannotbuild, tracking WHERE tracking.deamon = '$name' AND cannotbuild.lastcheck < tracking.last_start"
+ );
+
+ $sthselect->execute();
+ my $l = $sthselect->rows() ;
+
+ print "There is $l too old cannot build\n";
+
+
+ $sthselect->finish();
+
+}
+
+
+
+1;
More information about the pkg-bioc-devel
mailing list