line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PkgForge::Handler::Initialise; # -*-perl-*- |
2
|
1
|
|
|
1
|
|
1640
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# $Id: Initialise.pm.in 15409 2011-01-12 17:25:17Z squinney@INF.ED.AC.UK $ |
6
|
|
|
|
|
|
|
# $Source:$ |
7
|
|
|
|
|
|
|
# $Revision: 15409 $ |
8
|
|
|
|
|
|
|
# $HeadURL: https://svn.lcfg.org/svn/source/tags/PkgForge-Server/PkgForge_Server_1_1_10/lib/PkgForge/Handler/Initialise.pm.in $ |
9
|
|
|
|
|
|
|
# $Date: 2011-01-12 17:25:17 +0000 (Wed, 12 Jan 2011) $ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.1.10'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
4
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
14
|
1
|
|
|
1
|
|
457
|
use File::Path (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
19
|
|
15
|
1
|
|
|
1
|
|
5
|
use File::Spec (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
13
|
|
16
|
1
|
|
|
1
|
|
407
|
use PkgForge::Utils (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Moose; |
19
|
|
|
|
|
|
|
use MooseX::Types::Moose qw(Bool); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
extends 'PkgForge::Handler'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'zap' => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => Bool, |
26
|
|
|
|
|
|
|
default => 0, |
27
|
|
|
|
|
|
|
documentation => 'Delete existing directory contents', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
no Moose; |
31
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub execute { |
34
|
|
|
|
|
|
|
my ($self) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Before anything else we MUST ensure that the log directory exists. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $logdir = $self->logdir; |
39
|
|
|
|
|
|
|
if ( !-d $logdir ) { |
40
|
|
|
|
|
|
|
my $created = eval { File::Path::mkpath($logdir) }; |
41
|
|
|
|
|
|
|
if ( $EVAL_ERROR || $created == 0 ) { |
42
|
|
|
|
|
|
|
$self->logger->log_and_die( level => 'critical', |
43
|
|
|
|
|
|
|
message => "Failed to create $logdir: $EVAL_ERROR" ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$self->logger->info('Initialising server environment'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
for my $attr ( $self->meta->get_all_attributes ) { |
50
|
|
|
|
|
|
|
if ( !$attr->does('PkgForge::Meta::Attribute::Trait::Directory') ) { |
51
|
|
|
|
|
|
|
next; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $dir = $attr->get_value($self); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if ( -d $dir && $self->zap ) { |
57
|
|
|
|
|
|
|
$self->logger->info("Wiping directory $dir"); |
58
|
|
|
|
|
|
|
my ( @errors, @results ); |
59
|
|
|
|
|
|
|
my $options = { error => \@errors, keep_root => 1 }; |
60
|
|
|
|
|
|
|
if ( $self->debug ) { |
61
|
|
|
|
|
|
|
$options->{result} = \@results; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
PkgForge::Utils::remove_tree($dir, $options); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
if ( $self->debug ) { |
67
|
|
|
|
|
|
|
$self->logger->debug("Removed @results"); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
if ( scalar @errors > 1 ) { |
71
|
|
|
|
|
|
|
$self->logger->log_and_die( level => 'critical', |
72
|
|
|
|
|
|
|
message => "Failed to wipe $dir: @errors" ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
if ( !-d $dir ) { |
77
|
|
|
|
|
|
|
$self->logger->info("Creating directory $dir"); |
78
|
|
|
|
|
|
|
my $created = eval { File::Path::mkpath($dir) }; |
79
|
|
|
|
|
|
|
if ( $EVAL_ERROR || $created == 0 ) { |
80
|
|
|
|
|
|
|
$self->logger->log_and_die( level => 'critical', |
81
|
|
|
|
|
|
|
message => "Failed to create $dir: $EVAL_ERROR" ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
PkgForge::Handler::Initialise - Package Forge class for initialising the server |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 VERSION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This documentation refers to PkgForge::Handler::Initialise version 1.1.10 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SYNOPSIS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
use PkgForge::Handler::Initialise (); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $init = PkgForge::Handler::Initialise->new_with_config(); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$init->execute; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 DESCRIPTION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This class provides a method for initialising the Package Forge |
111
|
|
|
|
|
|
|
server. It creates any necessary directories and, optionally, wipes |
112
|
|
|
|
|
|
|
them to return them to a pristine starting position. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This class inherits from L<PkgForge::Handler>, see the documentation |
117
|
|
|
|
|
|
|
for that module for full details of inherited attributes. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item zap |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Controls whether the contents of Package Forge directories which |
124
|
|
|
|
|
|
|
already exist should be wiped. Defaults to false. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item configfile |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This is inherited from L<MooseX::ConfigFromFile> (via |
129
|
|
|
|
|
|
|
L<PkgForge::ConfigFile>), if specified it can be used to initialise |
130
|
|
|
|
|
|
|
the class via the C<new_with_config> method. It can be a string or a |
131
|
|
|
|
|
|
|
list of strings, each file should be a YAML file, see |
132
|
|
|
|
|
|
|
L<PkgForge::ConfigFile> for details. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item debug |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
A boolean value to control whether or not debugging messages are |
137
|
|
|
|
|
|
|
logged. The default is false. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item incoming |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The directory into which incoming package forge jobs will be |
142
|
|
|
|
|
|
|
submitted. The default is C</var/lib/pkgforge/incoming> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item accepted |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
The directory into which package forge jobs will be transferred if |
147
|
|
|
|
|
|
|
they are accepted as valid. The default is C</var/lib/pkgforge/accepted> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item results |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The directory into which the results of finished package forge jobs |
152
|
|
|
|
|
|
|
will be stored. The default is C</var/lib/pkgforge/results>. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item logdir |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
The directory into which log files will be stored by default. You can |
157
|
|
|
|
|
|
|
override the path to a log file to have any absolute path you wish so |
158
|
|
|
|
|
|
|
this attribute may have no effect on the log file used. The default is |
159
|
|
|
|
|
|
|
C</var/log/pkgforge>. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item logfile |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
The file into which messages will be logged. The default value is |
164
|
|
|
|
|
|
|
C<default.log> within the directory specified in the C<logdir> |
165
|
|
|
|
|
|
|
attribute. You probably want a different log file for each handler. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item logger |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
This is the logger object, you can call methods such as C<debug> and |
170
|
|
|
|
|
|
|
C<error> on this object to log messages. See L<Log::Dispatch> and |
171
|
|
|
|
|
|
|
L<Log::Dispatch::Config> for full details. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=back |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This class inherits from L<PkgForge::Handler>, see the documentation |
178
|
|
|
|
|
|
|
for that module for full details of inherited methods. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=over |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item new_with_config |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This uses L<PkgForge::ConfigFile>, which in turn uses |
185
|
|
|
|
|
|
|
L<MooseX::ConfigFromFile>, to set the attributes for the module from |
186
|
|
|
|
|
|
|
configuration files. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item execute |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This method does the actual work of initialising the Package Forge |
191
|
|
|
|
|
|
|
server environment. It will create the required directories if they do |
192
|
|
|
|
|
|
|
not exist. If the C<zap> attribute has been set to true then it will |
193
|
|
|
|
|
|
|
also wipe the contents of the directories if they already exist. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=back |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This module is powered by L<Moose> and uses L<MooseX::ConfigFromFile> |
200
|
|
|
|
|
|
|
and L<MooseX::Types>. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 SEE ALSO |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L<PkgForge>, L<PkgForge::Handler>, L<PkgForge::Utils> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 PLATFORMS |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
This is the list of platforms on which we have tested this |
209
|
|
|
|
|
|
|
software. We expect this software to work on any Unix-like platform |
210
|
|
|
|
|
|
|
which is supported by Perl. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
ScientificLinux5, Fedora13 |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Please report any bugs or problems (or praise!) to bugs@lcfg.org, |
217
|
|
|
|
|
|
|
feedback and patches are also always very welcome. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 AUTHOR |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Stephen Quinney <squinney@inf.ed.ac.uk> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Copyright (C) 2010-2011 University of Edinburgh. All rights reserved. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
228
|
|
|
|
|
|
|
it under the terms of the GPL, version 2 or later. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
231
|
|
|
|
|
|
|
|