source: gs2-extensions/parallel-building/trunk/src/bin/script/rm_archives.pl@ 29662

Last change on this file since 29662 was 29662, checked in by jmt12, 9 years ago

Now removes building and index directories if found

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Unix::Getrusage;
7
8if (!defined($ENV{'GSDLHOME'}))
9{
10 print STDERR "Error! GSDLHOME not in environment (have you sourced setup.bash?)\n";
11 exit(0);
12}
13
14if (!defined($ARGV[0]))
15{
16 print STDERR "Usage: rm_archives.pl <collection name> [<debug>]\n";
17 exit(0);
18}
19
20# Clean up command...
21my $cmd = 'rm -rf ';
22my $del_count = 0;
23
24# Check the archives directory as a priority
25my $archives_dir = $ENV{'GSDLHOME'} . '/collect/' . $ARGV[0] . '/archives';
26if (-d $archives_dir)
27{
28 $cmd .= ' "' . $archives_dir . '"';
29 $del_count++;
30}
31
32# Cache dir too for video or other caching plugins
33my $cached_dir = $ENV{'GSDLHOME'} . '/collect/' . $ARGV[0] . '/cached';
34if (-d $cached_dir)
35{
36 $cmd .= ' "' . $cached_dir . '"';
37 $del_count++;
38}
39
40# There may also be a logs directory we'll nuke, for clarity sake
41my $logs_dir = $ENV{'GSDLHOME'} . '/collect/' . $ARGV[0] . '/logs';
42if (-d $logs_dir)
43{
44 $cmd .= ' "' . $logs_dir . '"';
45 $del_count++;
46}
47
48
49# Index dirs too!
50my $building_dir = $ENV{'GSDLHOME'} . '/collect/' . $ARGV[0] . '/building';
51if (-d $building_dir)
52{
53 $cmd .= ' "' . $building_dir . '"';
54 $del_count++;
55}
56my $index_dir = $ENV{'GSDLHOME'} . '/collect/' . $ARGV[0] . '/index';
57if (-d $index_dir)
58{
59 $cmd .= ' "' . $index_dir . '"';
60 $del_count++;
61}
62
63# Now run the built up command (assuming we found something to delete)
64if ($del_count > 0)
65{
66 if (defined ($ARGV[1]))
67 {
68 print "CMD: " . $cmd . "\n";
69 }
70 `$cmd`;
71}
72else
73{
74 print "Warning - no previous archives found: " . $archives_dir . "\n";
75}
76
77# Write out timing statistics
78if (defined ($ARGV[1]))
79{
80 my $rusage_struct = getrusage();
81 my $rusage_children_struct = getrusage_children();
82 print "\n";
83 print "*************************************************\n";
84 print "DEBUG: Script Timing/Usage for rm_archives.pl\n";
85 print "*************************************************\n";
86 my $rusage_fields = {'user time used'=>'ru_utime',
87 'system time used'=>'ru_stime',
88 'maximum resident set size'=>'ru_maxrss',
89 'integral shared memory size'=>'ru_ixrss',
90 'integral unshared data size'=>'ru_idrss',
91 'integral unshared stack size'=>'ru_isrss',
92 'page reclaims'=>'ru_minflt',
93 'page faults'=>'ru_majflt',
94 'swaps'=>'ru_nswap',
95 'block input operations'=>'ru_inblock',
96 'block output operations'=>'ru_oublock',
97 'messages sent'=>'ru_msgsnd',
98 'messages received'=>'ru_msgrcv',
99 'signals received'=>'ru_nsignals',
100 'voluntary context switches'=>'ru_nvcsw',
101 'involuntary context switches'=>'ru_nivcsw'};
102 foreach my $rusage_title (sort keys %{$rusage_fields})
103 {
104 my $rusage_field = $rusage_fields->{$rusage_title};
105 my $total = $rusage_struct->{$rusage_field} + $rusage_children_struct->{$rusage_field};
106 print ' * ' . sprintf("%-30s", ucfirst($rusage_title) . ': ') . $total . "\n";
107 }
108 print "*************************************************\n";
109 print "\n";
110}
111
112exit(0);
Note: See TracBrowser for help on using the repository browser.