[Bio] / RAST / rast_sync.pl Repository:
ViewVC logotype

View of /RAST/rast_sync.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (as text) (annotate)
Thu Oct 9 15:14:19 2008 UTC (11 years, 1 month ago) by paczian
Branch: MAIN
CVS Tags: mgrast_dev_02212011, rast_rel_2010_0928, rast_rel_2010_0526, rast_rel_2014_0729, rast_rel_2009_05_18, rast_rel_2009_0925, rast_rel_2010_1206, rast_rel_2010_0118, rast_rel_2009_02_05, rast_rel_2011_0119, rast_rel_2008_12_18, mgrast_rel_2008_1110_v2, rast_rel_2008_10_09, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_10_29, mgrast_dev_02222011, rast_rel_2009_03_26, rast_rel_2008_11_24
Changes since 1.5: +8 -6 lines
switched jobcache.db from SQLite to MySQL

#!/usr/bin/env perl

use strict;
use warnings; 

use DBMaster;
use Getopt::Long;
use DirHandle;

use FIG_Config;

use constant BACKEND  => 'MySQL';
use constant DATABASE => 'JobCacheRast';

# usage message 
sub usage {
  my $error = shift;
  print "Usage: rast_sync.pl [-job id] [-verbose]\n";
  print "Error: $error\n" if($error);
  exit;
}

print "[SYNC] Syncing $FIG_Config::rast_jobs\n";

# get command line parameters
my %options = ();
GetOptions (\%options, 
	    "job=s", "verbose",
	    "backend=s", "database=s",
	   ); 

print "[SYNC] Verbose mode ON\n" if ($options{verbose});

# check for job directory
unless(defined($FIG_Config::rast_jobs)) {
  &usage("No job directory found in FIG_Config.pm.");
}

# check for web application db settings in FIG_Config
unless(defined($FIG_Config::webapplication_db) and
       defined($FIG_Config::webapplication_backend)) {
  &usage("No webapplication db settings found in FIG_Config.pm.");
}


# init PPO 
my $backend  = $options{backend} || BACKEND;
my $database = $options{database} || $FIG_Config::rast_jobcache_db || DATABASE;
my $dbmaster = DBMaster->new(-database => $database,
			     -backend  => $backend,
			     -host     => $FIG_Config::rast_jobcache_host,
			     -user     => $FIG_Config::rast_jobcache_user,
			     -password => $FIG_Config::rast_jobcache_password );

# update just the specified job
if ($options{job}) {
  my $job;
  eval { $job = $dbmaster->Job->init({ id => $options{job}}) };
  if ($job) {
    print "Updated job id ".$job->id.".\n" 
      if ($options{verbose});
  }
  else {
    print STDERR "Update failed on job ".$options{job}.".\n";
  }
}

# update all jobs in the job directory
else {
  my $jobs = [];
  my $dh = new DirHandle($FIG_Config::rast_jobs);
  while (defined($_ = $dh->read())) {
    next unless /^\d+$/;
    my $id = $_;
    my $job;
    eval { $job = $dbmaster->Job->init({ id => $id}) };
    if ($job) {
      print "Update successful on job $id.\n"
	if ($options{verbose});
      push @$jobs, $job;
    }
    else {
      print STDERR "[SYNC] Update failed on job $id: $@\n";
    }
  }
  print "[SYNC] Updated ".scalar(@$jobs)." in the job directory.\n";
}

exit 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3