line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Zanata (http://zanata.org/) synchronization plugin for Serge |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Serge::Sync::Plugin::TranslationService::zanata; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
19116
|
use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1761
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use Serge::Util qw(subst_macros); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
84
|
|
10
|
1
|
|
|
1
|
|
459
|
use version; |
|
1
|
|
|
|
|
1889
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = qv('0.906.0'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub name { |
15
|
11
|
|
|
11
|
0
|
175325
|
return 'Zanata translation server (http://zanata.org/) synchronization plugin'; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub init { |
19
|
11
|
|
|
11
|
0
|
139
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
11
|
|
|
|
|
59
|
$self->SUPER::init(@_); |
22
|
|
|
|
|
|
|
|
23
|
11
|
|
|
|
|
88
|
$self->{optimizations} = 1; |
24
|
|
|
|
|
|
|
|
25
|
11
|
|
|
|
|
153
|
$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
|
|
|
11
|
0
|
20131
|
my ($self) = @_; |
55
|
|
|
|
|
|
|
|
56
|
11
|
|
|
|
|
57
|
$self->SUPER::validate_data; |
57
|
|
|
|
|
|
|
|
58
|
11
|
|
|
|
|
5889
|
$self->{data}->{project_config} = subst_macros($self->{data}->{project_config}); |
59
|
11
|
|
|
|
|
370
|
$self->{data}->{user_config} = subst_macros($self->{data}->{user_config}); |
60
|
11
|
|
|
|
|
309
|
$self->{data}->{push_type} = subst_macros($self->{data}->{push_type}); |
61
|
11
|
|
|
|
|
287
|
$self->{data}->{cache_dir} = subst_macros($self->{data}->{cache_dir}); |
62
|
11
|
|
|
|
|
283
|
$self->{data}->{use_cache} = subst_macros($self->{data}->{use_cache}); |
63
|
11
|
|
|
|
|
296
|
$self->{data}->{purge_cache} = subst_macros($self->{data}->{purge_cache}); |
64
|
11
|
|
|
|
|
294
|
$self->{data}->{file_types} = subst_macros($self->{data}->{file_types}); |
65
|
11
|
|
|
|
|
308
|
$self->{data}->{debug} = subst_macros($self->{data}->{debug}); |
66
|
11
|
|
|
|
|
299
|
$self->{data}->{errors} = subst_macros($self->{data}->{errors}); |
67
|
11
|
|
|
|
|
290
|
$self->{data}->{disable_ssl_cert} = subst_macros($self->{data}->{disable_ssl_cert}); |
68
|
11
|
|
|
|
|
294
|
$self->{data}->{dry_run} = subst_macros($self->{data}->{dry_run}); |
69
|
|
|
|
|
|
|
|
70
|
11
|
100
|
|
|
|
293
|
die "'project_config' not defined" unless defined $self->{data}->{project_config}; |
71
|
10
|
100
|
|
|
|
92
|
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}; |
72
|
|
|
|
|
|
|
|
73
|
9
|
100
|
|
|
|
306
|
if (defined $self->{data}->{cache_dir}) { |
74
|
5
|
100
|
|
|
|
53
|
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}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
7
|
100
|
|
|
|
112
|
if (defined $self->{data}->{user_config}) { |
78
|
2
|
100
|
|
|
|
18
|
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}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
6
|
100
|
|
|
|
82
|
if (!(defined $self->{data}->{push_type})) { |
82
|
2
|
|
|
|
|
23
|
$self->{data}->{push_type} = 'both'; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
6
|
100
|
100
|
|
|
63
|
if (($self->{data}->{push_type} ne 'both') and ($self->{data}->{push_type} ne 'source')) { |
86
|
1
|
|
|
|
|
17
|
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
|
|
|
10
|
0
|
36
|
my ($self, $action, $langs, $capture) = @_; |
92
|
|
|
|
|
|
|
|
93
|
10
|
|
|
|
|
28
|
my $command = '--batch-mode '.$action; |
94
|
|
|
|
|
|
|
|
95
|
10
|
|
|
|
|
36
|
$command .= ' --project-config '.$self->{data}->{project_config}; |
96
|
|
|
|
|
|
|
|
97
|
10
|
100
|
|
|
|
85
|
if (defined $self->{data}->{user_config}) { |
98
|
2
|
|
|
|
|
18
|
$command .= ' --user-config '.$self->{data}->{user_config}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
10
|
100
|
|
|
|
85
|
if ($langs) { |
102
|
2
|
|
|
|
|
7
|
my @locales = map {$self->get_zanata_locale($_)} @$langs; |
|
4
|
|
|
|
|
11
|
|
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
8
|
my $locales_as_string = join(',', @locales); |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
8
|
$command .= ' --locales '.$locales_as_string; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
10
|
50
|
66
|
|
|
35
|
if (defined $self->{data}->{debug} && $self->{data}->{debug}) { |
110
|
0
|
|
|
|
|
0
|
$command .= ' --debug'; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
10
|
50
|
66
|
|
|
106
|
if (defined $self->{data}->{errors} && $self->{data}->{errors}) { |
114
|
0
|
|
|
|
|
0
|
$command .= ' --errors'; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
10
|
50
|
66
|
|
|
95
|
if (defined $self->{data}->{disable_ssl_cert} && $self->{data}->{disable_ssl_cert}) { |
118
|
0
|
|
|
|
|
0
|
$command .= ' --disable-ssl-cert'; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
10
|
50
|
66
|
|
|
100
|
if (defined $self->{data}->{dry_run} && $self->{data}->{dry_run}) { |
122
|
0
|
|
|
|
|
0
|
$command .= ' --dry-run'; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
10
|
|
|
|
|
94
|
$command = 'zanata-cli '.$command; |
126
|
|
|
|
|
|
|
|
127
|
10
|
|
|
|
|
355
|
print "Running '$command'...\n"; |
128
|
10
|
|
|
|
|
83
|
return $self->run_cmd($command, $capture); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub get_zanata_locale { |
132
|
4
|
|
|
4
|
0
|
12
|
my ($self, $lang) = @_; |
133
|
|
|
|
|
|
|
|
134
|
4
|
|
|
|
|
20
|
$lang =~ s/-(\w+)$/'-'.uc($1)/e; # convert e.g. 'pt-br' to 'pt-BR' |
|
2
|
|
|
|
|
12
|
|
135
|
|
|
|
|
|
|
|
136
|
4
|
|
|
|
|
14
|
return $lang; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub pull_ts { |
140
|
5
|
|
|
5
|
0
|
1481
|
my ($self, $langs) = @_; |
141
|
|
|
|
|
|
|
|
142
|
5
|
|
|
|
|
15
|
my $action = 'pull'; |
143
|
|
|
|
|
|
|
|
144
|
5
|
100
|
|
|
|
28
|
if (defined $self->{data}->{cache_dir}) { |
145
|
3
|
|
|
|
|
39
|
$action .= ' --cache-dir '.$self->{data}->{cache_dir}; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
5
|
50
|
66
|
|
|
50
|
if (defined $self->{data}->{use_cache} && $self->{data}->{use_cache}) { |
149
|
0
|
|
|
|
|
0
|
$action .= ' --use-cache'; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
5
|
50
|
66
|
|
|
89
|
if (defined $self->{data}->{purge_cache} && $self->{data}->{purge_cache}) { |
153
|
0
|
|
|
|
|
0
|
$action .= ' --purge-cache'; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
5
|
|
|
|
|
68
|
return $self->run_zanata_cli($action, $langs); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub push_ts { |
160
|
5
|
|
|
5
|
0
|
3122
|
my ($self, $langs) = @_; |
161
|
|
|
|
|
|
|
|
162
|
5
|
|
|
|
|
30
|
my $action = "push --push-type $self->{data}->{push_type}"; |
163
|
|
|
|
|
|
|
|
164
|
5
|
100
|
|
|
|
57
|
if (defined $self->{data}->{file_types}) { |
165
|
1
|
|
|
|
|
10
|
my $file_types = $self->{data}->{file_types}; |
166
|
|
|
|
|
|
|
|
167
|
1
|
|
|
|
|
11
|
my $joined_file_types = join(',', @$file_types); |
168
|
|
|
|
|
|
|
|
169
|
1
|
|
|
|
|
4
|
$action .= ' --file-types '.$joined_file_types; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
5
|
|
|
|
|
49
|
$self->run_zanata_cli($action, $langs); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |