Skip to content

Commit

Permalink
Importer.pm inherits process_job sub from Engine.pm
Browse files Browse the repository at this point in the history
Fixed parsing rc file and import test
  • Loading branch information
icnocop committed Mar 8, 2019
1 parent 5831284 commit 2b70f1e
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 66 deletions.
3 changes: 2 additions & 1 deletion lib/Serge/Engine/Plugin/parse_rc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ sub parse {
# STRINGTABLE BEGIN...END block contents
} elsif ($stringtable && $blocklevel) {
if ($line =~ m/^[\t ]*(\w+)[\t ]+"((.*?("")*)*?)"/) { # test for one-line string definitions
$hint = $1;
$idstr = $1;
$hint = $idstr;
$orig_str = $2;
} elsif ($line =~ m/^[\t ]*(\w+)[\t ]*(\/\/.*)*$/) { # test for the first line (id) of the two-line string definitions
$idstr = $1;
Expand Down
59 changes: 0 additions & 59 deletions lib/Serge/Importer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,6 @@ use Unicode::Normalize;

use Serge::Util;

sub process_job {
my ($self, $job) = @_;

$self->{stats} = {} unless exists $self->{stats};

$self->init_job($job);
$self->adjust_job_defaults($job);
$self->adjust_destination_languages($job);

# this hash will hold key => {item => <item_id>, string => <string>} mapping
# for the source resource file
$job->{source_keys} = {};
$job->{localized_keys} = {};
$job->{optimizations} = undef;

# now that we have a final list of destination languages, we can
# determine if the job can run or not

# for import purposes, skip jobs having output_only_mode as well

if ($self->job_can_run($job) && !$job->{output_only_mode}) {
print "\n\n*** [".$job->{id}."] ".$job->{name}." ***\n\n";
} else {
print "*** SKIPPING: [".$job->{id}."] ".$job->{name}." ***\n";
return;
}

$self->open_database($job);
$self->adjust_modified_languages($job);

die "source_dir [$job->{source_dir}] doesn't exist. Try doing an initial data checkout (`serge pull --initialize`), or reconfigure your job" unless -d $job->{source_dir};

print "Path to source resources: [".$job->{source_dir}."]\n";
print "Path to localized resources: [".$job->{output_file_path}."]\n";
print "Languages: [".join(',', sort @{$job->{modified_languages}})."]\n";
print "DB source: [".$job->{db_source}."]\n";

# preload all items/strings/translations into cache

$self->{db}->preload_cache_for_job($job->{db_namespace}, $job->{id}, $job->{modified_languages});

$self->run_callbacks('before_job');

$self->run_callbacks('before_update_database_from_source_files');

$self->{current_lang} = '';

$self->update_database_from_source_files;

$self->parse_localized_files;

# note: do not close the database at this point as it might be reused in another job

$self->run_callbacks('after_job');

print "*** [end] ***\n";

}

sub parse_localized_files {
my ($self) = @_;

Expand Down
22 changes: 18 additions & 4 deletions t/data/importer/parse_rc/00/reference-output/database/properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
properties
{
0 1 source:1 b88e2e32e7cd852f7d4b76ba913a78a1
1 2 hash:1 b88e2e32e7cd852f7d4b76ba913a78a1
2 3 size:1 923
3 4 items:1 1,2,3,4,5
0 1 source:1 b88e2e32e7cd852f7d4b76ba913a78a1
1 2 hash:1 b88e2e32e7cd852f7d4b76ba913a78a1
2 3 size:1 923
3 4 items:1 1,2,3,4,5
4 5 ts:1:test:count 5
5 6 usn:1:test 16
6 7 ts:1:test a535701a4bf40dfd3e41ccd666298f16
7 8 target:1:test_job:test 402d4b321ffe9876cb697d5122b5569a
8 9 target:mtime:1:test_job:test 12345678
9 10 source:1:test_job:test b88e2e32e7cd852f7d4b76ba913a78a1
10 11 source:ts:1:test_job:test
a535701a4bf40dfd3e41ccd666298f16
11 12 job-hash:test_namespace:test_job
13b98de1726dbf76b84d3c04553c69a6
12 13 job-plugin:test_namespace:test_job parse_rc.
13 14 job-serializer-plugin:test_namespace:test_job
serialize_po.
14 15 job-engine:test_namespace:test_job 1.3.2
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
translations
{
0 1 12 1 test `Ṽáļũē 1` NO 0 0
1 2 13 2 test `Ṽáļũē 2` NO 0 0
2 3 14 3 test `Ēŕŕőŕ %s` NO 0 0
3 4 15 4 test `Ṽáļũē 3` NO 0 0
4 5 16 5 test `Ṽáļũē 4` NO 0 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

/////////////////////////////////////////////////////////////////////////////
//
// Test Version
//

VS_VERSION_INFO VERSIONINFO
VERSION 1,0,0,1111
PRODUCTVERSION 4,0,0,1111
FILEFLAGSMASK 0x12L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Sample Name", "Sample Name Value"
VALUE "Description", "Good description"
VALUE "Version", "1,0,0,1111"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Alternative", 0x409, 1200
END
END

/////////////////////////////////////////////////////////////////////////////
//
// Test Strings
//

STRINGTABLE
BEGIN
IDS_TEST_1 "Ṽáļũē 1"
IDS_TEST_2 "Ṽáļũē 2"
IDS_ERROR "Ēŕŕőŕ %s"
END

STRINGTABLE
BEGIN
IDS_TEST_3
"Ṽáļũē 3"
IDS_TEST_4 "Ṽáļũē 4"
END
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: test\n"
"Generated-By: Serge 1.3\n"

#. IDS_TEST_1
#: File: application.rc
#: ID: 52b8425aa485a7e3b7a02e1b586f9cef
msgid "Value 1"
msgstr "Ṽáļũē 1"

#. IDS_TEST_2
#: File: application.rc
#: ID: 3fa07f98de1fb810037bfde267c704d1
msgid "Value 2"
msgstr "Ṽáļũē 2"

#. IDS_ERROR
#: File: application.rc
#: ID: 062f9dcbf9d6b396c1733a30e68226ab
msgid "Error %s"
msgstr "Ēŕŕőŕ %s"

#. IDS_TEST_3
#: File: application.rc
#: ID: 2e920fe719df0296f38564a3a624f4fa
msgid "Value 3"
msgstr "Ṽáļũē 3"

#. IDS_TEST_4
#: File: application.rc
#: ID: bf5a11014de06a379dcb4fda0faa156d
msgid "Value 4"
msgstr "Ṽáļũē 4"
5 changes: 3 additions & 2 deletions t/importer.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ $| = 1; # disable output buffering

# to get the same results between tests,
# we override the `file_mtime` function to return a constant value;
# Serge::Importer automatically imports this function from Serge::Util
# Serge::Engine automatically imports this function from Serge::Util
# (this is why it actually appears in Serge::Importer namespace)
sub Serge::Importer::file_mtime {
sub Serge::Engine::file_mtime {
return 12345678;
}

Expand Down Expand Up @@ -112,6 +112,7 @@ for my $config_file (@importer_confs) {
foreach my $job_data (@{$cfg->{data}->{jobs}}) {
my $job;

$engine->{debug} = $job_data->{debug};
eval {
$job = Serge::Engine::Job->new($job_data, $engine, $cfg->{base_dir});
$engine->process_job($job);
Expand Down

0 comments on commit 2b70f1e

Please sign in to comment.