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::Project; |
---|
11 | |
---|
12 | use overload q{""} => \&get_name; |
---|
13 | use FCM::Admin::Config; |
---|
14 | use File::Spec; |
---|
15 | |
---|
16 | my $ARCHIVE_EXTENSION = q{.tgz}; |
---|
17 | |
---|
18 | # ------------------------------------------------------------------------------ |
---|
19 | # Creates a new instance of this class. |
---|
20 | sub new { |
---|
21 | my ($class, $args_ref) = @_; |
---|
22 | return bless({%{$args_ref}}, $class); |
---|
23 | } |
---|
24 | |
---|
25 | # ------------------------------------------------------------------------------ |
---|
26 | # Returns the name of the project. |
---|
27 | sub get_name { |
---|
28 | my ($self) = @_; |
---|
29 | return $self->{name}; |
---|
30 | } |
---|
31 | |
---|
32 | # ------------------------------------------------------------------------------ |
---|
33 | # Returns the base name of the backup archive of the project's SVN repository. |
---|
34 | sub get_svn_archive_base_name { |
---|
35 | my ($self) = @_; |
---|
36 | return $self->get_svn_base_name() . $ARCHIVE_EXTENSION; |
---|
37 | } |
---|
38 | |
---|
39 | # ------------------------------------------------------------------------------ |
---|
40 | # Returns the path of the backup archive of the project's SVN repository. |
---|
41 | sub get_svn_backup_path { |
---|
42 | my ($self) = @_; |
---|
43 | return File::Spec->catfile( |
---|
44 | FCM::Admin::Config->instance()->get_svn_backup_dir(), |
---|
45 | $self->get_svn_archive_base_name(), |
---|
46 | ); |
---|
47 | } |
---|
48 | |
---|
49 | # ------------------------------------------------------------------------------ |
---|
50 | # Returns the base name of the project's Subversion repository. |
---|
51 | sub get_svn_base_name { |
---|
52 | my ($self) = @_; |
---|
53 | return |
---|
54 | $self->get_name() |
---|
55 | . FCM::Admin::Config->instance()->get_svn_project_suffix(); |
---|
56 | } |
---|
57 | |
---|
58 | # ------------------------------------------------------------------------------ |
---|
59 | # Returns the path to the revision dumps of the project's SVN repository. |
---|
60 | sub get_svn_dump_path { |
---|
61 | my ($self) = @_; |
---|
62 | return File::Spec->catfile( |
---|
63 | FCM::Admin::Config->instance()->get_svn_dump_dir(), |
---|
64 | $self->get_svn_base_name(), |
---|
65 | ); |
---|
66 | } |
---|
67 | |
---|
68 | # ------------------------------------------------------------------------------ |
---|
69 | # Returns the path to the project's SVN live repository's hooks directory. |
---|
70 | sub get_svn_live_hook_path { |
---|
71 | my ($self) = @_; |
---|
72 | return File::Spec->catfile($self->get_svn_live_path(), q{hooks}); |
---|
73 | } |
---|
74 | |
---|
75 | # ------------------------------------------------------------------------------ |
---|
76 | # Returns the path to the project's SVN live repository. |
---|
77 | sub get_svn_live_path { |
---|
78 | my ($self) = @_; |
---|
79 | return File::Spec->catfile( |
---|
80 | FCM::Admin::Config->instance()->get_svn_live_dir(), |
---|
81 | $self->get_svn_base_name(), |
---|
82 | ); |
---|
83 | } |
---|
84 | |
---|
85 | # ------------------------------------------------------------------------------ |
---|
86 | # Returns the file:// URI to the project's SVN live repository. |
---|
87 | sub get_svn_file_uri { |
---|
88 | my ($self) = @_; |
---|
89 | return q{file://} . $self->get_svn_live_path(); |
---|
90 | # Note: can use URI::file in theory, but it returns file:/path (instead of |
---|
91 | # file:///path) which Subversion does not like. |
---|
92 | } |
---|
93 | |
---|
94 | # ------------------------------------------------------------------------------ |
---|
95 | # Returns the base name of the project's Trac environment backup archive. |
---|
96 | sub get_trac_archive_base_name { |
---|
97 | my ($self) = @_; |
---|
98 | return $self->get_name() . $ARCHIVE_EXTENSION; |
---|
99 | } |
---|
100 | |
---|
101 | # ------------------------------------------------------------------------------ |
---|
102 | # Returns the path to the project's Trac backup archive. |
---|
103 | sub get_trac_backup_path { |
---|
104 | my ($self) = @_; |
---|
105 | return File::Spec->catfile( |
---|
106 | FCM::Admin::Config->instance()->get_trac_backup_dir(), |
---|
107 | $self->get_trac_archive_base_name(), |
---|
108 | ); |
---|
109 | } |
---|
110 | |
---|
111 | # ------------------------------------------------------------------------------ |
---|
112 | # Returns the path to the project's Trac live environment's database. |
---|
113 | sub get_trac_live_db_path { |
---|
114 | my ($self) = @_; |
---|
115 | return File::Spec->catfile($self->get_trac_live_path(), qw{db trac.db}); |
---|
116 | } |
---|
117 | |
---|
118 | # ------------------------------------------------------------------------------ |
---|
119 | # Returns the path to the project's Trac live environment's INI file. |
---|
120 | sub get_trac_live_ini_path { |
---|
121 | my ($self) = @_; |
---|
122 | return File::Spec->catfile($self->get_trac_live_path(), qw{conf trac.ini}); |
---|
123 | } |
---|
124 | |
---|
125 | # ------------------------------------------------------------------------------ |
---|
126 | # Returns the path to the project's Trac live environment. |
---|
127 | sub get_trac_live_path { |
---|
128 | my ($self) = @_; |
---|
129 | return File::Spec->catfile( |
---|
130 | FCM::Admin::Config->instance()->get_trac_live_dir(), |
---|
131 | $self->get_name(), |
---|
132 | ); |
---|
133 | } |
---|
134 | |
---|
135 | 1; |
---|
136 | __END__ |
---|
137 | |
---|
138 | =head1 NAME |
---|
139 | |
---|
140 | FCM::Admin::Project |
---|
141 | |
---|
142 | =head1 SYNOPSIS |
---|
143 | |
---|
144 | use FCM::Admin::Project; |
---|
145 | $project = FCM::Admin::Project->new({name => 'foo'}); |
---|
146 | $path = $project->get_svn_live_path(); |
---|
147 | |
---|
148 | =head1 DESCRIPTION |
---|
149 | |
---|
150 | An object of this class represents a project hosted/managed by FCM. The methods |
---|
151 | of this class relies on L<FCM::Admin::Config|FCM::Admin::Config> for many of the |
---|
152 | configurations. |
---|
153 | |
---|
154 | =head1 METHODS |
---|
155 | |
---|
156 | =over 4 |
---|
157 | |
---|
158 | =item FCM::Admin::Project->new({name => $name}) |
---|
159 | |
---|
160 | Returns a new instance. A name of the project must be specified. |
---|
161 | |
---|
162 | =item $project->get_name() |
---|
163 | |
---|
164 | Returns the name of the project. |
---|
165 | |
---|
166 | =item $project->get_svn_archive_base_name() |
---|
167 | |
---|
168 | Returns the base name of the backup archive of the project's Subversion |
---|
169 | repository. |
---|
170 | |
---|
171 | =item $project->get_svn_backup_path() |
---|
172 | |
---|
173 | Returns the path to the backup archive of the project's Subversion repository. |
---|
174 | |
---|
175 | =item $project->get_svn_base_name() |
---|
176 | |
---|
177 | Returns the base name of the project's Subversion repository. |
---|
178 | |
---|
179 | =item $project->get_svn_dump_path() |
---|
180 | |
---|
181 | Returns the path to the revision dumps of the project's Subversion repository. |
---|
182 | |
---|
183 | =item $project->get_svn_live_hook_path() |
---|
184 | |
---|
185 | Returns the path to the project's SVN live repository's hooks directory. |
---|
186 | |
---|
187 | =item $project->get_svn_live_path() |
---|
188 | |
---|
189 | Returns the path to the project's SVN live repository. |
---|
190 | |
---|
191 | =item $project->get_svn_file_uri() |
---|
192 | |
---|
193 | Returns the file:// URI to the project's SVN live repository. |
---|
194 | |
---|
195 | =item $project->get_trac_archive_base_name() |
---|
196 | |
---|
197 | Returns the base name of the project's Trac environment backup archive. |
---|
198 | |
---|
199 | =item $project->get_trac_backup_path() |
---|
200 | |
---|
201 | Returns the path to the project's Trac backup archive. |
---|
202 | |
---|
203 | =item $project->get_trac_live_db_path() |
---|
204 | |
---|
205 | Returns the path to the project's Trac live environment's database. |
---|
206 | |
---|
207 | =item $project->get_trac_live_ini_path() |
---|
208 | |
---|
209 | Returns the path to the project's Trac live environment's INI file. |
---|
210 | |
---|
211 | =item $project->get_trac_live_path() |
---|
212 | |
---|
213 | Returns the path to the project's Trac live environment. |
---|
214 | |
---|
215 | =back |
---|
216 | |
---|
217 | =head1 SEE ALSO |
---|
218 | |
---|
219 | L<FCM::Admin::Config|FCM::Admin::Config> |
---|
220 | |
---|
221 | =head1 COPYRIGHT |
---|
222 | |
---|
223 | E<169> Crown copyright Met Office. All rights reserved. |
---|
224 | |
---|
225 | =cut |
---|