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.
Old.pm in vendors/lib/FCM/System – NEMO

source: vendors/lib/FCM/System/Old.pm @ 10669

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

Import latest FCM release from Github into the repository for testing

File size: 3.9 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# ------------------------------------------------------------------------------
19use strict;
20use warnings;
21# ------------------------------------------------------------------------------
22package FCM::System::Old;
23use base qw{FCM::Class::CODE};
24
25use Cwd qw{cwd};
26use FCM1::Build;
27use FCM1::Config;
28use FCM1::Extract;
29#use FCM1::ExtractConfigComparator;
30use FCM1::Keyword;
31
32my %CLASS_OF = (build => 'FCM1::Build', extract => 'FCM1::Extract');
33
34my %KEY_OF = (
35    'archive'     => 'ARCHIVE',
36    'clean'       => 'CLEAN',
37    'full'        => 'FULL',
38    'ignore-lock' => 'IGNORE_LOCK',
39    'jobs'        => 'JOBS',
40    'stage'       => 'STAGE',
41    'targets'     => 'TARGETS',
42);
43
44__PACKAGE__->class(
45    {util => '&'},
46    {   init => \&_init,
47        action_of => {
48            build          => sub {_run('build', @_)},
49            config_compare => \&_config_compare,
50            extract        => sub {_run('extract', @_)},
51        },
52    },
53);
54
55sub _init {
56    my ($attrib_ref) = @_;
57    if (!defined(FCM1::Keyword::get_util())) {
58        FCM1::Keyword::set_util($attrib_ref->{util});
59    }
60}
61
62sub _config_compare {
63    my ($attrib_ref, $option_hash_ref, @args) = @_;
64    $attrib_ref->{util}->class_load('FCM1::CmUrl');
65    $attrib_ref->{util}->class_load('FCM1::ExtractConfigComparator');
66    if (exists($option_hash_ref->{verbosity})) {
67        FCM1::Config->instance()->verbose($option_hash_ref->{verbosity});
68    }
69    my %option = %{$option_hash_ref};
70    if (exists($option{'wiki-format'})) {
71        $option{'wiki'} = delete($option{'wiki-format'});
72    }
73    my $system = FCM1::ExtractConfigComparator->new({files => \@args, %option});
74    $system->invoke();
75}
76
77sub _run {
78    my ($key, $attrib_ref, $option_hash_ref, @args) = @_;
79    if (exists($option_hash_ref->{targets})) {
80        @{$option_hash_ref->{targets}}
81            = split(qr{:}msx, join(':', @{$option_hash_ref->{targets}}));
82    }
83    if (exists($option_hash_ref->{verbosity})) {
84        FCM1::Config->instance()->verbose($option_hash_ref->{verbosity});
85    }
86    my $system = $CLASS_OF{$key}->new();
87    my $path_to_cfg = @args ? $args[0] : cwd();
88    $system->cfg()->src($path_to_cfg);
89    my %option_of;
90    while (my ($key, $value) = each(%{$option_hash_ref})) {
91        if (exists($KEY_OF{$key})) {
92            $option_of{$KEY_OF{$key}} = $value;
93        }
94    }
95    $system->invoke(%option_of);
96}
97
98# ------------------------------------------------------------------------------
991;
100__END__
101
102=head1 NAME
103
104FCM::System::Old
105
106=head1 SYNOPSIS
107
108    use FCM::System::Old;
109    my $system = FCM::System::Old->new();
110    $system->('extract', \%option, \@args);
111
112=head1 DESCRIPTION
113
114Provides a compatibility layer for obsolete FCM 1 functionalities.
115
116=head1 METHODS
117
118=over 4
119
120=item $class->new()
121
122Creates and returns an instance of this class.
123
124=item $instance->build(\%option,@args)
125
126Invokes the FCM 1 build system.
127
128=item $instance->config_compare(\%option,@args)
129
130Invokes the FCM 1 cmp-ext-cfg application.
131
132=item $instance->extract(\%option,@args)
133
134Invokes the FCM 1 extract system.
135
136=back
137
138=head1 COPYRIGHT
139
140(C) Crown copyright Met Office. All rights reserved.
141
142=cut
Note: See TracBrowser for help on using the repository browser.