Imported Upstream version 3.2.0
[debian/amanda] / perl / Amanda / Script.pm
1 # vim:ft=perl
2 # Copyright (c) 2008,2009 Zmanda, Inc.  All Rights Reserved.
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19
20 package Amanda::Script;
21 use base qw(Amanda::Script_App);
22
23 use strict;
24 use warnings;
25
26 =head1 NAME
27
28 Amanda::Script - perl utility functions for Scripts.
29
30 =head1 SYNOPSIS
31
32   package Amanda::Script::my_script;
33   use base qw(Amanda::Script);
34
35   sub new {
36     my $class = shift;
37     my ($execute_where, $foo, $bar) = @_;
38     my $self = $class->SUPER::new($execute_where);
39     $self->{'execute_where'} = $execute_where;
40     $self->{'foo'} = $foo;
41     $self->{'bar'} = $bar;
42
43     return $self;
44   }
45
46   # Define all command_* subs that you need, e.g.,
47   sub command_pre_dle_amcheck {
48     my $self = shift;
49     # ...
50   }
51
52   package main;
53
54   # .. parse arguments ..
55   my $script = Amanda::Script::my_script->new($opt_execute_where, $opt_foo, $opt_bar);
56   $script->do($cmd);
57
58 =cut
59
60 sub new {
61     my $class = shift;
62     my ($execute_where, $config_name) = @_;
63
64     my $self = Amanda::Script_App::new($class, $execute_where, "script", $config_name);
65
66     $self->{known_commands} = {
67         support             => 1,
68         pre_dle_amcheck     => 1,
69         pre_host_amcheck    => 1,
70         post_dle_amcheck    => 1,
71         post_host_amcheck   => 1,
72         pre_dle_estimate    => 1,
73         pre_host_estimate   => 1,
74         post_dle_estimate   => 1,
75         post_host_estimate  => 1,
76         pre_dle_backup      => 1,
77         pre_host_backup     => 1,
78         post_dle_backup     => 1,
79         post_host_backup    => 1,
80         pre_recover         => 1,
81         post_recover        => 1,
82         pre_level_recover   => 1,
83         post_level_recover  => 1,
84         inter_level_recover => 1,
85     };
86     return $self;
87 }
88
89 sub _set_mesgout {
90     my $self = shift;
91
92     my $mesgout_fd;
93     open ($mesgout_fd, '>&=1') || die("Can't open mesgout_fd: $!");
94     $self->{mesgout} = $mesgout_fd;
95 }
96
97 1;