testability-driver 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- data/bin/start_app_perf +199 -0
- data/bin/tdriver-devtools +3 -0
- data/config/sut_parameters.rb +39 -0
- data/ext/extconf.rb +67 -0
- data/ext/native_extensions.c +70 -0
- data/lib/matti.rb +30 -0
- data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +223 -0
- data/lib/tdriver-devtools/behaviour/old/xml/example/impl.rb_invalid +194 -0
- data/lib/tdriver-devtools/behaviour/old/xml/generate_behaviour_xml.rb +95 -0
- data/lib/tdriver-devtools/behaviour/old/xml/lib/tdriver_generator.rb +722 -0
- data/lib/tdriver-devtools/behaviour/old/xml/qdoc_generator.rb +321 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.method.template +43 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.module.template +54 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument.template +7 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument_type.template +7 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.exception.template +5 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.line.template +2 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.template +5 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.method.template +23 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/behaviour/old/xml/update +3 -0
- data/lib/tdriver-devtools/behaviour/xml/generate.rb +88 -0
- data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +1924 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.default.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument_type.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.exception.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.arguments.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.deprecated.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.exceptions.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.info.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.returns.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.tables.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.template +12 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.returns.template +5 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.item.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.row.template +2 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.template +8 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/example/flick-example.rb +245 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/example/sut.rb +964 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/generate.rb +68 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/lib/custom_rdoc_generator.rb +1865 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.default.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument_type.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.exception.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.arguments.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.deprecated.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.exceptions.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.info.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.returns.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.tables.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.template +12 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.returns.template +5 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.item.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.row.template +2 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.template +7 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/update +3 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/QtExampleGestureBehaviour.xml +138 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/created.rid +1 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/tdriver.hash +1 -0
- data/lib/tdriver-devtools/doc/feature_xml/qt_widget_hold.feature.xml +9 -0
- data/lib/tdriver-devtools/doc/feature_xml/qt_widget_tap.feature.xml +9 -0
- data/lib/tdriver-devtools/doc/generate.rb +892 -0
- data/lib/tdriver-devtools/doc/update +1 -0
- data/lib/tdriver-devtools/doc/xslt/html.rb +7 -0
- data/lib/tdriver-devtools/doc/xslt/template.xsl +1861 -0
- data/lib/tdriver-devtools/doc/xslt/update +3 -0
- data/lib/tdriver-devtools/plugin/placeholder.txt +1 -0
- data/lib/tdriver-devtools/tdriver-devtools.rb +404 -0
- data/lib/tdriver-devtools/tests/feature_tests/example/flick-example.rb +233 -0
- data/lib/tdriver-devtools/tests/feature_tests/example/impl.rb +194 -0
- data/lib/tdriver-devtools/tests/feature_tests/generate.rb +82 -0
- data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +468 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/feature_attribute.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/feature_method.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_attribute.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_method.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/update +3 -0
- data/lib/tdriver.rb +26 -0
- data/lib/tdriver/base/behaviour/behaviour.rb +32 -0
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +94 -0
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +262 -0
- data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +111 -0
- data/lib/tdriver/base/behaviour/factory.rb +380 -0
- data/lib/tdriver/base/behaviour/loader.rb +28 -0
- data/lib/tdriver/base/command_data/command_data.rb +51 -0
- data/lib/tdriver/base/command_data/loader.rb +25 -0
- data/lib/tdriver/base/errors.rb +131 -0
- data/lib/tdriver/base/loader.rb +38 -0
- data/lib/tdriver/base/state_object.rb +270 -0
- data/lib/tdriver/base/sut/adapter.rb +28 -0
- data/lib/tdriver/base/sut/controller.rb +119 -0
- data/lib/tdriver/base/sut/factory.rb +287 -0
- data/lib/tdriver/base/sut/generic/behaviours/application.rb +243 -0
- data/lib/tdriver/base/sut/generic/behaviours/controller.rb +67 -0
- data/lib/tdriver/base/sut/generic/behaviours/find.rb +96 -0
- data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +346 -0
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +1268 -0
- data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +182 -0
- data/lib/tdriver/base/sut/generic/behaviours/verification.rb +119 -0
- data/lib/tdriver/base/sut/generic/commands/application.rb +219 -0
- data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +82 -0
- data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +58 -0
- data/lib/tdriver/base/sut/generic/plugin.rb +96 -0
- data/lib/tdriver/base/sut/loader.rb +35 -0
- data/lib/tdriver/base/sut/sut.rb +67 -0
- data/lib/tdriver/base/test_object/abstract.rb +179 -0
- data/lib/tdriver/base/test_object/behaviours/syncronization.rb +94 -0
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +787 -0
- data/lib/tdriver/base/test_object/factory.rb +618 -0
- data/lib/tdriver/base/test_object/identificator.rb +511 -0
- data/lib/tdriver/base/test_object/loader.rb +37 -0
- data/lib/tdriver/env.rb +21 -0
- data/lib/tdriver/loader.rb +36 -0
- data/lib/tdriver/matti.rb +35 -0
- data/lib/tdriver/report/error_recovery/tdriver_custom_error_recovery.rb +83 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +158 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +98 -0
- data/lib/tdriver/report/report.rb +47 -0
- data/lib/tdriver/report/report_api.rb +207 -0
- data/lib/tdriver/report/report_combine.rb +86 -0
- data/lib/tdriver/report/report_crash_file_capture.rb +167 -0
- data/lib/tdriver/report/report_creator.rb +571 -0
- data/lib/tdriver/report/report_cucumber.rb +158 -0
- data/lib/tdriver/report/report_cucumber_listener.rb +337 -0
- data/lib/tdriver/report/report_cucumber_reporter.rb +335 -0
- data/lib/tdriver/report/report_data_presentation.rb +152 -0
- data/lib/tdriver/report/report_data_table.rb +64 -0
- data/lib/tdriver/report/report_execution_statistics.rb +284 -0
- data/lib/tdriver/report/report_file_capture.rb +159 -0
- data/lib/tdriver/report/report_grouping.rb +539 -0
- data/lib/tdriver/report/report_junit_xml.rb +147 -0
- data/lib/tdriver/report/report_rspec.rb +108 -0
- data/lib/tdriver/report/report_test_case_run.rb +621 -0
- data/lib/tdriver/report/report_test_run.rb +1286 -0
- data/lib/tdriver/report/report_test_unit.rb +175 -0
- data/lib/tdriver/report/report_writer.rb +1405 -0
- data/lib/tdriver/tdriver.rb +158 -0
- data/lib/tdriver/util/common.rb +24 -0
- data/lib/tdriver/util/common/array.rb +39 -0
- data/lib/tdriver/util/common/crc16.rb +100 -0
- data/lib/tdriver/util/common/environment.rb +153 -0
- data/lib/tdriver/util/common/error.rb +39 -0
- data/lib/tdriver/util/common/file.rb +315 -0
- data/lib/tdriver/util/common/gem.rb +108 -0
- data/lib/tdriver/util/common/kernel.rb +189 -0
- data/lib/tdriver/util/common/loader.rb +39 -0
- data/lib/tdriver/util/common/retryable.rb +98 -0
- data/lib/tdriver/util/common/string.rb +77 -0
- data/lib/tdriver/util/dbaccess/dbaccess.rb +188 -0
- data/lib/tdriver/util/dbaccess/dbconnection.rb +41 -0
- data/lib/tdriver/util/dbaccess/error.rb +35 -0
- data/lib/tdriver/util/dbaccess/loader.rb +29 -0
- data/lib/tdriver/util/dynamic_attribute_filter.rb +182 -0
- data/lib/tdriver/util/hooking.rb +434 -0
- data/lib/tdriver/util/loader.rb +65 -0
- data/lib/tdriver/util/localisation.rb +24 -0
- data/lib/tdriver/util/localisation/error.rb +32 -0
- data/lib/tdriver/util/localisation/loader.rb +28 -0
- data/lib/tdriver/util/localisation/localisation.rb +479 -0
- data/lib/tdriver/util/logger.rb +377 -0
- data/lib/tdriver/util/operator_data/error.rb +29 -0
- data/lib/tdriver/util/operator_data/loader.rb +26 -0
- data/lib/tdriver/util/operator_data/operator_data.rb +93 -0
- data/lib/tdriver/util/other/config.rb +221 -0
- data/lib/tdriver/util/parameter.rb +24 -0
- data/lib/tdriver/util/parameter/error.rb +45 -0
- data/lib/tdriver/util/parameter/loader.rb +37 -0
- data/lib/tdriver/util/parameter/parameter.rb +285 -0
- data/lib/tdriver/util/parameter/parameter_hash.rb +101 -0
- data/lib/tdriver/util/parameter/parameter_template.rb +120 -0
- data/lib/tdriver/util/parameter/parameter_user_api.rb +84 -0
- data/lib/tdriver/util/parameter/parameter_xml.rb +247 -0
- data/lib/tdriver/util/plugin/abstract.rb +60 -0
- data/lib/tdriver/util/plugin/error.rb +25 -0
- data/lib/tdriver/util/plugin/loader.rb +28 -0
- data/lib/tdriver/util/plugin/service.rb +200 -0
- data/lib/tdriver/util/recorder.rb +292 -0
- data/lib/tdriver/util/stats.rb +90 -0
- data/lib/tdriver/util/user_data/error.rb +29 -0
- data/lib/tdriver/util/user_data/loader.rb +26 -0
- data/lib/tdriver/util/user_data/user_data.rb +103 -0
- data/lib/tdriver/util/video_rec.rb +264 -0
- data/lib/tdriver/util/xml/abstraction.rb +47 -0
- data/lib/tdriver/util/xml/builder.rb +54 -0
- data/lib/tdriver/util/xml/document.rb +32 -0
- data/lib/tdriver/util/xml/element.rb +32 -0
- data/lib/tdriver/util/xml/error.rb +46 -0
- data/lib/tdriver/util/xml/loader.rb +46 -0
- data/lib/tdriver/util/xml/nil_element.rb +89 -0
- data/lib/tdriver/util/xml/nodeset.rb +32 -0
- data/lib/tdriver/util/xml/parsers/libxml/libxml.rb +140 -0
- data/lib/tdriver/util/xml/parsers/loader.rb +22 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +111 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +54 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +58 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +58 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +147 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +42 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +187 -0
- data/lib/tdriver/util/xml/xml.rb +170 -0
- data/lib/tdriver/verify/verify.rb +687 -0
- data/lib/tdriver/verify/verify.rb_org +630 -0
- data/lib/tdriver/version.rb +21 -0
- data/xml/behaviours/generic.xml +495 -0
- data/xml/defaults/generic.xml +97 -0
- data/xml/defaults/sut_generic.xml +36 -0
- data/xml/parameters/tdriver_parameters.xml +23 -0
- data/xml/templates/generic.xml +227 -0
- metadata +327 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
############################################################################
|
2
|
+
##
|
3
|
+
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
## All rights reserved.
|
5
|
+
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
+
##
|
7
|
+
## This file is part of Testability Driver.
|
8
|
+
##
|
9
|
+
## If you have questions regarding the use of this file, please contact
|
10
|
+
## Nokia at testabilitydriver@nokia.com .
|
11
|
+
##
|
12
|
+
## This library is free software; you can redistribute it and/or
|
13
|
+
## modify it under the terms of the GNU Lesser General Public
|
14
|
+
## License version 2.1 as published by the Free Software Foundation
|
15
|
+
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
+
## of this file.
|
17
|
+
##
|
18
|
+
############################################################################
|
19
|
+
|
20
|
+
|
21
|
+
require 'singleton'
|
22
|
+
require 'rubygems'
|
23
|
+
|
24
|
+
# Hooking module - should be loaded first due to above modules uses its functions
|
25
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'hooking.rb' ) )
|
26
|
+
|
27
|
+
# generic/common utility modules
|
28
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'common/loader.rb' ) )
|
29
|
+
|
30
|
+
# Logger module
|
31
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'logger.rb' ) )
|
32
|
+
|
33
|
+
# Parameter modules
|
34
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'xml/loader.rb' ) )
|
35
|
+
|
36
|
+
# Statistics module
|
37
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'stats.rb' ) )
|
38
|
+
|
39
|
+
# Dynamic attribute filter module
|
40
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'dynamic_attribute_filter' ) )
|
41
|
+
|
42
|
+
# Plugin service & abstract class
|
43
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'plugin/loader.rb' ) )
|
44
|
+
|
45
|
+
# Parameter modules
|
46
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter/loader.rb' ) )
|
47
|
+
|
48
|
+
# DBAccess module
|
49
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'dbaccess/loader.rb' ) )
|
50
|
+
|
51
|
+
# Localisation module
|
52
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'localisation/loader.rb' ) )
|
53
|
+
|
54
|
+
# User Data module
|
55
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'user_data/loader.rb' ) )
|
56
|
+
|
57
|
+
# Operator Data module
|
58
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'operator_data/loader.rb' ) )
|
59
|
+
|
60
|
+
# Recorder module
|
61
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'recorder.rb' ) )
|
62
|
+
|
63
|
+
# Video rec module
|
64
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'video_rec.rb' ) )
|
65
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
############################################################################
|
2
|
+
##
|
3
|
+
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
## All rights reserved.
|
5
|
+
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
+
##
|
7
|
+
## This file is part of Testability Driver.
|
8
|
+
##
|
9
|
+
## If you have questions regarding the use of this file, please contact
|
10
|
+
## Nokia at testabilitydriver@nokia.com .
|
11
|
+
##
|
12
|
+
## This library is free software; you can redistribute it and/or
|
13
|
+
## modify it under the terms of the GNU Lesser General Public
|
14
|
+
## License version 2.1 as published by the Free Software Foundation
|
15
|
+
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
+
## of this file.
|
17
|
+
##
|
18
|
+
############################################################################
|
19
|
+
|
20
|
+
|
21
|
+
STDOUT.puts "Please require 'util/localisation/loader.rb' instead of 'util/localisation.rb'"
|
22
|
+
|
23
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'localisation/loader.rb' ) )
|
24
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
############################################################################
|
2
|
+
##
|
3
|
+
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
## All rights reserved.
|
5
|
+
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
+
##
|
7
|
+
## This file is part of Testability Driver.
|
8
|
+
##
|
9
|
+
## If you have questions regarding the use of this file, please contact
|
10
|
+
## Nokia at testabilitydriver@nokia.com .
|
11
|
+
##
|
12
|
+
## This library is free software; you can redistribute it and/or
|
13
|
+
## modify it under the terms of the GNU Lesser General Public
|
14
|
+
## License version 2.1 as published by the Free Software Foundation
|
15
|
+
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
+
## of this file.
|
17
|
+
##
|
18
|
+
############################################################################
|
19
|
+
|
20
|
+
|
21
|
+
module MobyUtil
|
22
|
+
|
23
|
+
# This error should be raised when referred language is not found
|
24
|
+
class LanguageNotFoundError < CustomError; end;
|
25
|
+
|
26
|
+
# This error should be raised when referred table is not found
|
27
|
+
class TableNotFoundError < CustomError; end;
|
28
|
+
|
29
|
+
# This error should be raised when referred logical name is not found for specified language
|
30
|
+
class LogicalNameNotFoundError < CustomError; end;
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
############################################################################
|
2
|
+
##
|
3
|
+
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
## All rights reserved.
|
5
|
+
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
+
##
|
7
|
+
## This file is part of Testability Driver.
|
8
|
+
##
|
9
|
+
## If you have questions regarding the use of this file, please contact
|
10
|
+
## Nokia at testabilitydriver@nokia.com .
|
11
|
+
##
|
12
|
+
## This library is free software; you can redistribute it and/or
|
13
|
+
## modify it under the terms of the GNU Lesser General Public
|
14
|
+
## License version 2.1 as published by the Free Software Foundation
|
15
|
+
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
+
## of this file.
|
17
|
+
##
|
18
|
+
############################################################################
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
# localisation related errors
|
24
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'error.rb' ) )
|
25
|
+
|
26
|
+
# localisation module implementation
|
27
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), 'localisation.rb' ) )
|
28
|
+
|
@@ -0,0 +1,479 @@
|
|
1
|
+
############################################################################
|
2
|
+
##
|
3
|
+
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
## All rights reserved.
|
5
|
+
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
+
##
|
7
|
+
## This file is part of Testability Driver.
|
8
|
+
##
|
9
|
+
## If you have questions regarding the use of this file, please contact
|
10
|
+
## Nokia at testabilitydriver@nokia.com .
|
11
|
+
##
|
12
|
+
## This library is free software; you can redistribute it and/or
|
13
|
+
## modify it under the terms of the GNU Lesser General Public
|
14
|
+
## License version 2.1 as published by the Free Software Foundation
|
15
|
+
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
+
## of this file.
|
17
|
+
##
|
18
|
+
############################################################################
|
19
|
+
|
20
|
+
require 'nokogiri'
|
21
|
+
|
22
|
+
# Utility for handling localisation database
|
23
|
+
|
24
|
+
module MobyUtil
|
25
|
+
|
26
|
+
class Localisation
|
27
|
+
|
28
|
+
# == description
|
29
|
+
# Function to fetch a translation for a given logical name from the localisation DB
|
30
|
+
#
|
31
|
+
# == arguments
|
32
|
+
# logical_name
|
33
|
+
# String
|
34
|
+
# description: Logical name (LNAME) of the item to be translated. If prefix for User Information or Operator Data are used then the appropiate retrieve methods will be called
|
35
|
+
# example: "txt_button_ok"
|
36
|
+
# Symbol
|
37
|
+
# description: Symbol form of the logical name (LNAME) of the item to be translated.
|
38
|
+
# example: :txt_button_ok
|
39
|
+
#
|
40
|
+
# language
|
41
|
+
# String
|
42
|
+
# description: Name of the language column to be used. This is normally the language code found on the .ts or .qm translation files
|
43
|
+
# example: "en"
|
44
|
+
#
|
45
|
+
# table_name
|
46
|
+
# String
|
47
|
+
# description: Name of the translation table to use from the localisation DB
|
48
|
+
# example: "B10_1_week201042_loc"
|
49
|
+
#
|
50
|
+
# file_name
|
51
|
+
# String
|
52
|
+
# description: Optional FNAME search argument for the translation. The FNAME column stores the application name that the translation belongs to
|
53
|
+
# example: "calendar"
|
54
|
+
#
|
55
|
+
# plurality
|
56
|
+
# String
|
57
|
+
# description: Optional PLURALITY search argument for the translation
|
58
|
+
# example: "a" or "singular"
|
59
|
+
#
|
60
|
+
# lengthvariant
|
61
|
+
# String
|
62
|
+
# description: Optional LENGTHVAR search argument for the translation (1-9)
|
63
|
+
# example: "1"
|
64
|
+
#
|
65
|
+
# == returns
|
66
|
+
# String
|
67
|
+
# description: Translation matching the logical_name
|
68
|
+
# example: "Ok"
|
69
|
+
# Array
|
70
|
+
# description: If multiple translations have been found for the search conditions an Array with all Strings be returned
|
71
|
+
# example: ["Ok", "OK"]
|
72
|
+
#
|
73
|
+
# == exceptions
|
74
|
+
# LanguageNotFoundError
|
75
|
+
# description: In case language is not found
|
76
|
+
#
|
77
|
+
# LogicalNameNotFoundError
|
78
|
+
# description: In case no logical name is not found for current language
|
79
|
+
#
|
80
|
+
# TableNotFoundError
|
81
|
+
# description: If the table name argument is not valid
|
82
|
+
#
|
83
|
+
# SqlError
|
84
|
+
# description: In case there are problems with the database connectivity
|
85
|
+
#
|
86
|
+
def self.translation( logical_name, language, table_name, file_name = nil , plurality = nil, lengthvariant = nil )
|
87
|
+
|
88
|
+
Kernel::raise LogicalNameNotFoundError.new( "Logical name cannot be nil" ) if logical_name == nil
|
89
|
+
Kernel::raise LanguageNotFoundError.new( "Language cannot be nil" ) if language == nil
|
90
|
+
Kernel::raise TableNotFoundError.new( "Table name cannot be nil" ) if table_name == nil
|
91
|
+
|
92
|
+
# Avoid system column names for language columns and user only downcase
|
93
|
+
language = language.to_s.downcase
|
94
|
+
if language.eql? "id" or language.eql? "fname" or language.eql? "lname" or language.eql? "plurality" or language.eql? "lengthvar"
|
95
|
+
language += "_"
|
96
|
+
end
|
97
|
+
|
98
|
+
db_type = MobyUtil::Parameter[ :localisation_db_type, nil ]
|
99
|
+
host = MobyUtil::Parameter[ :localisation_server_ip ]
|
100
|
+
username = MobyUtil::Parameter[ :localisation_server_username ]
|
101
|
+
password = MobyUtil::Parameter[ :localisation_server_password ]
|
102
|
+
database_name = MobyUtil::Parameter[ :localisation_server_database_name ]
|
103
|
+
|
104
|
+
db_connection = DBConnection.new( db_type, host, database_name, username, password )
|
105
|
+
|
106
|
+
query_string = "select `#{ language }` from #{ table_name } where lname = '#{ logical_name }'"
|
107
|
+
query_string += " and `FNAME` = '#{ file_name }'" unless file_name.nil?
|
108
|
+
query_string += " and `PLURALITY` = '#{ plurality }'" unless plurality.nil?
|
109
|
+
query_string += " and `LENGTHVAR` = '#{ lengthvariant }'" unless lengthvariant.nil?
|
110
|
+
query_string += " and `#{ language }` <> \'#MISSING\'"
|
111
|
+
|
112
|
+
begin
|
113
|
+
# Returns a uniform set of results as an array of rows, rows beeing an array of values ( Array<Array<String>> )
|
114
|
+
result = MobyUtil::DBAccess.query( db_connection, query_string )
|
115
|
+
rescue
|
116
|
+
# if column referring to language is not found then Kernel::raise error for language not found
|
117
|
+
Kernel::raise LanguageNotFoundError.new( "No language '#{ language }' found" ) unless $!.message.index( "Unknown column" ) == nil
|
118
|
+
Kernel::raise SqlError.new( $!.message )
|
119
|
+
end
|
120
|
+
|
121
|
+
# Return only the first column of the row or and array of the values of the first column if multiple rows have been found
|
122
|
+
Kernel::raise LogicalNameNotFoundError.new( "No translation found for logical name '#{ logical_name }' in language '#{ language }' with given plurality and lengthvariant." ) if ( result.empty?)
|
123
|
+
if result.length > 1
|
124
|
+
# Result is an Array of rows (Array<String>)! We want the first column of each row.
|
125
|
+
result_array = Array.new
|
126
|
+
result.each do |row|
|
127
|
+
result_array << row[0]
|
128
|
+
end
|
129
|
+
return result_array
|
130
|
+
else
|
131
|
+
# Result is an Array of rows (Array<String>)! We want the first column of the first row.
|
132
|
+
return result[0][0]
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
# == description
|
138
|
+
# Function upload translations in a given Qt Linguist translation file to the localisation DB
|
139
|
+
#
|
140
|
+
# == arguments
|
141
|
+
# file
|
142
|
+
# String
|
143
|
+
# description: Path to Qt Linguist translation file to upload. Both .ts and .qm files are allowed.
|
144
|
+
# example: "accessories_ar.ts"
|
145
|
+
#
|
146
|
+
# table_name
|
147
|
+
# String
|
148
|
+
# description: Name of the translation table to use form the localisation DB
|
149
|
+
# example: "B10_1_week201042_loc"
|
150
|
+
#
|
151
|
+
# db_connection
|
152
|
+
# MobyUtil::DBConnection
|
153
|
+
# description: A DBConnection object contains all the connection details required to connect to a SQL DB (mysql or sqlite)
|
154
|
+
# example: "MobyUtil::DBConnection.new('mysql', '192.168.0.1', 'tdriver_locale', 'username', 'password')"
|
155
|
+
#
|
156
|
+
# column_names_map
|
157
|
+
# Hash
|
158
|
+
# description: Hash with the language codes from the translation files as keys and the desired column names as values
|
159
|
+
# example: {"en" => "en_GB"}
|
160
|
+
#
|
161
|
+
# record_sql
|
162
|
+
# Bool
|
163
|
+
# description: When this flag is set to true then
|
164
|
+
# example: true
|
165
|
+
#
|
166
|
+
# == returns
|
167
|
+
#
|
168
|
+
# == throws
|
169
|
+
# ArgumentError
|
170
|
+
# description: When arguments provided are not valid
|
171
|
+
#
|
172
|
+
# Exception
|
173
|
+
# description: When its not possible to parse the file provided
|
174
|
+
#
|
175
|
+
def self.upload_translation_file( file, table_name, db_connection = nil, column_names_map = {}, record_sql = false)
|
176
|
+
Kernel::raise ArgumentError.new("") if file.nil? or file.empty?
|
177
|
+
Kernel::raise ArgumentError.new("") if table_name.nil? or table_name.empty?
|
178
|
+
|
179
|
+
# Get a connection to the DB
|
180
|
+
if db_connection.nil? or !db_connection.kind_of? MobyUtil::DBConnection
|
181
|
+
db_type = MobyUtil::Parameter[ :localisation_db_type ]
|
182
|
+
host = MobyUtil::Parameter[ :localisation_server_ip ]
|
183
|
+
database_name = MobyUtil::Parameter[ :localisation_server_database_name ]
|
184
|
+
username = MobyUtil::Parameter[ :localisation_server_username ]
|
185
|
+
password = MobyUtil::Parameter[ :localisation_server_password ]
|
186
|
+
|
187
|
+
db_connection = DBConnection.new( db_type, host, database_name, username, password )
|
188
|
+
end
|
189
|
+
# Check File and convert to TS File if needed
|
190
|
+
tsFile = MobyUtil::Localisation.convert_to_ts( file )
|
191
|
+
Kernel::raise Exception.new("Failed to convert #{file} to .ts") if tsFile == nil
|
192
|
+
# Collect data for INSERT query from TS File
|
193
|
+
language, data = MobyUtil::Localisation.parse_ts_file( tsFile, column_names_map )
|
194
|
+
Kernel::raise Exception.new("Error while parsing #{file}.") if language == nil or data == ""
|
195
|
+
# Upload language data to DB for current language file
|
196
|
+
MobyUtil::Localisation.upload_ts_data( language, data, table_name, db_connection, record_sql )
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
private
|
202
|
+
|
203
|
+
|
204
|
+
# == description
|
205
|
+
# Checks Qt Linguist translation file for validity and converts to TS if needed
|
206
|
+
#
|
207
|
+
# == arguments
|
208
|
+
# file
|
209
|
+
# String
|
210
|
+
# description: Name (and path) of the Qt Linguist translation file (.ts or .qm)
|
211
|
+
# example: "calendar.qm"
|
212
|
+
#
|
213
|
+
# == returns
|
214
|
+
# String
|
215
|
+
# description: Name (and path) of the checked and maybe converted .ts Qt Linguist translation file
|
216
|
+
#
|
217
|
+
# == throws
|
218
|
+
#
|
219
|
+
def self.convert_to_ts(file)
|
220
|
+
if !File.exists?(file)
|
221
|
+
puts "[WARNING] File '" + file + "' not found. Skiping."
|
222
|
+
file = nil
|
223
|
+
elsif (nil == file.match(/.*\.ts/) and nil == file.match(/.*\.qm/) )
|
224
|
+
puts "[WARNING] Unknown file extension. Skiping. \n\n" + file
|
225
|
+
file = nil
|
226
|
+
elsif ( match = file.match(/(.*)\.qm/) )
|
227
|
+
if(! system "lconvert -o " + match[1] + ".ts " + file )
|
228
|
+
puts "[ERROR] lconvert can't convert .qm file to .ts. Skiping. \n\n" + match[0]
|
229
|
+
return nil
|
230
|
+
end
|
231
|
+
file = match[1] + ".ts"
|
232
|
+
end
|
233
|
+
file
|
234
|
+
end
|
235
|
+
|
236
|
+
|
237
|
+
# == description
|
238
|
+
# Extracts translation data from TS file
|
239
|
+
#
|
240
|
+
# == arguments
|
241
|
+
# file
|
242
|
+
# String
|
243
|
+
# description: Name (and path) of the Qt Linguist translation file (.ts or .qm)
|
244
|
+
# example: "calendar.qm"
|
245
|
+
#
|
246
|
+
# column_names_map
|
247
|
+
# Hash
|
248
|
+
# description: Hash with the language codes from the translation files as keys and the desired column names as values
|
249
|
+
# example: {"en" => "en_GB"}
|
250
|
+
#
|
251
|
+
# == returns
|
252
|
+
# String
|
253
|
+
# description: Name (and path) of the checked and maybe converted .ts Qt Linguist translation file
|
254
|
+
#
|
255
|
+
# Array
|
256
|
+
# description: Two dimentional Array with columns [ FNAME, Source, Translation, Plurality, Lengthvariant Priority ]
|
257
|
+
#
|
258
|
+
# == throws
|
259
|
+
#
|
260
|
+
def self.parse_ts_file(file, column_names_map = {} )
|
261
|
+
# Read TS file
|
262
|
+
open_file = File.new( file )
|
263
|
+
doc = Nokogiri.XML( open_file )
|
264
|
+
language = doc.xpath('.//TS').attribute("language")
|
265
|
+
# IF filename-to-columnname mapping is provided update language
|
266
|
+
fname = parseFName(file)
|
267
|
+
if (!column_names_map.empty?)
|
268
|
+
language_code = file.split('/').last.gsub(fname + "_" ){|s| ""}.gsub(".ts"){|s| ""}
|
269
|
+
language = column_names_map[ language_code ] if column_names_map.key?( language_code )
|
270
|
+
end
|
271
|
+
if (language == nil)
|
272
|
+
puts "[WARNING] The input file is missing the language attribute on it's <TS> element. Skiping. \n\n"
|
273
|
+
return nil, nil
|
274
|
+
end
|
275
|
+
# Collect data for INSERT query
|
276
|
+
data = []
|
277
|
+
doc.xpath('.//message').each do |node|
|
278
|
+
begin
|
279
|
+
nodeId = ""
|
280
|
+
nodeTranslation = ""
|
281
|
+
nodePlurality = ""
|
282
|
+
nodeLengthVar = ""
|
283
|
+
# set nodeId
|
284
|
+
#raise Exception if node.xpath('@id').inner_text() == ""
|
285
|
+
if node.xpath('@id').inner_text() != ""
|
286
|
+
nodeId = node.xpath('@id').inner_text()
|
287
|
+
else
|
288
|
+
nodeId = node.xpath('.//source').inner_text()
|
289
|
+
end
|
290
|
+
# Parse Numerus(LengthVar), or Numerus or LengthVar or translation direclty
|
291
|
+
if ! node.xpath('.//translation/numerusform').empty?
|
292
|
+
# puts ">>> Numerusform"
|
293
|
+
node.xpath('.//translation/numerusform').each do |numerus|
|
294
|
+
nodePlurality = numerus.xpath('@plurality').inner_text()
|
295
|
+
if ! numerus.xpath('.//lengthvariant').empty?
|
296
|
+
# puts " >>> Lengthvar"
|
297
|
+
numerus.xpath('.//lengthvariant').each do |lenghtvar|
|
298
|
+
nodeLengthVar = lenghtvar.xpath('@priority').inner_text()
|
299
|
+
nodeTranslation = lenghtvar.inner_text()
|
300
|
+
data << [ fname, nodeId, nodeTranslation, nodePlurality, nodeLengthVar ]
|
301
|
+
end
|
302
|
+
else
|
303
|
+
nodeTranslation = numerus.inner_text()
|
304
|
+
data << [ fname, nodeId, nodeTranslation, nodePlurality, nodeLengthVar ]
|
305
|
+
end
|
306
|
+
end
|
307
|
+
elsif ! node.xpath('.//translation/lengthvariant').empty?
|
308
|
+
# puts ">>> Lengthvar"
|
309
|
+
priority = 1
|
310
|
+
node.xpath('.//translation/lengthvariant').each do |lenghtvar|
|
311
|
+
nodeLengthVar = lenghtvar.xpath('@priority').inner_text()
|
312
|
+
nodeLengthVar = priority.to_s if nodeLengthVar.empty?
|
313
|
+
nodeTranslation = lenghtvar.inner_text()
|
314
|
+
data << [ fname, nodeId, nodeTranslation, nodePlurality, nodeLengthVar ]
|
315
|
+
priority += 1
|
316
|
+
end
|
317
|
+
else
|
318
|
+
# puts ">>> Translation"
|
319
|
+
nodeTranslation = node.xpath('.//translation').inner_text()
|
320
|
+
data << [ fname, nodeId, nodeTranslation, nodePlurality, nodeLengthVar ]
|
321
|
+
end
|
322
|
+
rescue Exception # ignores bad elements or elements with empty translations for now
|
323
|
+
end
|
324
|
+
end
|
325
|
+
open_file.close
|
326
|
+
return language, data
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
# == description
|
331
|
+
# Uploads language data to Localisation DB and optionally records the sql queries on a file
|
332
|
+
#
|
333
|
+
def self.upload_ts_data( language, data, table_name, db_connection, record_sql = false )
|
334
|
+
|
335
|
+
raise Exception.new("Language not provided.") if language.nil? or language.to_s.empty?
|
336
|
+
raise Exception.new("No data povided. Please make sure the source of your data is valid.") if data.nil? or data.empty?
|
337
|
+
raise Exception.new("No table name provided.") if table_name.nil? or table_name.empty?
|
338
|
+
raise Exception.new("Invalid connection object provided.") if db_connection.nil? or !db_connection.kind_of? MobyUtil::DBConnection
|
339
|
+
|
340
|
+
# Avoid system column names for language columns and user only downcase
|
341
|
+
language = language.to_s.downcase
|
342
|
+
if language.eql? "id" or language.eql? "fname" or language.eql? "lname" or language.eql? "plurality" or language.eql? "lengthvar"
|
343
|
+
language += "_"
|
344
|
+
end
|
345
|
+
|
346
|
+
sql_file = File.open(table_name + ".#{db_connection.db_type}.sql", 'a') if record_sql
|
347
|
+
|
348
|
+
# CREATE TABLE if doesn't exist (language columns to be created as needed)
|
349
|
+
case db_connection.db_type
|
350
|
+
when "mysql"
|
351
|
+
query_string = "CREATE TABLE IF NOT EXISTS " + table_name + " (
|
352
|
+
`ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
353
|
+
`FNAME` VARCHAR(150) NOT NULL COLLATE latin1_general_ci,
|
354
|
+
`LNAME` VARCHAR(150) NOT NULL COLLATE latin1_general_ci,
|
355
|
+
`PLURALITY` VARCHAR(50) COLLATE latin1_general_ci,
|
356
|
+
`LENGTHVAR` INT(10),
|
357
|
+
PRIMARY KEY (`ID`),
|
358
|
+
UNIQUE INDEX `FileLogicNameIndex` (`FNAME`,`LNAME`, `PLURALITY`, `LENGTHVAR`),
|
359
|
+
INDEX `LNameIndex` (`LNAME`)
|
360
|
+
) COLLATE=utf8_general_ci;"
|
361
|
+
MobyUtil::DBAccess.query( db_connection, query_string )
|
362
|
+
sql_file.write( query_string + "\n" ) if record_sql
|
363
|
+
when "sqlite"
|
364
|
+
query_string = "CREATE TABLE IF NOT EXISTS " + table_name + " (
|
365
|
+
`ID` INTEGER PRIMARY KEY AUTOINCREMENT,
|
366
|
+
`FNAME` VARCHAR(150) NOT NULL,
|
367
|
+
`LNAME` VARCHAR(150) NOT NULL,
|
368
|
+
`PLURALITY` VARCHAR(50),
|
369
|
+
`LENGTHVAR` INT(10));"
|
370
|
+
MobyUtil::DBAccess.query( db_connection, query_string )
|
371
|
+
sql_file.write( query_string + "\n" ) if record_sql
|
372
|
+
|
373
|
+
query_string = "CREATE UNIQUE INDEX IF NOT EXISTS 'FileLogicNameIndex' ON " + table_name + " (`FNAME`,`LNAME`, `PLURALITY`, `LENGTHVAR`);"
|
374
|
+
MobyUtil::DBAccess.query( db_connection, query_string )
|
375
|
+
sql_file.write( query_string + "\n" ) if record_sql
|
376
|
+
|
377
|
+
query_string = "CREATE INDEX IF NOT EXISTS 'FileLogicIndex' ON " + table_name + " (`LNAME`);"
|
378
|
+
MobyUtil::DBAccess.query( db_connection, query_string )
|
379
|
+
sql_file.write( query_string + "\n" ) if record_sql
|
380
|
+
end
|
381
|
+
|
382
|
+
# ADD NEW COLUMNS for new language if needed
|
383
|
+
case db_connection.db_type
|
384
|
+
when "mysql"
|
385
|
+
begin
|
386
|
+
query_string = "ALTER TABLE `" + table_name + "` ADD `" + language + "` VARCHAR(350) NULL DEFAULT NULL COLLATE utf8_general_ci;"
|
387
|
+
MobyUtil::DBAccess.query( db_connection, query_string )
|
388
|
+
sql_file.write( query_string + "\n" ) if record_sql
|
389
|
+
rescue Mysql::Error # catch if language column already exists
|
390
|
+
end
|
391
|
+
when "sqlite"
|
392
|
+
begin
|
393
|
+
query_string = "ALTER TABLE `" + table_name + "` ADD `" + language + "` TEXT;"
|
394
|
+
MobyUtil::DBAccess.query( db_connection, query_string )
|
395
|
+
sql_file.write( query_string + "\n" ) if record_sql
|
396
|
+
rescue SQLite3::SQLException # catch if language column already exists
|
397
|
+
end
|
398
|
+
end
|
399
|
+
# INSERT new data
|
400
|
+
case db_connection.db_type
|
401
|
+
when "mysql"
|
402
|
+
begin
|
403
|
+
# Formatting (seems like there is no length limit for the insert string)
|
404
|
+
insert_values = ""
|
405
|
+
data.each do |fname, source, translation, plurality, lengthvar|
|
406
|
+
# Escape ` and ' and " and other restricted characters in SQL (prevent SQL injections
|
407
|
+
source = source.gsub(/([\'\"\`\;\&])/){|s| "\\" + s}
|
408
|
+
translation = (translation != nil) ? translation.gsub(/([\'\"\`\;\&])/){|s| "\\" + s} : ""
|
409
|
+
insert_values += "('" + fname + "', '" + source + "', '" + translation + "', '" + plurality + "', '" + lengthvar + "'), "
|
410
|
+
end
|
411
|
+
insert_values[-2] = ' ' unless insert_values == "" # replace last ',' with ';'
|
412
|
+
# INSERT Query
|
413
|
+
query_string = "INSERT INTO `" + table_name + "` (FNAME, LNAME, `" + language + "`, `PLURALITY`, `LENGTHVAR`) VALUES " + insert_values +
|
414
|
+
"ON DUPLICATE KEY UPDATE fname = VALUES(fname), lname = VALUES(lname), `" + language + "` = VALUES(`" + language + "`) ;"
|
415
|
+
MobyUtil::DBAccess.query( db_connection, query_string )
|
416
|
+
sql_file.write( query_string + "\n" ) if record_sql
|
417
|
+
rescue Exception => e
|
418
|
+
puts e.inspect
|
419
|
+
puts e.backtrace.join("\n")
|
420
|
+
end
|
421
|
+
when "sqlite"
|
422
|
+
begin
|
423
|
+
# Formatting (limit on the length of the Insert String! So multiple Insets
|
424
|
+
counter = 0
|
425
|
+
cumulated = 0
|
426
|
+
union_all = ""
|
427
|
+
MobyUtil::DBAccess.query( db_connection, "BEGIN TRANSACTION")
|
428
|
+
sql_file.write( "BEGIN TRANSACTION\n" ) if record_sql
|
429
|
+
data.each do |fname, source, translation, plurality, lengthvar|
|
430
|
+
counter += 1
|
431
|
+
cumulated += 1
|
432
|
+
# we MAYBE fucked if the texts have ";" or "`" or """ but for now only "'" seems to be problematic
|
433
|
+
source = source.strip.gsub(/([\'])/){|s| s + s}
|
434
|
+
translation = (translation != nil ) ? translation.strip.gsub(/([\'])/){|s| s + s} : ""
|
435
|
+
### UPDATE OR INSERT IF NO ROWS AFFECTED
|
436
|
+
query_string = "UPDATE `" + table_name + "` SET `#{language}`='#{translation}' WHERE FNAME='#{fname}' AND " +
|
437
|
+
"LNAME='#{source}' AND `PLURALITY`='#{plurality}' AND `LENGTHVAR`='#{lengthvar}';"
|
438
|
+
MobyUtil::DBAccess.query( db_connection, query_string )
|
439
|
+
sql_file.write( query_string + "\n" ) if record_sql
|
440
|
+
if MobyUtil::DBAccess.affected_rows( db_connection ) == 0
|
441
|
+
query_string = "INSERT INTO `" + table_name + "` (FNAME, LNAME, `" + language + "`, `PLURALITY`, `LENGTHVAR`) " +
|
442
|
+
"VALUES ('#{fname}' ,'#{source}','#{translation}', '#{plurality}', '#{lengthvar}');"
|
443
|
+
MobyUtil::DBAccess.query( db_connection, query_string )
|
444
|
+
sql_file.write( query_string + "\n" ) if record_sql
|
445
|
+
end
|
446
|
+
end
|
447
|
+
MobyUtil::DBAccess.query( db_connection, "COMMIT TRANSACTION")
|
448
|
+
sql_file.write( "COMMIT TRANSACTION\n" ) if record_sql
|
449
|
+
rescue Exception => e
|
450
|
+
puts e.inspect
|
451
|
+
puts e.backtrace.join("\n")
|
452
|
+
MobyUtil::DBAccess.query( db_connection, "ROLLBACK TRANSACTION")
|
453
|
+
sql_file.write( "ROLLBACK TRANSACTION\n" ) if record_sql
|
454
|
+
end
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
|
459
|
+
# == description
|
460
|
+
# Extracs application name used for FNAME from a given filename (removes language tags and file extension)
|
461
|
+
#
|
462
|
+
def self.parseFName(file)
|
463
|
+
fname = file.split('/').last
|
464
|
+
#(wordlist matching)
|
465
|
+
words = ["ar", "bg", "ca", "cs", "da", "de", "el", "en", "english-gb", "(apac)", "(apaccn)", "(apachk)", "(apactw)", "japanese", "thai", "us", "es", "419", "et", "eu", "fa", "fi", "fr", "gl", "he", "hi", "hr", "hu", "id", "is", "it", "ja", "ko", "lt", "lv", "mr", "ms", "nb", "nl", "pl", "pt", "br", "ro", "ru", "sk", "sl", "sr", "sv", "th", "tl", "tr", "uk", "ur", "us", "vi", "zh", "hk", "tw", "no"]
|
466
|
+
match = fname.scan(/_([a-zA-Z1-9\-\(\)]*)/)
|
467
|
+
if match
|
468
|
+
match.each do |m|
|
469
|
+
fname.gsub!("_#{m[0]}"){|s| ""} if words.include?( m[0].downcase )
|
470
|
+
end
|
471
|
+
end
|
472
|
+
fname.gsub!(".ts"){|s| ""}
|
473
|
+
return fname #gsub! will return nil if now subs are performed
|
474
|
+
end
|
475
|
+
|
476
|
+
end # class
|
477
|
+
|
478
|
+
end # module
|
479
|
+
|