Imported Upstream version 3.3.3
[debian/amanda] / perl / Amanda / Cmdline.pm
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 2.0.4
3 #
4 # Do not make changes to this file unless you know what you are doing--modify
5 # the SWIG interface file instead.
6
7 package Amanda::Cmdline;
8 use base qw(Exporter);
9 use base qw(DynaLoader);
10 package Amanda::Cmdlinec;
11 bootstrap Amanda::Cmdline;
12 package Amanda::Cmdline;
13 @EXPORT = qw();
14
15 # ---------- BASE METHODS -------------
16
17 package Amanda::Cmdline;
18
19 sub TIEHASH {
20     my ($classname,$obj) = @_;
21     return bless $obj, $classname;
22 }
23
24 sub CLEAR { }
25
26 sub FIRSTKEY { }
27
28 sub NEXTKEY { }
29
30 sub FETCH {
31     my ($self,$field) = @_;
32     my $member_func = "swig_${field}_get";
33     $self->$member_func();
34 }
35
36 sub STORE {
37     my ($self,$field,$newval) = @_;
38     my $member_func = "swig_${field}_set";
39     $self->$member_func($newval);
40 }
41
42 sub this {
43     my $ptr = shift;
44     return tied(%$ptr);
45 }
46
47
48 # ------- FUNCTION WRAPPERS --------
49
50 package Amanda::Cmdline;
51
52 *format_dumpspec_components = *Amanda::Cmdlinec::format_dumpspec_components;
53 *parse_dumpspecs = *Amanda::Cmdlinec::parse_dumpspecs;
54 *header_matches_dumpspecs = *Amanda::Cmdlinec::header_matches_dumpspecs;
55
56 ############# Class : Amanda::Cmdline::dumpspec_t ##############
57
58 package Amanda::Cmdline::dumpspec_t;
59 use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
60 @ISA = qw( Amanda::Cmdline );
61 %OWNER = ();
62 %ITERATORS = ();
63 *swig_host_get = *Amanda::Cmdlinec::dumpspec_t_host_get;
64 *swig_host_set = *Amanda::Cmdlinec::dumpspec_t_host_set;
65 *swig_disk_get = *Amanda::Cmdlinec::dumpspec_t_disk_get;
66 *swig_disk_set = *Amanda::Cmdlinec::dumpspec_t_disk_set;
67 *swig_datestamp_get = *Amanda::Cmdlinec::dumpspec_t_datestamp_get;
68 *swig_datestamp_set = *Amanda::Cmdlinec::dumpspec_t_datestamp_set;
69 *swig_level_get = *Amanda::Cmdlinec::dumpspec_t_level_get;
70 *swig_level_set = *Amanda::Cmdlinec::dumpspec_t_level_set;
71 *swig_write_timestamp_get = *Amanda::Cmdlinec::dumpspec_t_write_timestamp_get;
72 *swig_write_timestamp_set = *Amanda::Cmdlinec::dumpspec_t_write_timestamp_set;
73 sub new {
74     my $pkg = shift;
75     my $self = Amanda::Cmdlinec::new_dumpspec_t(@_);
76     bless $self, $pkg if defined($self);
77 }
78
79 sub DESTROY {
80     return unless $_[0]->isa('HASH');
81     my $self = tied(%{$_[0]});
82     return unless defined $self;
83     delete $ITERATORS{$self};
84     if (exists $OWNER{$self}) {
85         Amanda::Cmdlinec::delete_dumpspec_t($self);
86         delete $OWNER{$self};
87     }
88 }
89
90 *format = *Amanda::Cmdlinec::dumpspec_t_format;
91 sub DISOWN {
92     my $self = shift;
93     my $ptr = tied(%$self);
94     delete $OWNER{$ptr};
95 }
96
97 sub ACQUIRE {
98     my $self = shift;
99     my $ptr = tied(%$self);
100     $OWNER{$ptr} = 1;
101 }
102
103
104 # ------- VARIABLE STUBS --------
105
106 package Amanda::Cmdline;
107
108 *CMDLINE_PARSE_DATESTAMP = *Amanda::Cmdlinec::CMDLINE_PARSE_DATESTAMP;
109 *CMDLINE_PARSE_LEVEL = *Amanda::Cmdlinec::CMDLINE_PARSE_LEVEL;
110 *CMDLINE_EMPTY_TO_WILDCARD = *Amanda::Cmdlinec::CMDLINE_EMPTY_TO_WILDCARD;
111 *CMDLINE_EXACT_MATCH = *Amanda::Cmdlinec::CMDLINE_EXACT_MATCH;
112
113 @EXPORT_OK = ();
114 %EXPORT_TAGS = ();
115
116
117 =head1 NAME
118
119 Amanda::Cmdline - utilities for handling command lines
120
121 =head1 SYNOPSIS
122
123   use Amanda::Cmdline;
124
125   my $spec = Amanda::Cmdline::dumpspec_t->new($host, $disk, $datestamp, $level, $write_timestamp);
126   print "host: $spec->{'host'}; disk: $spec->{'disk'}\n";
127
128   my @specs = Amanda::Cmdline::parse_dumpspecs(["host", "disk", "date"],
129                             $Amanda::Cmdline::CMDLINE_PARSE_DATESTAMP);
130
131 =head1 Amanda::Cmdline::dumpspec_t Objects
132
133 Note that this class was called C<Amanda::Cmdline::dumpspec_t> in older versions;
134 that name will still work, but is deprecated.
135
136 =head2 Keys
137
138 Each key contains a match expression, in the form of a string, or undef.  Note
139 that the values of these keys are read-only.
140
141 =over
142
143 =item C<< $ds->{'host'} >>
144
145 Hostname
146
147 =item C<< $ds->{'disk'} >>
148
149 Disk name
150
151 =item C<< $ds->{'datestamp'} >>
152
153 Dump timestamp.
154
155 =item C<< $ds->{'level'} >>
156
157 Dump level
158
159 =item C<< $ds->{'write_timestamp'} >>
160
161 Timestamp when the dump is written to storage media.
162
163 =back
164
165 =head2 Methods
166
167 =over
168
169 =item C<< $ds->format() >>
170
171 Format the dumpspec as a string.
172
173 =back
174
175 =head1 Package Functions
176
177 =over
178
179 =item C<format_dumpspec_components($host, $disk, $datestamp, $level)>
180
181 This function returns a string representing the formatted form of the
182 given dumpspec.  This formatting is the same as performed by
183 C<< $ds->format() >>, but does not need a C<Dumpspec>.
184
185 =item C<parse_dumpspecs([@cmdline], $flags)>
186
187 This function parses C<@cmdline> into a list of C<Dumpspec> objects,
188 according to C<$flags>, which is a logical combination of zero or more
189 of
190
191  $CMDLINE_PARSE_DATESTAMP - recognize datestamps
192  $CMDLINE_PARSE_LEVEL - recognize levels
193  $CMDLINE_EMPTY_TO_WILDCARD - if @cmdline is empty, make a wildcard dumpspec
194
195 These constants are available in export tag C<:constants>.  The command-line
196 format is
197
198   [host [disk [datestamp [level [host [..]]]]]]
199
200 Note that there is no facility for specifying C<write_timestamp> on the command
201 line.
202
203 =item C<header_matches_dumpspecs($hdr, [@dumpspecs])>
204
205 This function compares a header to a list of dumpspecs, returning true if the
206 header matches at least one dumpspec.  If C<@dumpspecs> is empty, the function
207 returns false.
208
209 =back
210
211 =head1 SEE ALSO
212
213 L<Amanda::Config> handles C<-o> options itself, through
214 C<config_overrides>.
215
216 =cut
217
218
219
220 push @EXPORT_OK, qw(cmdline_parse_dumpspecs_flags_to_strings);
221 push @{$EXPORT_TAGS{"cmdline_parse_dumpspecs_flags"}}, qw(cmdline_parse_dumpspecs_flags_to_strings);
222
223 my %_cmdline_parse_dumpspecs_flags_VALUES;
224 #Convert a flag value to a list of names for flags that are set.
225 sub cmdline_parse_dumpspecs_flags_to_strings {
226     my ($flags) = @_;
227     my @result = ();
228
229     for my $k (keys %_cmdline_parse_dumpspecs_flags_VALUES) {
230         my $v = $_cmdline_parse_dumpspecs_flags_VALUES{$k};
231
232         #is this a matching flag?
233         if (($v == 0 && $flags == 0) || ($v != 0 && ($flags & $v) == $v)) {
234             push @result, $k;
235         }
236     }
237
238 #by default, just return the number as a 1-element list
239     if (!@result) {
240         return ($flags);
241     }
242
243     return @result;
244 }
245
246 push @EXPORT_OK, qw($CMDLINE_PARSE_DATESTAMP);
247 push @{$EXPORT_TAGS{"cmdline_parse_dumpspecs_flags"}}, qw($CMDLINE_PARSE_DATESTAMP);
248
249 $_cmdline_parse_dumpspecs_flags_VALUES{"CMDLINE_PARSE_DATESTAMP"} = $CMDLINE_PARSE_DATESTAMP;
250
251 push @EXPORT_OK, qw($CMDLINE_PARSE_LEVEL);
252 push @{$EXPORT_TAGS{"cmdline_parse_dumpspecs_flags"}}, qw($CMDLINE_PARSE_LEVEL);
253
254 $_cmdline_parse_dumpspecs_flags_VALUES{"CMDLINE_PARSE_LEVEL"} = $CMDLINE_PARSE_LEVEL;
255
256 push @EXPORT_OK, qw($CMDLINE_EMPTY_TO_WILDCARD);
257 push @{$EXPORT_TAGS{"cmdline_parse_dumpspecs_flags"}}, qw($CMDLINE_EMPTY_TO_WILDCARD);
258
259 $_cmdline_parse_dumpspecs_flags_VALUES{"CMDLINE_EMPTY_TO_WILDCARD"} = $CMDLINE_EMPTY_TO_WILDCARD;
260
261 push @EXPORT_OK, qw($CMDLINE_EXACT_MATCH);
262 push @{$EXPORT_TAGS{"cmdline_parse_dumpspecs_flags"}}, qw($CMDLINE_EXACT_MATCH);
263
264 $_cmdline_parse_dumpspecs_flags_VALUES{"CMDLINE_EXACT_MATCH"} = $CMDLINE_EXACT_MATCH;
265
266 #copy symbols in cmdline_parse_dumpspecs_flags to constants
267 push @{$EXPORT_TAGS{"constants"}},  @{$EXPORT_TAGS{"cmdline_parse_dumpspecs_flags"}};
268
269 push @EXPORT_OK, qw(header_matches_dumpspecs parse_dumpspecs format_dumpspec_components);
270 1;