~ubuntu-branches/ubuntu/raring/octopussy/raring

« back to all changes in this revision

Viewing changes to usr/sbin/octo_tool

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-09-25 10:27:37 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120925102737-1hgntjl557w3sjqh
Tags: 1.0.6-0ubuntu1
* New upstream release (LP: #1056016).
* d/control: bumped Standards-Version: 3.9.3, no changes.
* d/{copyright,control}: Updated upstream URL.
* d/README.Debian: Fixed minor typo.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
=head1 NAME
 
4
 
 
5
octo_tool - Octopussy tool to do simple tasks
 
6
 
 
7
=head1 DESCRIPTION
 
8
 
 
9
octo_tool backup - Backups Octopussy configuration
 
10
octo_tool cache_clear - Clears Cache (msgid_stats or taxonomy_stats)
 
11
octo_tool message_copy - Copies Message from a Service to another Service
 
12
octo_tool message_move - Moves Message from a Service to another Service
 
13
octo_tool service_clone - Clones a Service
 
14
octo_tool table_clone - Clones a Table
 
15
 
 
16
=head1 SYNOPSIS
 
17
 
 
18
octo_tool <task> [options]
 
19
 
 
20
octo_tool backup <filename>
 
21
 
 
22
octo_tool cache_clear msgid_stats|taxonomy_stats
 
23
 
 
24
octo_tool message_copy <msgid_src> <msg_dst>
 
25
 
 
26
octo_tool message_move <msgid_src> <msg_dst>
 
27
 
 
28
octo_tool service_clone <servicename> <cloned_servicename>
 
29
 
 
30
octo_tool table_clone <tablename> <cloned_tablename>
 
31
 
 
32
=head1 OPTIONS
 
33
 
 
34
=over 4
 
35
 
 
36
=item B<-h,--help>
 
37
 
 
38
Prints this help.
 
39
 
 
40
=item B<-v,--version>
 
41
 
 
42
Prints version.
 
43
 
 
44
=back
 
45
 
 
46
=cut
 
47
 
 
48
use strict;
 
49
use warnings;
 
50
 
 
51
use Getopt::Long;
 
52
use Pod::Usage;
 
53
use POSIX qw(strftime);
 
54
 
 
55
use Octopussy::Cache;
 
56
use Octopussy::Configuration;
 
57
use Octopussy::Service;
 
58
use Octopussy::Table;
 
59
 
 
60
my $VERSION = '0.6';
 
61
 
 
62
my %option = ();
 
63
my %task = (
 
64
        backup => \&Backup,
 
65
        cache_clear => \&Cache_Clear,
 
66
        message_copy => \&Message_Copy,
 
67
        message_move => \&Message_Move,
 
68
        service_clone => \&Service_Clone,
 
69
        table_clone => \&Table_Clone,
 
70
        );
 
71
 
 
72
my $status = GetOptions(
 
73
        'h|help|?'      => \$option{help},
 
74
        'v|version' => sub { printf "octo_tool $VERSION\n"; exit; }
 
75
        );
 
76
 
 
77
=head1 FUNCTIONS
 
78
 
 
79
=head2 Usage($msg)
 
80
 
 
81
Prints Script Usage
 
82
 
 
83
=cut
 
84
 
 
85
sub Usage
 
86
{
 
87
        my $msg = shift;
 
88
 
 
89
        if (defined $msg)
 
90
        {
 
91
                pod2usage(-verbose => 99, -sections => [ qw(SYNOPSIS OPTIONS) ], 
 
92
                        -message => "\n$msg\n");
 
93
        }
 
94
        else
 
95
        {
 
96
                pod2usage(-verbose => 99, -sections => [ qw(SYNOPSIS OPTIONS) ]);
 
97
        }
 
98
}
 
99
 
 
100
=head2 Backup($filename)
 
101
 
 
102
Backups Octopussy configuration
 
103
 
 
104
=cut
 
105
 
 
106
sub Backup
 
107
{
 
108
        my $filename = shift;
 
109
 
 
110
        my $timestamp   = strftime("%Y%m%d%H%M%S", localtime);
 
111
        $filename .= ($filename !~ /\.tgz$/ ? "_${timestamp}.tgz" : '');
 
112
        Octopussy::Configuration::Backup($filename);
 
113
}
 
114
 
 
115
=head2 Cache_Clear($cache_name)
 
116
 
 
117
Clears Cache 'msgid_stats' or 'taxonomy_stats'
 
118
 
 
119
=cut
 
120
 
 
121
sub Cache_Clear
 
122
{
 
123
        my $cache_name = shift;
 
124
 
 
125
        Usage('[ERROR] Invalid number of args.')    if (!defined $cache_name);
 
126
 
 
127
        if ($cache_name eq 'msgid_stats')
 
128
        {
 
129
                Octopussy::Cache::Clear_MsgID_Stats();
 
130
        }
 
131
        elsif ($cache_name eq 'taxonomy_stats')
 
132
        {
 
133
                Octopussy::Cache::Clear_Taxonomy_Stats();
 
134
        }
 
135
}
 
136
 
 
137
=head2 Message_Copy($msgid_src, $msgid_dst)
 
138
 
 
139
Copies Message 'msgid_src' to Message 'msgid_dst'
 
140
 
 
141
=cut
 
142
 
 
143
sub Message_Copy
 
144
{
 
145
        my ($msgid_src, $msgid_dst) = @_;
 
146
 
 
147
        Usage('[ERROR] Invalid number of args.')    if (!defined $msgid_dst);
 
148
 
 
149
        Octopussy::Service::Copy_Message($msgid_src, $msgid_dst);
 
150
}
 
151
 
 
152
=head2 Message_Move($msgid_src, $msgid_dst)
 
153
 
 
154
Moves Message 'msgid_src' to Message 'msgid_dst'
 
155
 
 
156
=cut
 
157
 
 
158
sub Message_Move
 
159
{
 
160
    my ($msgid_src, $msgid_dst) = @_;
 
161
 
 
162
    Usage('[ERROR] Invalid number of args.')    if (!defined $msgid_dst);
 
163
 
 
164
    my $nb_errors = Octopussy::Service::Copy_Message($msgid_src, $msgid_dst);
 
165
        if ($nb_errors == 0)
 
166
        {
 
167
                my ($serv_src) = $msgid_src =~ /^(.+):.+$/;
 
168
                Octopussy::Service::Remove_Message($serv_src, $msgid_src);
 
169
        }
 
170
}
 
171
 
 
172
=head2 Service_Clone($service_orig, $service_clone)
 
173
 
 
174
Clones Service '$service_orig' in '$service_clone'
 
175
 
 
176
=cut
 
177
 
 
178
sub Service_Clone
 
179
{
 
180
        my ($service_orig, $service_clone) = @_;
 
181
 
 
182
        Usage('[ERROR] Invalid number of args.')        if (!defined $service_clone);
 
183
 
 
184
        my $service_orig_filename = Octopussy::Service::Filename($service_orig);
 
185
        my $service_clone_filename = Octopussy::Service::Filename($service_clone);
 
186
        Usage("[ERROR] Service '$service_orig' doesn't exist !")
 
187
                if (!-f $service_orig_filename);
 
188
        Usage("[ERROR] Service '$service_clone' already exists !")
 
189
        if ((defined $service_clone_filename) && (-f $service_clone_filename));
 
190
 
 
191
        Octopussy::Service::Clone($service_orig, $service_clone);
 
192
}
 
193
 
 
194
=head2 Table_Clone($table_orig, $table_clone)
 
195
 
 
196
Clones Table '$table_orig' in '$table_clone'
 
197
 
 
198
=cut
 
199
 
 
200
sub Table_Clone
 
201
{
 
202
        my ($table_orig, $table_clone) = @_;
 
203
 
 
204
    Usage('[ERROR] Invalid number of args.')    if (!defined $table_clone);
 
205
 
 
206
    my $table_orig_filename = Octopussy::Table::Filename($table_orig);
 
207
    my $table_clone_filename = Octopussy::Table::Filename($table_clone);
 
208
    Usage("[ERROR] Table '$table_orig' doesn't exist !")
 
209
        if (!-f $table_orig_filename);
 
210
    Usage("[ERROR] Table '$table_clone' already exists !")
 
211
        if ((defined $table_clone_filename) && (-f $table_clone_filename));
 
212
        Octopussy::Table::Clone($table_orig, $table_clone);
 
213
}
 
214
 
 
215
 
 
216
Usage() if ($option{help});
 
217
Usage('[ERROR] No task specified.')     if (@ARGV < 1);
 
218
 
 
219
my $t = $ARGV[0];
 
220
my @args = @ARGV;
 
221
shift @args;
 
222
 
 
223
$task{$t}(@args)        if (defined $task{$t});