source: trunk/lib/macros/keep_listed_trees.amc

Last change on this file was 19354, checked in by westram, 2 years ago
  • deny execution.
  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!/usr/bin/perl
2use strict;
3use warnings;
4
5# ------------------------------ configure trees to keep
6
7# simply enter names of trees to remain in the list below.
8my @keep =
9  (
10   'tree_to_keep',
11  );
12
13
14
15# ------------------------------ configure trees to keep [end]
16
17BEGIN {
18  if (not exists $ENV{'ARBHOME'}) { die "Environment variable \$ARBHOME has to be defined"; }
19  my $arbhome = $ENV{'ARBHOME'};
20  push @INC, "$arbhome/lib";
21  push @INC, "$arbhome/PERL_SCRIPTS/lib";
22  1;
23}
24
25use ARB;
26use tools;
27
28my $gb_main = ARB::open(":","r");
29if (not $gb_main) {
30  my $error = ARB::await_error();
31  die "$error";
32}
33
34die "This script will delete most trees from your database.\nTo use, edit it, uncomment this line and save it locally.\nAlso edit list of kept trees to fit your needs.";
35
36# ------------------------------ read existing trees
37
38dieOnError(ARB::begin_transaction($gb_main), 'begin_transaction');
39
40my $gb_trees = ARB::search($gb_main, '/tree_data', 'NONE');
41die 'failed to find tree-data' if not $gb_trees;
42
43my @trees = ();
44
45for (my $gb_sub = ARB::child($gb_trees); $gb_sub; $gb_sub = ARB::nextChild($gb_sub)) { # read all childs
46  my $name = ARB::read_key($gb_sub); # the tree name is "stored" in the key name :-(
47  expectError('read name of tree') if not $name;
48  if (substr($name, 0, 5) eq 'tree_') {
49    push @trees, $name;
50  }
51  else {
52    print "Skipping entry '$name' (not a tree)\n";
53  }
54}
55
56dieOnError(ARB::commit_transaction($gb_main), 'commit_transaction');
57
58my $trees = scalar(@trees);
59BIO::message($gb_main, "Found $trees trees");
60
61# ------------------------------ read existing trees [end]
62# ------------------------------ decide which trees to delete
63
64my %keep = map { $_ => 1; } @keep;
65my @delete = grep { not defined $keep{$_}; } @trees;
66
67my $keep = scalar(@keep);
68my $delete = scalar(@delete);
69BIO::message($gb_main, "Deleting $delete trees ($keep listed as protected)");
70
71# ------------------------------ decide which trees to delete [end]
72
73BIO::remote_action($gb_main,'ARB_NT','tree_admin');
74
75my $count = 0;
76foreach my $treedel (@delete) {
77  ++$count;
78  my $percent = int($count/$delete*100.0);
79  print "Deleting tree $count/$delete ($percent%, '$treedel')\n";
80  BIO::remote_awar($gb_main,'ARB_NT','tmp/ad_tree/tree_name', $treedel);
81  BIO::remote_action($gb_main,'ARB_NT','TREE_ADMIN/DELETE');
82}
83
84BIO::message($gb_main, "$delete unlisted trees have been deleted.");
85BIO::message($gb_main, "Check remaining trees before you overwrite your database.");
86
87# recording stopped @ Sun Dec 26 11:19:28 2021
88ARB::close($gb_main);
Note: See TracBrowser for help on using the repository browser.