Bio-GMOD

 view release on metacpan or  search on metacpan

GMOD/Admin/Update.pm  view on Meta::CPAN

  # print "$install_root $rsync_module $exclude $rsync_path\n";
  my $result = system("rsync -rztpovl $exclude $rsync_path $install_root");
  $self->test_for_error($result,"Rsync'ing the mirror site");
}


#########################################################
# Housecleaning: checking for diskspace, etc
#########################################################
sub check_disk_space {
  my ($self,@p) = @_;
  my ($path,$required,$component) = rearrange([qw/PATH REQUIRED COMPONENT/],@p);
  my ($mount_point,$available) = $self->get_available_space($path); # calculated in GB

  if ($available >= $required) {
    $self->logit(-msg=>"Sufficient space to install $component ($required GB required; $available GB available)");
  } else {
    $self->logit(-msg=>"Insufficient space to install $component ($required GB required; $available GB available)",-die=>1);
  }
  return 1;
}

sub get_available_space {
  my ($self,$path) = @_;
  return unless $path;

  my $cmd = "df -k $path";
  open (IN, "$cmd |") or $self->logit(-msg =>"get_available_space: Cannot run df command ($cmd): $!",-die=>1);

  my ($mount_point, $available_space);
  my $counter;
  while (<IN>) {
    next unless /^\//;
    my ($filesystem, $blocks, $used, $available, $use_percent, $mounted_on) = split(/\s+/);
    $mount_point = $mounted_on;
    $available_space = sprintf("%.2f", $available/1048576);
    $counter++;
  }

  unless ($mount_point && $available_space) { 
    $self->logit("get_available_space: Internal error: Cannot parse df cmd ($cmd)",-die=>1);
  }
  return ($mount_point,$available_space);
}

sub prepare_tmp_dir {
  my ($self,@p)  = @_;
  my ($tmp_path,$sync_to) = rearrange([qw/TMP_PATH SYNC_TO/],@p);
  my $adaptor  = $self->adaptor;
  $adaptor->{defaults}->{tmp_path} = $tmp_path if $tmp_path;

  my $method = $sync_to . "_version";
  my $version  = $self->$method || 'unknown_version';
  $tmp_path ||= $adaptor->tmp_path;
  my $full_path = "$tmp_path/$version";

  unless (-e "$full_path") {
    $self->logit(-msg => "Creating temporary directory at $full_path");
    my $command = <<END;
mkdir -p $full_path
chmod -R 0775 $full_path
END
;
  my $result = system($command);
    if ($result == 0) {
      $self->logit(-msg => "Successfully created temporary directory");
    } else {
      $self->logit(-msg => "Cannot make temporary directory: $!",
		   -die => 1);
    }
  }
  return 1;
}

sub cleanup {
  my ($self,@p) = @_;
  my $tmp = $self->tmp_path;
  $self->logit(-msg => "Cleaning up $tmp");
  system("rm -rf $tmp/*");
}


__END__


=pod

=head1 NAME

Bio::GMOD::Admin::Update - Generics methods for updating a Bio::GMOD installation

=head1 SYNOPSIS

  # Update your Bio::GMOD installation
  use Bio::GMOD::Admin::Update;
  my $mod = Bio::GMOD::Admin::Update->new(-mod => 'WormBase');
  $mod->update(-version => 'WS136');

=head1 DESCRIPTION

Bio::GMOD::Admin::Update contains subroutines that simplify the maintenance
of a Bio::GMOD installation.

=head1 PUBLIC METHODS

=over 4

=item $mod = Bio::GMOD::Admin::Update->new()

The generic new() method is provided by Bio::GMOD.pm.  new() provides
the ability to override system installation paths.  If you have a
default installation for your MOD of interest, this should not be
necessary. You will not normally interact with Bio::GMOD::Admin::Update
objects, but instead with Bio::GMOD::Admin::Update::"MOD" objects.

See Bio::GMOD.pm and Bio::GMOD::Adaptor::* for a full description of
all default paths for your MOD of interest.

=item $mod->update(@options)

update() is a wrapper method that should be overriden by



( run in 1.314 second using v1.01-cache-2.11-cpan-d8267643d1d )