| 1 | package Serge::Command::sync; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use parent Serge::Command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Serge::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Serge::Engine; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Serge::Engine::Processor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Serge::Sync; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub get_commands { | ||||||||||||||||||||||||||||
| 14 | return { | ||||||||||||||||||||||||||||
| 15 | 0 | ▶ | pull => {need_config => 1, handler => \&run, info => 'Pull project files from source control', combine_with => [ 'push', 'pull-ts', 'push-ts', 'localize']}, | ||||||||||||||||||||||||||
|
Subroutine
get_commands: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | push => {need_config => 1, handler => \&run, info => 'Push project files to source control', combine_with => ['pull', 'pull-ts', 'push-ts', 'localize']}, | ||||||||||||||||||||||||||||
| 17 | 'pull-ts' => {need_config => 1, handler => \&run, info => 'Pull data from translation server', combine_with => ['pull', 'push', 'push-ts', 'localize']}, | ||||||||||||||||||||||||||||
| 18 | 'push-ts' => {need_config => 1, handler => \&run, info => 'Push data to translation server', combine_with => ['pull', 'push', 'pull-ts', 'localize']}, | ||||||||||||||||||||||||||||
| 19 | localize => {need_config => 1, handler => \&run, info => 'Perform localization cycle', combine_with => ['pull', 'push', 'pull-ts', 'push-ts' ]}, | ||||||||||||||||||||||||||||
| 20 | sync => {need_config => 1, handler => \&run, info => 'Perform a full synchronization + localization cycle'}, | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub init { | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my ($self, $command) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | $self->SUPER::init(@_); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | my $error_msg = "Failed to parse some command-line parameters."; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($command eq 'pull') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | GetOptions( | ||||||||||||||||||||||||||||
| 33 | "initialize" => \$self->{initialize}, | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | ) or die $error_msg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($command =~ m/^(pull-ts|localize|push-ts|sync)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | GetOptions( | ||||||||||||||||||||||||||||
| 39 | "force" => \$self->{force}, | ||||||||||||||||||||||||||||
| 40 | "lang|language|languages=s" => \$self->{languages}, | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | ) or die $error_msg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($command =~ m/^(pull|pull-ts|push-ts|push|sync)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | GetOptions( | ||||||||||||||||||||||||||||
| 46 | "echo-commands" => \$self->{echo_commands}, | ||||||||||||||||||||||||||||
| 47 | "echo-output" => \$self->{echo_output}, | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | ) or die $error_msg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($command =~ m/^(push|sync)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | GetOptions( | ||||||||||||||||||||||||||||
| 53 | "message=s" => \$self->{message}, | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | ) or die $error_msg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($command =~ m/^(localize|sync)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | GetOptions( | ||||||||||||||||||||||||||||
| 59 | "job|jobs=s" => \$self->{jobs}, | ||||||||||||||||||||||||||||
| 60 | "rebuild-ts-files" => \$self->{rebuild_ts_files}, | ||||||||||||||||||||||||||||
| 61 | "output-only-mode" => \$self->{output_only_mode}, | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | ) or die $error_msg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | sub run { | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my ($self, $commands_list) = @_; | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=37 SCAR=72.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # if only one command provided, convert it to an array | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $commands_list = [$commands_list] unless ref($commands_list) eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my $engine = Serge::Engine->new(); | |||||||||||||||||||||||||||
| 73 | 0 | my $sync = Serge::Sync->new(); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $sync->{debug} = 1 if $self->{parent}->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $sync->{initialize} = 1 if $self->{initialize}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $sync->{optimizations} = undef if $self->{force}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $sync->{echo_commands} = 1 if $self->{echo_commands}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $sync->{echo_output} = 1 if $self->{echo_output}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $sync->{commit_message} = $self->{message}; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $engine->{debug} = 1 if $self->{parent}->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $engine->{optimizations} = undef if $self->{force}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $engine->{rebuild_ts_files} = 1 if $self->{rebuild_ts_files}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $engine->{output_only_mode} = 1 if $self->{output_only_mode}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | my %limit_languages; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($self->{languages}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | my @l = split(/,/, $self->{languages}); | |||||||||||||||||||||||||||
| 92 | 0 | $sync->{languages} = \@l; | |||||||||||||||||||||||||||
| 93 | 0 | $engine->{limit_destination_languages} = \@l; | |||||||||||||||||||||||||||
| 94 | 0 | @limit_languages{@l} = @l; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | my %limit_jobs; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($self->{jobs}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | my @j = split(/,/, $self->{jobs}); | |||||||||||||||||||||||||||
| 100 | 0 | $engine->{limit_destination_jobs} = \@j; | |||||||||||||||||||||||||||
| 101 | 0 | @limit_jobs{@j} = @j; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | my ($pull, $pull_ts, $localize, $push_ts, $push); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | map { | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $pull = 1 if $_ eq 'pull'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $pull_ts = 1 if $_ eq 'pull-ts'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $localize = 1 if $_ eq 'localize'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $push_ts = 1 if $_ eq 'push-ts'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $push = 1 if $_ eq 'push'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $pull = $pull_ts = $localize = $push_ts = $push = 1 if $_ eq 'sync'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | } @$commands_list; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | $sync->{no_pull} = !$pull; | |||||||||||||||||||||||||||
| 117 | 0 | $sync->{no_pull_ts} = !$pull_ts; | |||||||||||||||||||||||||||
| 118 | 0 | $sync->{no_localize} = !$localize; | |||||||||||||||||||||||||||
| 119 | 0 | $sync->{no_push_ts} = !$push_ts; | |||||||||||||||||||||||||||
| 120 | 0 | $sync->{no_push} = !$push; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | $sync->reset_counters; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | my @confs = $self->{parent}->get_config_files; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | my $total_configs = 0; | |||||||||||||||||||||||||||
| 127 | 0 | my $failed_configs = 0; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | foreach my $config_file (@confs) { | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | print qq{ | |||||||||||||||||||||||||||
| 132 | ### $config_file | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | }; | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | my $config = $self->{parent}->get_config_object($config_file); | |||||||||||||||||||||||||||
| 137 | 0 | $config->chdir; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ($self->{languages} && !$config->any_language_exists(\%limit_languages)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"languages"} and not $config->any_language_exists(\%limit_languages)
MC/DC0%0/2
$self->{"languages"} and not $config->any_language_exists(\%limit_languages)
$self->{"languages"}
not $config->any_language_exists(\%limit_languages)
Truth table0%0/3
A and not(B)
A= $self->{"languages"}B= not $config->any_language_exists(\%limit_languages)
| |||||||||||||||||||||||||||||
| 140 | 0 | print "Skip (no target languages)\n"; | |||||||||||||||||||||||||||
| 141 | 0 | next; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ($self->{jobs} && !$config->any_job_exists(\%limit_jobs)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"jobs"} and not $config->any_job_exists(\%limit_jobs)
MC/DC0%0/2
$self->{"jobs"} and not $config->any_job_exists(\%limit_jobs)
$self->{"jobs"}
not $config->any_job_exists(\%limit_jobs)
Truth table0%0/3
A and not(B)
A= $self->{"jobs"}B= not $config->any_job_exists(\%limit_jobs)
| |||||||||||||||||||||||||||||
| 145 | 0 | print "Skip (no target jobs)\n"; | |||||||||||||||||||||||||||
| 146 | 0 | next; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | $total_configs++; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | eval { | |||||||||||||||||||||||||||
| 152 | 0 | $sync->do_sync($engine, $config); | |||||||||||||||||||||||||||
| 153 | }; | ||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | print "Exception occurred while processing configuration file: $@\n"; | |||||||||||||||||||||||||||
| 156 | 0 | $failed_configs++; | |||||||||||||||||||||||||||
| 157 | 0 | next; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | $engine->cleanup; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $jobs_plural = $sync->{total_jobs} == 1 ? 'job' : 'jobs'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my $files_plural = $total_configs == 1 ? 'file' : 'files'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $was_plural = $sync->{total_jobs} == 1 ? 'was' : 'were'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | print "\nSync complete. $sync->{total_jobs} $jobs_plural in $total_configs configuration $files_plural $was_plural processed\n"; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if ($failed_configs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $configs_plural = $failed_configs == 1 ? 'config' : 'configs'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | print "$failed_configs $configs_plural failed to be processed\n"; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ($sync->{skipped_jobs}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | my $jobs_plural = $sync->{skipped_jobs} == 1 ? 'job was' : 'jobs were'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | print "$sync->{skipped_jobs} $jobs_plural skipped due to configuration errors\n"; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ($sync->{failed_jobs}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | my $jobs_plural = $sync->{failed_jobs} == 1 ? 'job' : 'jobs'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 0 | print "$sync->{failed_jobs} $jobs_plural ended abnormally\n"; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | # return different codes for errors of different severity | ||||||||||||||||||||||||||||
| 184 | 0 | ▶ | return 3 if $failed_configs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return 2 if $sync->{failed_jobs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | return 1 if $sync->{skipped_jobs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | return 0; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 1 | 1; | |||||||||||||||||||||||||||