[Bio] / FigKernelScripts / install-data.pl Repository:
ViewVC logotype

View of /FigKernelScripts/install-data.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (as text) (annotate)
Thu Nov 29 23:08:26 2007 UTC (11 years, 11 months ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.7: +2 -2 lines
fix to dvd data installer

#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#


use FIG;
use strict;
use File::Spec::Functions 'rel2abs';
use Text::Wrap;
use File::Copy;
use File::Basename;
use File::Path;

#
# Install the contents of a data disk.
#

if (@ARGV != 1)
{
    die "Usage: install-data <data-disk-directory>\n";
}



my($data_dir) = @ARGV;

$data_dir = rel2abs($data_dir);

#
# First check that the data directory is valid.
#

if (! -d $data_dir or
    ! -f "$data_dir/RELEASE" or
    ! -f "$data_dir/MANIFEST")
{
    die "Data directory $data_dir is not a valid data release disk.\n";
}

#
# Read the release information.
#

my @r = read_release_file("$data_dir/RELEASE");
my($d_name, $d_id, $d_institution, $d_contact, $d_superset_id, @d_info) = @r;

opendir(D, $data_dir) or die "Cannot open data directory $data_dir: $!\n";

my @disk_tags = grep { /^DISK_\d+_OF_\d+$/ } readdir(D);

@disk_tags == 0 and die "Disk tag file DISK_X_OF_Y not found in $data_dir\n";
@disk_tags > 1 and die "Multiple disk tag file files @disk_tags found in $data_dir\n";

my($this_disk, $num_disks) = $disk_tags[0] =~ /DISK_(\d+)_OF_(\d+)/;

#
# At this point we have a valid data disk.
#
# Determine if we are in mid-install already. This is determined by the existence
# of a $FIG_Config::fig/DataInstall directory.
#
# If the directory already exists, we assume we are mid-install. Check the file
# DataInstall/INSTALL_RELEASE to see if it corresponds to the release we
# are now installing. If it does not, bail out, and give the user some idea
# of what is going on.
#
# If the directory doesn't exist, create it, and write the release info
# from this diesk to INSTALL_RELEASE.
#

my $install_dir = "$FIG_Config::fig/DataInstall";

if (-d $install_dir)
{
    if (-f "$install_dir/INSTALL_RELEASE")
    {
	my @r = read_release_file("$install_dir/INSTALL_RELEASE");
	my($r_name, $r_id, $r_institution, $r_contact, $r_superset_id, @r_info) = @r;

	if ($r_id ne $d_id)
	{
	    bad_release($d_name, $r_name);
        }
	#
	# If we get here, we're okay.
	#
    }
    else
    {
	bad_inst_dir();
    }
}
else
{
    #
    # We're just starting the install.
    #
    # Create the staging directory, and copy the release info into it.
    #

    mkdir $install_dir or die "Cannot mkdir $install_dir: $!\n";

    copy("$data_dir/RELEASE", "$install_dir/INSTALL_RELEASE");
}

#
# To do: check to see if we've already installed this disk. Skip this for now.
#

print "Installing data release \"$d_name\". Disk $this_disk of $num_disks\n";

#
# We untar into $install_dir/Stage
#

my $target_dir = "$install_dir/Stage";
&FIG::verify_dir($target_dir);

chdir $target_dir or die "Could not chdir $target_dir: $!\n";

open(M, "<$data_dir/MANIFEST") or die "Cannot open manifest $data_dir/MANIFEST: $!\n";

while (<M>)
{
    chomp;

    my($cksum, $size, $file) = split(/\s+/);
    print "cksum=$cksum size=$size file=$file\n";

    my $path = "$data_dir/$file";

    -f $path or die "File $path missing from disk.\n";

    my $psize = -s $path;
    $psize == $size or die "File $path is of the wrong size (is $psize, should be $size\n";

    #
    # Skip checksum check for now.
    #


    #
    # We only handle data files.
    #

    $file =~ /^data\.\d+\.tgz/ or next;

    #
    # Untar file.
    #

    if (system("tar -z -x -v -f $path") != 0)
    {
	die "Untar of $path failed\n";
    }
}

#
# Install complete.
#
# Create the "INSTALLED_X_OF_Y" file, and see if we have installed all disks.
#

my $fn = sprintf("$install_dir/INSTALLED_%s_OF_%s", $this_disk, $num_disks);
open(F, ">$fn")  or die "Cannot create $fn: $!\n";
close(F);

#
# Check to see if all are done.
#

my $more_needed = 0;

for (my $i = 1; $i <= $num_disks; $i++)
{
    my $fn = sprintf("$install_dir/INSTALLED_%s_OF_%s", $i, $num_disks);
    if (-f $fn)
    {
	print "Disk $i is installed.\n";
    }
    else
    {
	print "Disk $i is not installed.\n";
	$more_needed++;
    }
}

if ($more_needed > 0)
{
    print "Finished installing disk $this_disk. $more_needed disks need to be installed.\n";
    exit;
}

#
# We've installed them all.
#

print "All disks have been installed. Setting up SEED data directory.\n";

#
# First determine what the data directory looks like. It should be
# a directory that contains directories Organisms, NR, Sims, etc.
#

opendir(D, "$target_dir") or die "Cannot open $target_dir: $!\n";
my @f = grep (!/^\./, readdir(D));
print "$target_dir has files @f\n";

#
# Take the easy case first.
#

my $installed_data;

if (@f == 1)
{
    #
    # This should be our data path.
    #
    
    my $dp = "$target_dir/$f[0]";
    if (-d "$dp/Organisms" and -d "$dp/Global")
    {
	print "$dp appears to be a valid Data directory\n";
	$installed_data = $dp;
    }
    else
    {
	print "$dp is not a valid Data directory\n";
    }
}

if (!$installed_data)
{
    bad_data_format($target_dir);
}

#
# Now, $installed_data is our data directory. See if a
# directory of that name is present in the fig directory.
#

my $data_basename = basename($installed_data);

if (-e "$FIG_Config::fig/$data_basename")
{
    #
    # It already exists. Find a new name to call it.
    #

    my $idx = 0;
    while (1)
    {
	my $fn = sprintf("Data.%03d", $idx);
	if (! -e "$FIG_Config::fig/$fn")
	{
	    $data_basename = $fn;
	    print "Picking $data_basename for the new data\n";
	    last;
	}
	$idx++;
    }
}

print "Moving data to $FIG_Config::fig/$data_basename\n";

rename($installed_data, "$FIG_Config::fig/$data_basename");

#
# Check if fig/Data is a symlink that we can redirect.
# We don't have to do this if the data directory started
# out being called Data.
#

if ($data_basename ne "Data")
{
    
    my $data_link = "$FIG_Config::data";
    
    if (-l $data_link)
    {
	my $targ = readlink($data_link);
	print "$FIG_Config::data is a symlink pointing to $targ. Not changing this link\n";
	print "To use the newly installed data, run the following commands:\n";
	print "\trm $FIG_Config::data\n";
	print "\tln -s $data_basename $FIG_Config::data\n";
    }
    elsif (-d $data_link)
    {
	my $new;
	$new = "$FIG_Config::fig/Data." . int(time);
	
	print "$FIG_Config::data is a directory. It will\n";
	print "be have to moved out of the way to use the newly-installed data.\n";
	print "To do this, run the following commands:\n";
	print "\tmv $FIG_Config::data $new\n";
	print "\tln -s $data_basename $FIG_Config::data\n";
    }
    else
    {
	symlink($data_basename, $FIG_Config::data);
    }
}

print "Installation succeded.\n";

#
# Remove the staging directory.
#

rmtree($install_dir);

#
# Read a release info file.
#
sub read_release_file
{
    my($file) = @_;

    open(my $fh, "<$file") or die "Cannot open data release file $file: $!\n";

    my @r = <$fh>;
    chomp(@r);
    map { s/\r//g; } @r;

    if (@r < 5)
    {
	die "Invalid data release file $file: Not enough lines.\n";
    }

    return @r;
}

sub bad_release
{
    my($d_name, $r_name)  = @_;
    die join("\n", '', fill('', '', <<END), '', '')
The data on the installation media ($data_dir)
is from a different release ($d_name) 
than the data present in the installation temporary directory
$FIG_Config::fig/DataInstall ($r_name). The installation temporary directory
may be from a different disk set, or you have mounted an incorrect data disk.
END
}

sub bad_inst_dir
{
    die join("\n", '', fill('', '', <<END), '', '')
The installation temporary directory $FIG_Config::fig/DataInstall exists,
but does not have what we expect - the INSTALL_RELEASE file is missing.

If there was a problem with an earlier attempt at installation, try
removing the directory with this command:

    rm -f $FIG_Config::fig/DataInstall

and retrying the install.
END
}

sub bad_data_format
{
    my($dir) = @_;

    die <<END;
The data as extracted to $dir
is not recognizable as a valid SEED data directory. It
may correct, but not organized properly for this script
to understand. If you wish, you can peruse the extracted data
in the directory

\t$dir

to see if you can find the proper data. If you do, you can 
manually copy or move it to the FIG data directory 
$FIG_Config::data and proceed with installation.
END
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3