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

View of /RAST/make_genome_public.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Tue Jul 29 20:00:13 2008 UTC (11 years, 3 months ago) by wilke
Branch: MAIN
CVS Tags: mgrast_dev_02212011, rast_rel_2014_0912, rast_rel_2010_0928, rast_2008_0924, rast_rel_2008_09_30, rast_rel_2010_0526, rast_rel_2014_0729, rast_rel_2009_05_18, mgrast_rel_2008_0923, rast_rel_2009_0925, rast_rel_2010_1206, rast_rel_2010_0118, mgrast_rel_2008_0924, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, rast_rel_2008_12_18, rast_rel_2008_08_07, mgrast_rel_2008_1110_v2, rast_rel_2008_10_09, rast_release_2008_09_29, mgrast_rel_2008_0806, 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_02222011, rast_rel_2009_03_26, rast_rel_2008_11_24, HEAD
*** empty log message ***

#!/usr/bin/env perl
use strict;
use warnings;
use WebApplication;
#use PPO;
use DBMaster;
use Data::Dumper;
use FIG_Config;
use Getopt::Long;

sub usage {
  print "update_public_scope.pl >>> update the rights of the public scope\n";
  print "update_public_scope.pl -application <application> [-db <database>]\n";
}

# read in parameters
my $application = '';
my $db = "WebAppBackend";
my $dir = '';

GetOptions ( 'application=s' => \$application, 'db=s' => \$db, 'dir=s' => \$dir, );

unless ($application) {
  &usage();
  exit 0;
}

$dir = "/vol/mg-rast-test/jobs/" unless $dir;

my $ids = get_marked_genomes( $dir );

print $dir , "\n";







# initialize db-master
my $dbmaster = DBMaster->new(-database => $db,
			     -host => $FIG_Config::dbhost);
my $backend = $dbmaster->Backend->init( { 'name' => $application } );



unless (ref($backend)) {
  print "Could not retrieve backend $application from database\n";
  exit 0;
}

# check if there is a Public scope, otherwise create it




my $scopes = $dbmaster->Scope->get_objects( { 'name' => 'Public' } );

if (scalar @$scopes != 1){
  print STDERR "Error, no or more than one Public scope\n";
  exit 0;
}

my $scope = $scopes->[0];
 

unless (ref($scope)) {
  print STDERR "Public scope does not exists, creating public scope\n";
  $scope = $dbmaster->Scope->create( { 'name' => 'Public',
				       'description' => 'automatically created public scope' } );
}



# get users and add them to the public scope

# get jobs and IDs

my $ids = get_marked_genomes( $dir );

exit;

foreach my $genome_id (keys %$ids){
  
  grant_right($dbmaster , $genome_id);

}

#check for file 





sub grant_right {
  my ($master , $data_id) = @_;
  
 
  # define right and data type for public genomes
  my $right     = "view";
  my $data_type = "genome";
  my $app       = undef ;
  my $right_target = "group|Public";
 

  unless (defined($right) && defined($data_type) && defined($data_id)) {
    print STDERR 'warning', 'You must select a data type, a right and a data id, aborting.\n';
    return 0;
  }

    


  # determine target scope
  my $scope_object;
  my $scope_object_name = "";
  my ($type, $target) = split(/\|/, $right_target);
  if ($type eq 'group') {
    $scope_object = $master->Scope->get_objects( { name => $target} )->[0];
    $scope_object_name = "group " . $scope_object->name();
  } else {
  
    return 0;
  }

  # check if the right already exists
  my $right_object;
  my $right_objects = $master->Rights->get_objects( { 'application' => $app,
						      'name' => $right,
						      'data_type' => $data_type,
						      'data_id' => $data_id,
						      'scope' => $scope_object } );
  
  # some right exists
  if (scalar(@$right_objects)) {
    $right_objects->[0]->granted(1);
    $right_object = $right_objects->[0];
  } else {
    $right_object = $master->Rights->create( { 'application' => $app,
					       'granted' => 1,
					       'name' => $right,
					       'data_type' => $data_type,
					       'data_id' => $data_id,
					       'scope' => $scope_object } );
  }
  
 
  $right_object->delegated(1);

 
  
  return 1;
}



sub get_marked_genomes{
  my ( $dir ) = @_;
  my $ids = {};



  opendir(DIR, $dir) or die "could not open directory '$dir': $!";
  my @jobs = grep {-f "$dir/$_/ACTIVE"} grep {-f "$dir/$_/PUBLIC"}
    grep {/^\d+$/} readdir(DIR);
  closedir(DIR) or die "could not close directory '$dir': $!";
  

  
  foreach my $job ( sort {$a <=> $b} @jobs )
    {
      my $rp_dir = "$dir/$job/rp";
      
      open(GENOME_ID , "$dir/$job/GENOME_ID") or die "Can't open $dir/$job/GENOME_ID !\n";
      my $id = <GENOME_ID> ;
      chomp $id;
      $ids->{ $id } = 1;
      
    }
  
  print Dumper($ids);
  
  return $ids;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3