1 | # ------------------------------------------------------------------------------ |
---|
2 | # (C) Crown copyright Met Office. All rights reserved. |
---|
3 | # For further details please refer to the file COPYRIGHT.txt |
---|
4 | # which you should have received as part of this distribution. |
---|
5 | # ------------------------------------------------------------------------------ |
---|
6 | |
---|
7 | use strict; |
---|
8 | use warnings; |
---|
9 | |
---|
10 | package FCM::Admin::Config; |
---|
11 | |
---|
12 | use File::Spec; |
---|
13 | |
---|
14 | my $USER = (getpwuid($<))[0]; |
---|
15 | my $HOME = (getpwuid($<))[7]; |
---|
16 | my $LOCALDATA = File::Spec->catfile(q{/project/local}, $USER); |
---|
17 | |
---|
18 | # Default values for read-only attributes |
---|
19 | my %DEFAULT_R = ( |
---|
20 | admin_email => q{fcm@metoffice.gov.uk}, |
---|
21 | fcm_home => $HOME, |
---|
22 | fcm_dist_on_desktops => q{/project/ukmo/utils/supported/portable}, |
---|
23 | fcm_dist_on_HPCs => ['hpc1f:FCM/work/FCM/'], |
---|
24 | fcm_wc => File::Spec->catfile($HOME, qw{FCM work FCM}), |
---|
25 | fcm_admin_wc => File::Spec->catfile($HOME, qw{FCM work Admin}), |
---|
26 | trac_gid => scalar(getgrnam(q{apache})), |
---|
27 | user_number_min => 500, |
---|
28 | ); |
---|
29 | |
---|
30 | # Default values for read-write attributes |
---|
31 | my %DEFAULT_RW = ( |
---|
32 | svn_backup_dir => File::Spec->catfile($HOME, qw{svn backups}), |
---|
33 | svn_dump_dir => File::Spec->catfile($HOME, qw{svn dumps}), |
---|
34 | svn_hook_dir => File::Spec->catfile($HOME, qw{FCM work Admin svn-hooks}), |
---|
35 | svn_live_dir => File::Spec->catfile($LOCALDATA, qw{svn live}), |
---|
36 | svn_passwd_file => q{passwd}, |
---|
37 | svn_project_suffix => q{_svn}, |
---|
38 | trac_backup_dir => File::Spec->catfile($HOME, qw{trac backups}), |
---|
39 | trac_live_dir => File::Spec->catfile($LOCALDATA, qw{trac live}), |
---|
40 | trac_ini_file => q{trac.ini}, |
---|
41 | trac_passwd_file => q{trac.htpasswd}, |
---|
42 | ); |
---|
43 | |
---|
44 | my $INSTANCE; |
---|
45 | |
---|
46 | # ------------------------------------------------------------------------------ |
---|
47 | # Returns a unique instance of this class. |
---|
48 | sub instance { |
---|
49 | my ($class) = @_; |
---|
50 | if (!$INSTANCE) { |
---|
51 | $INSTANCE = bless({%DEFAULT_R, %DEFAULT_RW}, $class); |
---|
52 | } |
---|
53 | return $INSTANCE; |
---|
54 | } |
---|
55 | |
---|
56 | # ------------------------------------------------------------------------------ |
---|
57 | # Getters |
---|
58 | for my $name (keys(%DEFAULT_R), keys(%DEFAULT_RW)) { |
---|
59 | no strict qw{refs}; |
---|
60 | my $getter = qq{get_$name}; |
---|
61 | *$getter = sub { |
---|
62 | my ($self) = @_; |
---|
63 | return $self->{$name}; |
---|
64 | }; |
---|
65 | } |
---|
66 | |
---|
67 | # ------------------------------------------------------------------------------ |
---|
68 | # Setters |
---|
69 | for my $name (keys(%DEFAULT_RW)) { |
---|
70 | no strict qw{refs}; |
---|
71 | my $setter = qq{set_$name}; |
---|
72 | *$setter = sub { |
---|
73 | my ($self, $value) = @_; |
---|
74 | $self->{$name} = $value; |
---|
75 | }; |
---|
76 | } |
---|
77 | |
---|
78 | 1; |
---|
79 | __END__ |
---|
80 | |
---|
81 | =head1 NAME |
---|
82 | |
---|
83 | FCM::Admin::Config |
---|
84 | |
---|
85 | =head1 SYNOPSIS |
---|
86 | |
---|
87 | $config = FCM::Admin::Config->instance(); |
---|
88 | $dir = $config->get_svn_backup_dir(); |
---|
89 | # ... |
---|
90 | |
---|
91 | =head1 DESCRIPTION |
---|
92 | |
---|
93 | This class is used to retrieve/store configurations required by FCM |
---|
94 | admininstration scripts. |
---|
95 | |
---|
96 | =head1 METHODS |
---|
97 | |
---|
98 | =over 4 |
---|
99 | |
---|
100 | =item FCM::Admin::Config->instance() |
---|
101 | |
---|
102 | Returns a unique instance of this class. On first call, creates the instance |
---|
103 | with the configurations set to their default values. |
---|
104 | |
---|
105 | =item $config->get_admin_email() |
---|
106 | |
---|
107 | Returns the e-mail address of the FCM administrator. |
---|
108 | |
---|
109 | =item $config->get_fcm_home() |
---|
110 | |
---|
111 | Returns the HOME directory of the FCM administrator. |
---|
112 | |
---|
113 | =item $config->get_fcm_dist_on_desktops() |
---|
114 | |
---|
115 | Returns the path for distributing FCM on the desktops. |
---|
116 | |
---|
117 | =item $config->get_fcm_dist_on_HPCs() |
---|
118 | |
---|
119 | Returns a list of locations for distributing FCM on the HPCs. |
---|
120 | |
---|
121 | =item $config->get_fcm_wc() |
---|
122 | |
---|
123 | Returns the (working copy) source path of the default FCM distribution. |
---|
124 | |
---|
125 | =item $config->get_fcm_admin_wc() |
---|
126 | |
---|
127 | Returns the (working copy) source path of the default FCM admin distribution. |
---|
128 | |
---|
129 | =item $config->get_svn_backup_dir() |
---|
130 | |
---|
131 | Returns the path to a directory containing the backups of SVN repositories. |
---|
132 | |
---|
133 | =item $config->get_svn_dump_dir() |
---|
134 | |
---|
135 | Returns the path to a directory containing the revision dumps of SVN |
---|
136 | repositories. |
---|
137 | |
---|
138 | =item $config->get_svn_hook_dir() |
---|
139 | |
---|
140 | Returns the path to a directory containing source files of SVN hook scripts. |
---|
141 | |
---|
142 | =item $config->get_svn_live_dir() |
---|
143 | |
---|
144 | Returns the path to a directory containing the live SVN repositories. |
---|
145 | |
---|
146 | =item $config->get_svn_passwd_file() |
---|
147 | |
---|
148 | Returns the base name of the SVN password file. |
---|
149 | |
---|
150 | =item $config->get_svn_project_suffix() |
---|
151 | |
---|
152 | Returns the suffix added to the name of each SVN repository. |
---|
153 | |
---|
154 | =item $config->get_trac_backup_dir() |
---|
155 | |
---|
156 | Returns the path to a directory containing the backups of Trac environments. |
---|
157 | |
---|
158 | =item $config->get_trac_gid() |
---|
159 | |
---|
160 | Returns the group ID of the Trac server. |
---|
161 | |
---|
162 | =item $config->get_trac_live_dir() |
---|
163 | |
---|
164 | Returns the path to a directory containing the live Trac environments. |
---|
165 | |
---|
166 | =item $config->get_trac_ini_file() |
---|
167 | |
---|
168 | Returns the base name of the Trac INI file. |
---|
169 | |
---|
170 | =item $config->get_trac_passwd_file() |
---|
171 | |
---|
172 | Returns the base name of the Trac password file. |
---|
173 | |
---|
174 | =item $config->get_user_number_min() |
---|
175 | |
---|
176 | Returns the expected minimum number of users. |
---|
177 | |
---|
178 | =item $config->set_svn_backup_dir($value) |
---|
179 | |
---|
180 | Sets the path to a directory containing the backups of SVN repositories. |
---|
181 | |
---|
182 | =item $config->set_svn_dump_dir($value) |
---|
183 | |
---|
184 | Sets the path to a directory containing the revision dumps of SVN |
---|
185 | repositories. |
---|
186 | |
---|
187 | =item $config->set_svn_hook_dir($value) |
---|
188 | |
---|
189 | Sets the path to a directory containing source files of SVN hook scripts. |
---|
190 | |
---|
191 | =item $config->set_svn_live_dir($value) |
---|
192 | |
---|
193 | Sets the path to a directory containing the live SVN repositories. |
---|
194 | |
---|
195 | =item $config->set_svn_passwd_file($value) |
---|
196 | |
---|
197 | Sets the base name of the SVN password file. |
---|
198 | |
---|
199 | =item $config->set_svn_project_suffix($value) |
---|
200 | |
---|
201 | Sets the suffix added to the name of each SVN repository. |
---|
202 | |
---|
203 | =item $config->set_trac_backup_dir($value) |
---|
204 | |
---|
205 | Sets the path to a directory containing the backups of Trac environments. |
---|
206 | |
---|
207 | =item $config->set_trac_live_dir($value) |
---|
208 | |
---|
209 | Sets the path to a directory containing the live Trac environments. |
---|
210 | |
---|
211 | =item $config->set_trac_ini_file($value) |
---|
212 | |
---|
213 | Sets the base name of the Trac INI file. |
---|
214 | |
---|
215 | =item $config->set_trac_passwd_file($value) |
---|
216 | |
---|
217 | Sets the base name of the Trac password file. |
---|
218 | |
---|
219 | =back |
---|
220 | |
---|
221 | =head1 COPYRIGHT |
---|
222 | |
---|
223 | E<169> Crown copyright Met Office. All rights reserved. |
---|
224 | |
---|
225 | =cut |
---|