Bio-GMOD

 view release on metacpan or  search on metacpan

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

    if ($is_optional) {
      $self->logit(-msg => "$remote_path failed to download, installation is optional: $!");
    } else {
      $self->logit(-msg         => "$remote_path failed to download: $!",
		   -die         => 1);
    }
  }
  return 1;
}



#########################################################
# Rsync tasks
#########################################################
sub rsync_software {
  my ($self,@p) = @_;
  my ($rsync_module,$exclude,$install_root) = rearrange([qw/MODULE EXCLUDE INSTALL_ROOT/],@p);
  $self->logit(-msg=>"Rsync'ing software",-emphasis=>1);
  my $adaptor     = $self->adaptor;
  $adaptor->parse_params(@p);
  $install_root ||= $adaptor->install_root;
  $rsync_module .= '/' unless ($rsync_module =~ /\/$/);  # Add trailing slash

  my $rsync_url   = $adaptor->rsync_url;
  $rsync_module ||= $adaptor->rsync_module;
  my $rsync_path   = $rsync_url . ($rsync_module ? "/$rsync_module" : '');
  # 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



( run in 2.974 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )