New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Project.pm in vendors/FCM-2017.10.0/lib/FCM/Admin – NEMO

source: vendors/FCM-2017.10.0/lib/FCM/Admin/Project.pm @ 12899

Last change on this file since 12899 was 10672, checked in by nicolasmartin, 5 years ago

Reimport latest FCM release

File size: 7.7 KB
Line 
1# ------------------------------------------------------------------------------
2# (C) British Crown Copyright 2006-17 Met Office.
3#
4# This file is part of FCM, tools for managing and building source code.
5#
6# FCM is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# FCM is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with FCM. If not, see <http://www.gnu.org/licenses/>.
18# ------------------------------------------------------------------------------
19
20use strict;
21use warnings;
22
23package FCM::Admin::Project;
24
25use overload q{""} => \&get_name;
26use FCM::Admin::Config;
27use File::Spec;
28
29my $ARCHIVE_EXTENSION = q{.tgz};
30
31# ------------------------------------------------------------------------------
32# Creates a new instance of this class.
33sub new {
34    my ($class, $args_ref) = @_;
35    return bless({%{$args_ref}}, $class);
36}
37
38# ------------------------------------------------------------------------------
39# Returns the name of the project.
40sub get_name {
41    my ($self) = @_;
42    return $self->{name};
43}
44
45# ------------------------------------------------------------------------------
46# Returns the base name of the backup archive of the project's SVN repository.
47sub get_svn_archive_base_name {
48    my ($self) = @_;
49    return $self->get_svn_base_name() . $ARCHIVE_EXTENSION;
50}
51
52# ------------------------------------------------------------------------------
53# Returns the path of the backup archive of the project's SVN repository.
54sub get_svn_backup_path {
55    my ($self) = @_;
56    return File::Spec->catfile(
57        FCM::Admin::Config->instance()->get_svn_backup_dir(),
58        $self->get_svn_archive_base_name(),
59    );
60}
61
62# ------------------------------------------------------------------------------
63# Returns the base name of the project's Subversion repository.
64sub get_svn_base_name {
65    my ($self) = @_;
66    return
67        $self->get_name()
68        . FCM::Admin::Config->instance()->get_svn_project_suffix();
69}
70
71# ------------------------------------------------------------------------------
72# Returns the path to the revision dumps of the project's SVN repository.
73sub get_svn_dump_path {
74    my ($self) = @_;
75    return File::Spec->catfile(
76        FCM::Admin::Config->instance()->get_svn_dump_dir(),
77        $self->get_svn_base_name(),
78    );
79}
80
81# ------------------------------------------------------------------------------
82# Returns the path to the project's SVN live repository's hooks directory.
83sub get_svn_live_hook_path {
84    my ($self) = @_;
85    return File::Spec->catfile($self->get_svn_live_path(), q{hooks});
86}
87
88# ------------------------------------------------------------------------------
89# Returns the path to the project's SVN live repository.
90sub get_svn_live_path {
91    my ($self) = @_;
92    return File::Spec->catfile(
93        FCM::Admin::Config->instance()->get_svn_live_dir(),
94        $self->get_svn_base_name(),
95    );
96}
97
98# ------------------------------------------------------------------------------
99# Returns the file:// URI to the project's SVN live repository.
100sub get_svn_file_uri {
101    my ($self) = @_;
102    return q{file://} . $self->get_svn_live_path();
103    # Note: can use URI::file in theory, but it returns file:/path (instead of
104    #       file:///path) which Subversion does not like.
105}
106
107# ------------------------------------------------------------------------------
108# Returns the base name of the project's Trac environment backup archive.
109sub get_trac_archive_base_name {
110    my ($self) = @_;
111    return $self->get_name() . $ARCHIVE_EXTENSION;
112}
113
114# ------------------------------------------------------------------------------
115# Returns the path to the project's Trac backup archive.
116sub get_trac_backup_path {
117    my ($self) = @_;
118    return File::Spec->catfile(
119        FCM::Admin::Config->instance()->get_trac_backup_dir(),
120        $self->get_trac_archive_base_name(),
121    );
122}
123
124# ------------------------------------------------------------------------------
125# Returns the path to the project's Trac live environment's database.
126sub get_trac_live_db_path {
127    my ($self) = @_;
128    return File::Spec->catfile($self->get_trac_live_path(), qw{db trac.db});
129}
130
131# ------------------------------------------------------------------------------
132# Returns the path to the project's Trac live environment's INI file.
133sub get_trac_live_ini_path {
134    my ($self) = @_;
135    return File::Spec->catfile($self->get_trac_live_path(), qw{conf trac.ini});
136}
137
138# ------------------------------------------------------------------------------
139# Returns the path to the project's Trac live environment.
140sub get_trac_live_path {
141    my ($self) = @_;
142    return File::Spec->catfile(
143        FCM::Admin::Config->instance()->get_trac_live_dir(),
144        $self->get_name(),
145    );
146}
147
148# ------------------------------------------------------------------------------
149# Returns the URL to the project's Trac live environment.
150sub get_trac_live_url {
151    my ($self) = @_;
152    my $return = FCM::Admin::Config->instance()->get_trac_live_url_tmpl();
153    for (
154        ['{host}', FCM::Admin::Config->instance()->get_trac_host_name()],
155        ['{project}', $self->get_name()],
156    ) {
157        my ($key, $value) = @{$_};
158        my $index = index($return, $key);
159        if ($index > -1) {
160            substr($return, $index, length($key), $value);
161        }
162    }
163    $return;
164}
165
1661;
167__END__
168
169=head1 NAME
170
171FCM::Admin::Project
172
173=head1 SYNOPSIS
174
175    use FCM::Admin::Project;
176    $project = FCM::Admin::Project->new({name => 'foo'});
177    $path = $project->get_svn_live_path();
178
179=head1 DESCRIPTION
180
181An object of this class represents a project hosted/managed by FCM. The methods
182of this class relies on L<FCM::Admin::Config|FCM::Admin::Config> for many of the
183configurations.
184
185=head1 METHODS
186
187=over 4
188
189=item FCM::Admin::Project->new({name => $name})
190
191Returns a new instance. A name of the project must be specified.
192
193=item $project->get_name()
194
195Returns the name of the project.
196
197=item $project->get_svn_archive_base_name()
198
199Returns the base name of the backup archive of the project's Subversion
200repository.
201
202=item $project->get_svn_backup_path()
203
204Returns the path to the backup archive of the project's Subversion repository.
205
206=item $project->get_svn_base_name()
207
208Returns the base name of the project's Subversion repository.
209
210=item $project->get_svn_dump_path()
211
212Returns the path to the revision dumps of the project's Subversion repository.
213
214=item $project->get_svn_live_hook_path()
215
216Returns the path to the project's SVN live repository's hooks directory.
217
218=item $project->get_svn_live_path()
219
220Returns the path to the project's SVN live repository.
221
222=item $project->get_svn_file_uri()
223
224Returns the file:// URI to the project's SVN live repository.
225
226=item $project->get_trac_archive_base_name()
227
228Returns the base name of the project's Trac environment backup archive.
229
230=item $project->get_trac_backup_path()
231
232Returns the path to the project's Trac backup archive.
233
234=item $project->get_trac_live_db_path()
235
236Returns the path to the project's Trac live environment's database.
237
238=item $project->get_trac_live_ini_path()
239
240Returns the path to the project's Trac live environment's INI file.
241
242=item $project->get_trac_live_path()
243
244Returns the path to the project's Trac live environment.
245
246=item $project->get_trac_live_url()
247
248Returns the URL to the project's Trac live environment.
249
250=back
251
252=head1 SEE ALSO
253
254L<FCM::Admin::Config|FCM::Admin::Config>
255
256=head1 COPYRIGHT
257
258E<169> Crown copyright Met Office. All rights reserved.
259
260=cut
Note: See TracBrowser for help on using the repository browser.