| 1 | package Serge::Sync; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use parent Serge::Interface::PluginHost; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::Spec::Functions qw(rel2abs splitdir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Time::HiRes qw(gettimeofday tv_interval); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Serge::Engine::Processor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Serge::Sync::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Serge::Util qw(subst_macros); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # Initialize object | ||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||
| 18 | sub new { | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my ($class) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | my $self = { | |||||||||||||||||||||||||||
| 22 | debug => undef, # enable debug output | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | debug_echo_commands => undef, # set to 1 to echo system commands about to be executed | ||||||||||||||||||||||||||||
| 25 | debug_echo_output => undef, # set to 1 to echo commands' output to be parsed | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | no_pull => undef, # set to 1 to prevent checking out changes from VCS | ||||||||||||||||||||||||||||
| 28 | no_localize => undef, # set to 1 to prevent running the actual l10n script and just do VCS checkout/commit | ||||||||||||||||||||||||||||
| 29 | no_pull_ts => undef, # set to 1 to prevent executing pull_ts command (syncing changes from external translation service to local translation files) | ||||||||||||||||||||||||||||
| 30 | no_push_ts => undef, # set to 1 to prevent updating push_ts command (pushing local translation files to external translation service) | ||||||||||||||||||||||||||||
| 31 | no_push => undef, # set to 1 to prevent committing changes back to VCS | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ts => undef, # holds TS (translation service) plugin | ||||||||||||||||||||||||||||
| 34 | vcs => undef, # holds VCS (version control system) plugin | ||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | return $self; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub validate_config { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my ($self, $config) = @_; | ||||||||||||||||||||||||||
|
Subroutine
validate_config: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | die "\$config parameter not passed" unless defined $config; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | die "bad config object" unless defined $config->{data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (!$self->{no_pull_ts} || !$self->{no_push_ts}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"no_pull_ts"} and $self->{"no_push_ts"}
MC/DC0%0/2
$self->{"no_pull_ts"} and $self->{"no_push_ts"}
$self->{"no_pull_ts"}
$self->{"no_push_ts"}
Truth table0%0/3
A and B
A= $self->{"no_pull_ts"}B= $self->{"no_push_ts"}
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | die "'sync' section missing" unless defined $config->{data}->{sync}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | die "'sync'->'ts' section missing from " unless defined $config->{data}->{sync}->{ts}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if (!$self->{no_pull} || !$self->{no_push}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"no_pull"} and $self->{"no_push"}
MC/DC0%0/2
$self->{"no_pull"} and $self->{"no_push"}
$self->{"no_pull"}
$self->{"no_push"}
Truth table0%0/3
A and B
A= $self->{"no_pull"}B= $self->{"no_push"}
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | die "'sync' section missing" unless defined $config->{data}->{sync}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | die "'sync'->'vcs' not defined" unless defined $config->{data}->{sync}->{vcs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (!$self->{no_localize}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | die "'jobs' section missing" unless defined $config->{data}->{jobs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub reset_counters { | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
reset_counters: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 0 | $self->{total_jobs} = 0; | |||||||||||||||||||||||||||
| 66 | 0 | $self->{skipped_jobs} = 0; | |||||||||||||||||||||||||||
| 67 | 0 | $self->{failed_jobs} = 0; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub do_sync { | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my ($self, $engine, $config) = @_; | ||||||||||||||||||||||||||
|
Subroutine
do_sync: not called CC=20 SCAR=60.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | $self->validate_config($config); | |||||||||||||||||||||||||||
| 74 | 0 | $self->{config} = $config; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # initialize translation service plugin (if necessary) | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (!$self->{no_pull_ts} || !$self->{no_push_ts}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"no_pull_ts"} and $self->{"no_push_ts"}
MC/DC0%0/2
$self->{"no_pull_ts"} and $self->{"no_push_ts"}
$self->{"no_pull_ts"}
$self->{"no_push_ts"}
Truth table0%0/3
A and B
A= $self->{"no_pull_ts"}B= $self->{"no_push_ts"}
| |||||||||||||||||||||||||||||
| 79 | $self->{ts} = $self->load_plugin_from_node( | ||||||||||||||||||||||||||||
| 80 | 'Serge::Sync::Plugin::TranslationService', | ||||||||||||||||||||||||||||
| 81 | $config->{data}->{sync}->{ts} | ||||||||||||||||||||||||||||
| 82 | 0 | ); | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $self->{ts}->{echo_commands} = 1 if $self->{echo_commands}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $self->{ts}->{echo_output} = 1 if $self->{echo_output}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # initialize VCS plugin (if necessary) | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (!$self->{no_pull} || !$self->{no_push }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"no_pull"} and $self->{"no_push"}
MC/DC0%0/2
$self->{"no_pull"} and $self->{"no_push"}
$self->{"no_pull"}
$self->{"no_push"}
Truth table0%0/3
A and B
A= $self->{"no_pull"}B= $self->{"no_push"}
| |||||||||||||||||||||||||||||
| 90 | $self->{vcs} = $self->load_plugin_from_node( | ||||||||||||||||||||||||||||
| 91 | 'Serge::Sync::Plugin::VCS', | ||||||||||||||||||||||||||||
| 92 | $config->{data}->{sync}->{vcs} | ||||||||||||||||||||||||||||
| 93 | 0 | ); | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | $self->{vcs}->{initialize} = 1 if $self->{initialize}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $self->{vcs}->{echo_commands} = 1 if $self->{echo_commands}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $self->{vcs}->{echo_output} = 1 if $self->{echo_output}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # step 1 | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($self->{no_pull}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | print "Skip 'pull' step\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | } else { | ||||||||||||||||||||||||||||
| 104 | 0 | print "\nUpdating project from VCS...\n\n"; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | my $start = [gettimeofday]; | |||||||||||||||||||||||||||
| 107 | 0 | $self->{vcs}->checkout_all; | |||||||||||||||||||||||||||
| 108 | 0 | print "'pull' step took ", tv_interval($start), " seconds\n"; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # step 2 | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ($self->{no_pull_ts}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | print "Skip 'pull_ts' step\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||
| 116 | 0 | print "\nPulling translation files from external translation service...\n\n"; | |||||||||||||||||||||||||||
| 117 | 0 | my $start = [gettimeofday]; | |||||||||||||||||||||||||||
| 118 | 0 | $self->{ts}->pull_ts($self->{languages}); # update all languages | |||||||||||||||||||||||||||
| 119 | 0 | print "'pull-ts' step took ", tv_interval($start), " seconds\n"; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # step 3 | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ($self->{no_localize}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | print "Skip 'localize' step\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||
| 127 | 0 | print "\nRunning the translation framework...\n\n"; | |||||||||||||||||||||||||||
| 128 | 0 | my $start = [gettimeofday]; | |||||||||||||||||||||||||||
| 129 | 0 | my $processor = Serge::Engine::Processor->new($engine, $config); | |||||||||||||||||||||||||||
| 130 | 0 | $processor->run(); | |||||||||||||||||||||||||||
| 131 | 0 | print "'localize' step took ", tv_interval($start), " seconds\n"; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | $self->{total_jobs} += $processor->{total_jobs}; | |||||||||||||||||||||||||||
| 134 | 0 | $self->{skipped_jobs} += $processor->{skipped_jobs}; | |||||||||||||||||||||||||||
| 135 | 0 | $self->{failed_jobs} += $processor->{failed_jobs}; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # step 4 | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ($self->{no_push_ts}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | print "Skip 'push_ts' step\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | } else { | ||||||||||||||||||||||||||||
| 143 | 0 | print "\nPushing translation files to external translation service...\n\n"; | |||||||||||||||||||||||||||
| 144 | 0 | my $start = [gettimeofday]; | |||||||||||||||||||||||||||
| 145 | 0 | $self->{ts}->push_ts($self->{languages}); # update all languages | |||||||||||||||||||||||||||
| 146 | 0 | print "'push-ts' step took ", tv_interval($start), " seconds\n"; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # step 5 | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ($self->{no_push}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | print "Skip 'push' step\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | } else { | ||||||||||||||||||||||||||||
| 154 | 0 | print "\nCommitting updated project files back to VCS\n\n"; | |||||||||||||||||||||||||||
| 155 | 0 | my $start = [gettimeofday]; | |||||||||||||||||||||||||||
| 156 | 0 | $self->{vcs}->commit_all($self->{commit_message}); | |||||||||||||||||||||||||||
| 157 | 0 | print "'push' step took ", tv_interval($start), " seconds\n"; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | sub abspath { | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my ($self, $path) = @_; | ||||||||||||||||||||||||||
|
Subroutine
abspath: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | die "Config not initialized yet" unless defined $self->{config}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | return $self->{config}->abspath($path); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 1 | 1; | |||||||||||||||||||||||||||