[Bio] / FigRelEngTools / build-data-disks Repository:
ViewVC logotype

View of /FigRelEngTools/build-data-disks

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Tue May 3 15:58:25 2005 UTC (13 years, 11 months ago) by olson
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +129 -15 lines
mods.

#!/usr/bin/perl

use strict;
use POSIX;
use FileHandle;
use File::Basename;
use File::Copy;
use File::Spec::Functions 'rel2abs';

#
# Build SEED data disk images.
#
# We are given a directory containing the data.XXXX.tgz files and a MANIFEST
# with file sizes and checksums. We fill $n_disks disks of $disk_size bytes with
# files from this directory.
#
# The directory must also contain the RELEASE file for this data release.
#
# Output goes into $outdir/disk_N.
#
#

@ARGV == 2 or die "Usage: $0 data-dir output-dir\n";

my($dir, $out_dir) = @ARGV;

-f "$dir/RELEASE" or die "RELEASE file missing from $dir\n";
-d $out_dir or mkdir($out_dir) or die "Cannot mkdir $out_dir: $!\n";

#
# Info for iso images.
#

my $iso_preparer = 'Robert Olson olson@mcs.anl.gov';
my $iso_app = "SEED";
my $iso_publisher = "The SEED Project";
my $iso_volume_base = "SeedDist";

my $release_info;
{
    local $/;
    undef $/;
    open(R, "<$dir/RELEASE");
    $release_info = <R>;
    close(R);
}

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

my %manifest;

my $total_size = 0;
my @files = ();
while (<M>)
{
    chomp;
    my($cksum, $size, $file) = split(/\s+/);

    $total_size += $size;

    my $b = "$dir/" . basename($file);
    -f $b or die "Cannot find $b\n";
    -s $b == $size or die "File $b has the wrong size\n";

    push(@files, [$file, $size, $cksum]);
    $manifest{$file} = [$size, $cksum, rel2abs($b)];
}
close(M);

my $disk_size = 2_000_000_000;
#my $disk_size = 4_700_000_000;

my $n_disks = POSIX::ceil($total_size / $disk_size);
print "Writing $n_disks disks\n";

#
# @disks contains the disk contents.
#
# Each entry is a tuple [disk-num, disk-size, [files]].
# 
my @disks;

for my $i (0 .. $n_disks - 1)
{
    $disks[$i] = [$i, 0, []];
}

@files = sort { $a->[1] <=> $b->[1] } @files;

my $disk_idx = 0;
while (@files)
{
    my $f = pop(@files);
    my($file, $size, $cksum) = @$f;

    #
    # Put this file onto the next disk in sequence, unless it's full.
    #

    my $start = $disk_idx;
    while (($disks[$disk_idx]->[1] + $size) > $disk_size)
    {
	$disk_idx = ($disk_idx + 1) % $n_disks;
	if ($disk_idx == $start)
	{
	    die "No space left for $file $size on $n_disks disks\n";
	}
    }
    my $d = $disks[$disk_idx];
    
    print "Add $file $size to disk $disk_idx\n";
    push(@{$d->[2]}, $file);
    $d->[1] += $size;
    $disk_idx = ($disk_idx + 1) % $n_disks;
}

my $base = rel2abs($dir);

open(MKISO, ">$out_dir/make_iso_images");
print MKISO <<END;
#!/bin/sh

#
# Script to write ISO images from the disk directories.
#
# Generated by the $0 script.
#

mkisofs=mkisofs

END


for my $disk (@disks)
{
    my($num, $size, $files) = @$disk;
    print "Disk $num size=$size \n";

    $num++;
    
    my $d = "$out_dir/DISK_$num";

    -d $d or mkdir($d) or die "Cannot mkdir $d: $!\n";

    open(MM, ">$d/MANIFEST");
    
    for my $file (@$files)
    {
	my($size, $cksum, $path) = @{$manifest{$file}};

	print "$file: size=$size cksum=$cksum\n";

	print MM "$cksum $size $file\n";

	symlink($path, "$d/$file");
    }
    close(MM);

    open(R, ">$d/README");
    print R <<END;
This is SEED Data Disk $num of $n_disks.

Release information:

-------------------------
$release_info    
-------------------------

Installing a SEED Data Distribution requires first having
installed a SEED Code Distribution disk. If that has been
installed and configured, run this command to load the data
from this disk:

    install-data <path-to-this-disk>
END
    close(R);

    open(D, ">$d/DISK_${num}_OF_${n_disks}");
    close(D);

    open(D, ">$d/RELEASE");
    print D $release_info;
    close(D);

    print MKISO "\$mkisofs -A '$iso_app' -p '$iso_preparer' -P '$iso_publisher' -f -J -R -V ${iso_volume_base}_$num -o disk_$num.iso DISK_$num\n\n";

}
close(MKISO);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3