|
1 # -*- coding: ISO-8859-1 -*- |
|
2 """ |
|
3 /* |
|
4 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
5 * All rights reserved. |
|
6 * This component and the accompanying materials are made available |
|
7 * under the terms of "Eclipse Public License v1.0" |
|
8 * which accompanies this distribution, and is available |
|
9 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
10 * |
|
11 * Initial Contributors: |
|
12 * Nokia Corporation - initial contribution. |
|
13 * |
|
14 * Contributors: |
|
15 * |
|
16 * Description: |
|
17 * Python script that can be used to make localized pkg-files |
|
18 * based on Engineering English pkg-files |
|
19 * |
|
20 */ |
|
21 """ |
|
22 |
|
23 import sys, string |
|
24 |
|
25 LINE_FEED = "\n" |
|
26 INDENTATION = " " |
|
27 |
|
28 # Added to converted file name, so e.g. "filename.pkg" -> filename_loc.pkg" |
|
29 CONVERTED_FILE_NAME_ADDITION = "_loc" |
|
30 # Path identifiers for the paths that include files to be localized |
|
31 PATHS_TO_LOCALIZE = [ "resource\\" ] |
|
32 |
|
33 # Exclude paths of ECom plugin registeration files and extended startup list ctrl files |
|
34 PATHS_TO_EXCLUDE = [ "resource\\plugins\\", "private\\101f875a\\", "resource\\messaging\\", "resource\\fsmailbrandmanager.r", |
|
35 "\\esmragnversit2strings.rsc", "\\esmrurlparserplugindata.rsc", "\\esmrpolicies.rsc", "\\esmralarminfo.rsc", # Non-localized resource files from mrui |
|
36 "\\neascpnodenames.rsc", "\\neasicalstrings.rsc", "\\neasfreestylepluginresource.rsc" ] # Non-localized resource files from eas |
|
37 |
|
38 # File extension identifiers for the files to be localized |
|
39 EXTENSIONS_TO_LOCALIZE = [ ".rsc" ] |
|
40 # Embedded sisx packages to be localized |
|
41 EMBEDDED_PACKAGES_TO_LOCALIZE = [ "eas_engine.sisx", "eas_engine_udeb.sisx" ] |
|
42 EMBEDDED_PACKAGE_LINE_IDENTIFIER = "@" |
|
43 EMBEDDED_PACKAGE_FILE_EXTENSION = ".sisx" |
|
44 |
|
45 # List of language codes |
|
46 # LANGUAGE_CODES = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 25, 26, 27, 28, 29, 30, 31, 32, 33, 37, 39, 42, 44, 45, 49, 50, 51, 54, 57, 58, 59, 67, 68, 70, 76, 78, 79, 83, 93, 94, 129, 157, 158, 159, 160, 161, 326, 327, 401, 402 ] |
|
47 LANGUAGE_CODES = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 25, 26, 27, 28, 29, 30, 31, 32, 33, 37, 39, 42, 44, 45, 49, 50, 51, 54, 57, 59, 67, 68, 70, 76, 78, 79, 83, 93, 94, 96, 102, 103, 129, 157, 158, 159, 160, 161, 326, 327 ] |
|
48 |
|
49 # Comment line added with commented-out engineering english resource file |
|
50 PKG_FILE_COMMENT_LINE_START_TAG = ";" |
|
51 LOCALIZATION_COMMENT_LINE = PKG_FILE_COMMENT_LINE_START_TAG + " Following line is localized, so this Engineering English line is commented out\n" |
|
52 |
|
53 LOCALIZATION_LANG_CODE_IDENTIFIER = "***" |
|
54 LOCALIZATION_LANG_CODE_BLOCK_START_LINE = 'IF EXISTS( "z:\\resource\\avkon.r' + LOCALIZATION_LANG_CODE_IDENTIFIER + '" )' + LINE_FEED |
|
55 LOCALIZATION_LANG_CODE_BLOCK_END_LINE = 'ENDIF' + LINE_FEED + LINE_FEED |
|
56 |
|
57 # Identifier to identify the line of the starter app, which needs to be the last item in pkg file |
|
58 STARTER_APP_IDENTIFIER = "sys\\bin\\emailservermonitor.exe" |
|
59 |
|
60 HELP_TEXT0 = "Python script that can be used to generate localized pkg-file based on engineering English pkg-file.\nIt converts e.g. all *.rsc file names in input file to *.r01, *.r02, *.r03 etc. file names.\n" |
|
61 HELP_TEXT1 = "Usage:\n " |
|
62 HELP_TEXT2 = " engineering_english_to_convert.pkg\n" |
|
63 HELP_TEXT3 = "Output file name format:\n engineering_english_to_convert" |
|
64 HELP_TEXT4 = ".pkg\n" |
|
65 |
|
66 ########################################################################## |
|
67 # MAIN |
|
68 # |
|
69 def main(): |
|
70 if( len(sys.argv) == 1 ): |
|
71 ind = sys.argv[0].rfind( "\\" ) |
|
72 if( ind >= 0 and len(sys.argv[0]) >= ind+2 ): |
|
73 script_file = sys.argv[0][ind+1:] |
|
74 else: |
|
75 script_file = sys.argv[0] |
|
76 |
|
77 print HELP_TEXT0 |
|
78 print HELP_TEXT1 + script_file + HELP_TEXT2 |
|
79 print HELP_TEXT3 + CONVERTED_FILE_NAME_ADDITION + HELP_TEXT4 |
|
80 return |
|
81 |
|
82 files = sys.argv[1:] |
|
83 for file_name in files: |
|
84 ConvertFile( file_name ) |
|
85 |
|
86 return |
|
87 |
|
88 |
|
89 def ConstructLocalizedLines( lines_to_localize, converted_lines ): |
|
90 for lang_code in LANGUAGE_CODES: |
|
91 lang_code = str( lang_code ) |
|
92 lang_code = lang_code.zfill(2) |
|
93 |
|
94 start_line = LOCALIZATION_LANG_CODE_BLOCK_START_LINE |
|
95 converted_lines.append( start_line.replace( LOCALIZATION_LANG_CODE_IDENTIFIER, lang_code ) ) |
|
96 |
|
97 for line in lines_to_localize: |
|
98 extension = line[1] |
|
99 line = line[0] |
|
100 converted_lines.append( INDENTATION + line.replace( extension, extension[0:2] + lang_code ) ) |
|
101 |
|
102 converted_lines.append( LOCALIZATION_LANG_CODE_BLOCK_END_LINE ) |
|
103 |
|
104 return |
|
105 |
|
106 |
|
107 def DivideConvertedLines( converted ): |
|
108 footer = [] |
|
109 |
|
110 starter_app_found = False |
|
111 i = len( converted ) - 1 |
|
112 while( i >= 0 ): |
|
113 line = converted[i] |
|
114 # Append all files below STARTER_APP_IDENTIFIER to footer, including |
|
115 # also the line where STARTER_APP_IDENTIFIER is found |
|
116 if not( starter_app_found ): |
|
117 footer.insert( 0, line ) |
|
118 if( line.find( STARTER_APP_IDENTIFIER ) >= 0 ): |
|
119 starter_app_found = True |
|
120 |
|
121 # Append also all the pure comment lines before the starter app line, |
|
122 # because they are most probably related to starter app. When we |
|
123 # found first non comment line, we can quit |
|
124 else: |
|
125 if( (len(line) > 0) and (line[0] == PKG_FILE_COMMENT_LINE_START_TAG) ): |
|
126 footer.insert( 0, line ) |
|
127 else: |
|
128 # First non comment line found, quit the while loop |
|
129 break |
|
130 |
|
131 i = i - 1 |
|
132 |
|
133 # If starter app is not found, then there's no need to divide anything, |
|
134 # so keep the original converted list untouched and return empty footer |
|
135 if not( starter_app_found ): |
|
136 return [] |
|
137 |
|
138 # If starter app is found, remove the footer lines from the original |
|
139 # converted list and then return the footer |
|
140 del converted[i+1:] |
|
141 return footer |
|
142 |
|
143 |
|
144 def ConvertFile( file_name ): |
|
145 data = ReadFileToList( file_name ) |
|
146 |
|
147 converted = [] |
|
148 lines_to_localize = [] |
|
149 for line in data: |
|
150 line_localized = False |
|
151 for path in PATHS_TO_LOCALIZE: |
|
152 # Check does this line contain path to be localized |
|
153 if( (line.find( path ) >= 0) and not(LineIncludesExcludedPath( line.lower() )) ): |
|
154 for extension in EXTENSIONS_TO_LOCALIZE: |
|
155 if( line.lower().find( extension ) >= 0 ): |
|
156 lines_to_localize.append( [line.lower(), extension] ) |
|
157 converted.append( LOCALIZATION_COMMENT_LINE ) |
|
158 converted.append( PKG_FILE_COMMENT_LINE_START_TAG + line ) |
|
159 line_localized = True |
|
160 |
|
161 break # for path in PATHS_TO_LOCALIZE |
|
162 |
|
163 if not( line_localized ): |
|
164 # Check does this line include some embedded sis-package that is localized |
|
165 if( line.find( EMBEDDED_PACKAGE_LINE_IDENTIFIER) >= 0 ): |
|
166 for embedded_pkg in EMBEDDED_PACKAGES_TO_LOCALIZE: |
|
167 if( line.lower().find( embedded_pkg.lower() ) >= 0 ): |
|
168 # This is embedded sis-package that is localized |
|
169 # -> Change the name to *_loc.sisx |
|
170 extension_pos = line.lower().find( EMBEDDED_PACKAGE_FILE_EXTENSION.lower() ) |
|
171 converted.append( line[:extension_pos] + CONVERTED_FILE_NAME_ADDITION + line[extension_pos:] ) |
|
172 line_localized = True |
|
173 |
|
174 if not( line_localized ): |
|
175 converted.append( line ) |
|
176 |
|
177 converted_footer = DivideConvertedLines( converted ) |
|
178 |
|
179 # Add extra line feed just in case as it seems to be needed with some files. |
|
180 # Not needed if adding localised list to the middle of the file. |
|
181 if( len(converted_footer) == 0 ): |
|
182 converted.append( LINE_FEED ) |
|
183 |
|
184 if( len( lines_to_localize ) > 0 ): |
|
185 ConstructLocalizedLines( lines_to_localize, converted ) |
|
186 |
|
187 WriteListToFile( ConvertedFileName(file_name), converted, converted_footer ) |
|
188 |
|
189 return |
|
190 |
|
191 |
|
192 def LineIncludesExcludedPath( line ): |
|
193 for path in PATHS_TO_EXCLUDE: |
|
194 if( line.find( path ) >= 0 ): |
|
195 return True |
|
196 |
|
197 return False |
|
198 |
|
199 |
|
200 def ConvertedFileName( file_name ): |
|
201 ind = file_name.rfind( "." ) |
|
202 if( ind < 0 ): |
|
203 converted_file_name = file_name + CONVERTED_FILE_NAME_ADDITION |
|
204 else: |
|
205 converted_file_name = file_name[:ind] + CONVERTED_FILE_NAME_ADDITION + file_name[ind:] |
|
206 |
|
207 return converted_file_name |
|
208 |
|
209 |
|
210 def WriteListToFile( file_name, data1, data2 ): |
|
211 file_handle = open( file_name, 'w' ) |
|
212 for line in data1: |
|
213 file_handle.write( line ) |
|
214 |
|
215 for line in data2: |
|
216 file_handle.write( line ) |
|
217 |
|
218 file_handle.close() |
|
219 |
|
220 return |
|
221 |
|
222 |
|
223 def ReadFileToList( file_name ): |
|
224 file_handle = open( file_name, 'r' ) |
|
225 data = [ ] |
|
226 for line in file_handle.readlines(): |
|
227 data.append( line ) |
|
228 |
|
229 file_handle.close() |
|
230 |
|
231 return data |
|
232 |
|
233 |
|
234 ########################################################################## |
|
235 # The End Complete |
|
236 # |
|
237 if __name__ == '__main__': |
|
238 main() |