| 1 | # ABSTRACT: Zanata (http://zanata.org/) synchronization plugin for Serge | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Serge::Sync::Plugin::TranslationService::zanata; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Serge::Util qw(subst_macros); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = qv('0.906.0'); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub name { | ||||||||||||||||||||||||||||
| 15 | 11 | ▶ | return 'Zanata translation server (http://zanata.org/) synchronization plugin'; | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub init { | ||||||||||||||||||||||||||||
| 19 | 11 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 11 | $self->SUPER::init(@_); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 11 | $self->{optimizations} = 1; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 11 | $self->merge_schema({ | |||||||||||||||||||||||||||
| 26 | # Project configuration file, eg zanata.xml | ||||||||||||||||||||||||||||
| 27 | project_config => 'STRING', | ||||||||||||||||||||||||||||
| 28 | # User configuration, eg /home/user/.config/zanata.ini | ||||||||||||||||||||||||||||
| 29 | user_config => 'STRING', | ||||||||||||||||||||||||||||
| 30 | # Type of push to perform on the server: | ||||||||||||||||||||||||||||
| 31 | # 'source' pushes source documents only | ||||||||||||||||||||||||||||
| 32 | # 'both' (default) pushes both source and translation documents | ||||||||||||||||||||||||||||
| 33 | push_type => 'STRING', | ||||||||||||||||||||||||||||
| 34 | # The base directory for storing zanata cache files. Default is current directory. | ||||||||||||||||||||||||||||
| 35 | cache_dir => 'STRING', | ||||||||||||||||||||||||||||
| 36 | # Whether to use an Entity cache when fetching documents. | ||||||||||||||||||||||||||||
| 37 | use_cache => 'BOOLEAN', | ||||||||||||||||||||||||||||
| 38 | # Whether to purge the cache before performing the pull operation | ||||||||||||||||||||||||||||
| 39 | purge_cache => 'BOOLEAN', | ||||||||||||||||||||||||||||
| 40 | # File types to locate and transmit to the server when using project type 'file' | ||||||||||||||||||||||||||||
| 41 | file_types => 'ARRAY', | ||||||||||||||||||||||||||||
| 42 | # Whether to enable debug logging. Default is false. | ||||||||||||||||||||||||||||
| 43 | debug => 'BOOLEAN', | ||||||||||||||||||||||||||||
| 44 | # Whether to output full execution error messages (stacktraces). Default is false. | ||||||||||||||||||||||||||||
| 45 | errors => 'BOOLEAN', | ||||||||||||||||||||||||||||
| 46 | # Whether verification of SSL certificates should be disabled. Default is false. | ||||||||||||||||||||||||||||
| 47 | disable_ssl_cert => 'BOOLEAN', | ||||||||||||||||||||||||||||
| 48 | # Dry run: don't change any data, on the server or on the filesystem. Default is false. | ||||||||||||||||||||||||||||
| 49 | dry_run => 'BOOLEAN' | ||||||||||||||||||||||||||||
| 50 | }); | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub validate_data { | ||||||||||||||||||||||||||||
| 54 | 11 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
validate_data: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 11 | $self->SUPER::validate_data; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 11 | $self->{data}->{project_config} = subst_macros($self->{data}->{project_config}); | |||||||||||||||||||||||||||
| 59 | 11 | $self->{data}->{user_config} = subst_macros($self->{data}->{user_config}); | |||||||||||||||||||||||||||
| 60 | 11 | $self->{data}->{push_type} = subst_macros($self->{data}->{push_type}); | |||||||||||||||||||||||||||
| 61 | 11 | $self->{data}->{cache_dir} = subst_macros($self->{data}->{cache_dir}); | |||||||||||||||||||||||||||
| 62 | 11 | $self->{data}->{use_cache} = subst_macros($self->{data}->{use_cache}); | |||||||||||||||||||||||||||
| 63 | 11 | $self->{data}->{purge_cache} = subst_macros($self->{data}->{purge_cache}); | |||||||||||||||||||||||||||
| 64 | 11 | $self->{data}->{file_types} = subst_macros($self->{data}->{file_types}); | |||||||||||||||||||||||||||
| 65 | 11 | $self->{data}->{debug} = subst_macros($self->{data}->{debug}); | |||||||||||||||||||||||||||
| 66 | 11 | $self->{data}->{errors} = subst_macros($self->{data}->{errors}); | |||||||||||||||||||||||||||
| 67 | 11 | $self->{data}->{disable_ssl_cert} = subst_macros($self->{data}->{disable_ssl_cert}); | |||||||||||||||||||||||||||
| 68 | 11 | $self->{data}->{dry_run} = subst_macros($self->{data}->{dry_run}); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 11 | ▶ | die "'project_config' not defined" unless defined $self->{data}->{project_config}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 10 | ▶ | die "'project_config', which is set to '$self->{data}->{project_config}', does not point to a valid file.\n" unless -f $self->{data}->{project_config}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 9 | ▶ | if (defined $self->{data}->{cache_dir}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 5 | ▶ | die "'cache_dir', which is set to '$self->{data}->{cache_dir}', does not point to a valid dir.\n" unless -d $self->{data}->{cache_dir}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 7 | ▶ | if (defined $self->{data}->{user_config}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 2 | ▶ | die "'user_config', which is set to '$self->{data}->{user_config}', does not point to a valid file.\n" unless -f $self->{data}->{user_config}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 6 | ▶ | if (!(defined $self->{data}->{push_type})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 2 | $self->{data}->{push_type} = 'both'; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 6 | ▶ | if (($self->{data}->{push_type} ne 'both') and ($self->{data}->{push_type} ne 'source')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"data"}{"push_type"} ne "both" and $self->{"data"}{"push_type"} ne "source"
MC/DC100%2/2
$self->{"data"}{"push_type"} ne "both" and $self->{"data"}{"push_type"} ne "source"
$self->{"data"}{"push_type"} ne "both"
$self->{"data"}{"push_type"} ne "source"
Truth table100%3/3
A and B
A= $self->{"data"}{"push_type"} ne "both"B= $self->{"data"}{"push_type"} ne "source"
| |||||||||||||||||||||||||||||
| 86 | 1 | die "'push_type', which is set to $self->{data}->{push_type}, is not one of the valid options: 'source' or 'both'"; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub run_zanata_cli { | ||||||||||||||||||||||||||||
| 91 | 10 | ▶ | my ($self, $action, $langs, $capture) = @_; | ||||||||||||||||||||||||||
|
Subroutine
run_zanata_cli: called CC=11 SCAR=25.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 10 | my $command = '--batch-mode '.$action; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 10 | $command .= ' --project-config '.$self->{data}->{project_config}; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 10 | ▶ | if (defined $self->{data}->{user_config}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 2 | $command .= ' --user-config '.$self->{data}->{user_config}; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 10 | ▶ | if ($langs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 2 | my @locales = map {$self->get_zanata_locale($_)} @$langs; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | my $locales_as_string = join(',', @locales); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 2 | $command .= ' --locales '.$locales_as_string; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 10 | ▶ | if (defined $self->{data}->{debug} && $self->{data}->{debug}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"data"}{"debug"} and $self->{"data"}{"debug"}
MC/DC0%0/2
defined $self->{"data"}{"debug"} and $self->{"data"}{"debug"}
defined $self->{"data"}{"debug"}
$self->{"data"}{"debug"}
Truth table66%2/3
A and B
A= defined $self->{"data"}{"debug"}B= $self->{"data"}{"debug"}
| |||||||||||||||||||||||||||||
| 110 | 0 | $command .= ' --debug'; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 10 | ▶ | if (defined $self->{data}->{errors} && $self->{data}->{errors}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"data"}{"errors"} and $self->{"data"}{"errors"}
MC/DC0%0/2
defined $self->{"data"}{"errors"} and $self->{"data"}{"errors"}
defined $self->{"data"}{"errors"}
$self->{"data"}{"errors"}
Truth table66%2/3
A and B
A= defined $self->{"data"}{"errors"}B= $self->{"data"}{"errors"}
| |||||||||||||||||||||||||||||
| 114 | 0 | $command .= ' --errors'; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 10 | ▶ | if (defined $self->{data}->{disable_ssl_cert} && $self->{data}->{disable_ssl_cert}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"data"}{"disable_ssl_cert"} and $self->{"data"}{"disable_ssl_cert"}
MC/DC0%0/2
defined $self->{"data"}{"disable_ssl_cert"} and $self->{"data"}{"disable_ssl_cert"}
defined $self->{"data"}{"disable_ssl_cert"}
$self->{"data"}{"disable_ssl_cert"}
Truth table66%2/3
A and B
A= defined $self->{"data"}{"disable_ssl_cert"}B= $self->{"data"}{"disable_ssl_cert"}
| |||||||||||||||||||||||||||||
| 118 | 0 | $command .= ' --disable-ssl-cert'; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 10 | ▶ | if (defined $self->{data}->{dry_run} && $self->{data}->{dry_run}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"data"}{"dry_run"} and $self->{"data"}{"dry_run"}
MC/DC0%0/2
defined $self->{"data"}{"dry_run"} and $self->{"data"}{"dry_run"}
defined $self->{"data"}{"dry_run"}
$self->{"data"}{"dry_run"}
Truth table66%2/3
A and B
A= defined $self->{"data"}{"dry_run"}B= $self->{"data"}{"dry_run"}
| |||||||||||||||||||||||||||||
| 122 | 0 | $command .= ' --dry-run'; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 10 | $command = 'zanata-cli '.$command; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 10 | print "Running '$command'...\n"; | |||||||||||||||||||||||||||
| 128 | 10 | return $self->run_cmd($command, $capture); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | sub get_zanata_locale { | ||||||||||||||||||||||||||||
| 132 | 4 | ▶ | my ($self, $lang) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_zanata_locale: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 4 | $lang =~ s/-(\w+)$/'-'.uc($1)/e; # convert e.g. 'pt-br' to 'pt-BR' | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 4 | return $lang; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | sub pull_ts { | ||||||||||||||||||||||||||||
| 140 | 5 | ▶ | my ($self, $langs) = @_; | ||||||||||||||||||||||||||
|
Subroutine
pull_ts: called CC=6 SCAR=19.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 5 | my $action = 'pull'; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 5 | ▶ | if (defined $self->{data}->{cache_dir}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 3 | $action .= ' --cache-dir '.$self->{data}->{cache_dir}; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 5 | ▶ | if (defined $self->{data}->{use_cache} && $self->{data}->{use_cache}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"data"}{"use_cache"} and $self->{"data"}{"use_cache"}
MC/DC0%0/2
defined $self->{"data"}{"use_cache"} and $self->{"data"}{"use_cache"}
defined $self->{"data"}{"use_cache"}
$self->{"data"}{"use_cache"}
Truth table66%2/3
A and B
A= defined $self->{"data"}{"use_cache"}B= $self->{"data"}{"use_cache"}
| |||||||||||||||||||||||||||||
| 149 | 0 | $action .= ' --use-cache'; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 5 | ▶ | if (defined $self->{data}->{purge_cache} && $self->{data}->{purge_cache}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"data"}{"purge_cache"} and $self->{"data"}{"purge_cache"}
MC/DC0%0/2
defined $self->{"data"}{"purge_cache"} and $self->{"data"}{"purge_cache"}
defined $self->{"data"}{"purge_cache"}
$self->{"data"}{"purge_cache"}
Truth table66%2/3
A and B
A= defined $self->{"data"}{"purge_cache"}B= $self->{"data"}{"purge_cache"}
| |||||||||||||||||||||||||||||
| 153 | 0 | $action .= ' --purge-cache'; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 5 | return $self->run_zanata_cli($action, $langs); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | sub push_ts { | ||||||||||||||||||||||||||||
| 160 | 5 | ▶ | my ($self, $langs) = @_; | ||||||||||||||||||||||||||
|
Subroutine
push_ts: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 5 | my $action = "push --push-type $self->{data}->{push_type}"; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 5 | ▶ | if (defined $self->{data}->{file_types}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 1 | my $file_types = $self->{data}->{file_types}; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 1 | my $joined_file_types = join(',', @$file_types); | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 1 | $action .= ' --file-types '.$joined_file_types; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 5 | $self->run_zanata_cli($action, $langs); | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 2 | 1; | |||||||||||||||||||||||||||