Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: omaha_version_utils.py

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « official/plugins/update/activex/update_control_idl.idl ('k') | plugins/base/build.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 #
3 # Copyright 2010 Google Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ========================================================================
17
18 """Constants and utilities related to Omaha versions."""
19
20 _ONECLICK_PLUGIN_NAME = 'npGoogleOneClick'
21 _UPDATE_PLUGIN_NAME = 'npGoogleUpdate'
22 _BHO_NAME = 'GoopdateBho'
23 _CRASH_HANDLER_NAME = 'GoogleCrashHandler'
24
25 # List of languages that are fully supported in the current build.
26 _OMAHA_LANGUAGES = [
27 'am',
28 'ar',
29 'bg',
30 'bn',
31 'ca',
32 'cs',
33 'da',
34 'de',
35 'el',
36 'en',
37 'en-GB',
38 'es',
39 'es-419',
40 'et',
41 'fa',
42 'fi',
43 'fil',
44 'fr',
45 'gu',
46 'hi',
47 'hr',
48 'hu',
49 'id',
50 'is',
51 'it',
52 'iw',
53 'ja',
54 'kn',
55 'ko',
56 'lt',
57 'lv',
58 'ml',
59 'mr',
60 'ms',
61 'nl',
62 'no',
63 'pl',
64 'pt-BR',
65 'pt-PT',
66 'ro',
67 'ru',
68 'sk',
69 'sl',
70 'sr',
71 'sv',
72 'sw',
73 'ta',
74 'te',
75 'th',
76 'tr',
77 'uk',
78 'ur',
79 'vi',
80 'zh-CN',
81 'zh-TW',
82 ]
83
84 # The shell and goopdate.dll contain additional languages.
85 # 'userdefault' addresses apps that don't look up the resource for the OS
86 # language. See http://b/1328652.
87 _ADDITIONAL_SHELL_LANGUAGES = [
88 'or',
89 'userdefault',
90 'zh-HK',
91 ]
92
93
94 def _IsSupportedOmaha2Version(omaha_version):
95 """Returns true if omaha_version is an Omaha 2 version and is supported."""
96 return (omaha_version[0] == 1 and
97 omaha_version[1] == 2 and
98 omaha_version[2] >= 183)
99
100
101 # All languages supported by this script currently have the same set of
102 # languages, so the omaha_version_info parameter is unused.
103 def _GetMetainstallerPayloadFilenames(prefix,
104 update_plugin_filename,
105 bho_filename,
106 languages,
107 omaha_version):
108 """Returns list of metainstaller payload files for specified Omaha version."""
109 plugin_dll_name = '%s%s' % (prefix, update_plugin_filename)
110 bho_dll_name = '%s%s' % (prefix, bho_filename)
111
112 # The list of files below needs to be kept in sync with the list in
113 # SetupFiles::BuildFileLists().
114 # TODO(omaha): Move the other filename defines in main.scons into this file
115 # and allow all filenames to be customized. At the moment, while the plugin
116 # names are generated in one place due to version numbers, most of the other
117 # files (googleupdate.exe, goopdateres_*.dll, etc.) are hardcoded all over
118 # the place, and require a ton of point fixes to customize.
119 payload_files = [
120 'GoogleUpdate.exe',
121 '%s.exe' % _CRASH_HANDLER_NAME,
122 '%sgoopdate.dll' % (prefix),
123 plugin_dll_name,
124 bho_dll_name,
125 'GoogleUpdateHelper.msi',
126 'GoogleUpdateBroker.exe',
127 'GoogleUpdateOnDemand.exe',
128 '%spsmachine.dll' % (prefix),
129 '%spsuser.dll' % (prefix),
130 ]
131
132 if (omaha_version[0] == 1 and
133 omaha_version[1] == 3 and
134 omaha_version[2] >= 13):
135 # The BHO is not built yet.
136 payload_files.remove(bho_dll_name)
137 elif _IsSupportedOmaha2Version(omaha_version):
138 payload_files.remove(plugin_dll_name)
139 payload_files.remove('GoogleUpdateBroker.exe')
140 payload_files.remove('GoogleUpdateOnDemand.exe')
141 payload_files.remove('psmachine.dll')
142 payload_files.remove('psuser.dll')
143 else:
144 raise Exception('Unsupported version: ' +
145 ConvertVersionToString(omaha_version))
146
147 for language in languages:
148 payload_files += ['%sgoopdateres_%s.dll' % (prefix, language)]
149
150 return payload_files
151
152
153 def ConvertVersionToString(version):
154 """Converts a four-element version list to a version string."""
155 return '%d.%d.%d.%d' % (version[0], version[1], version[2], version[3])
156
157
158 def GetONECLICK_PLUGIN_NAME(): # pylint: disable-msg=C6409
159 """Returns the value of the ONECLICK_PLUGIN_NAME define for the C++ code."""
160 return _ONECLICK_PLUGIN_NAME
161
162
163 def GetUPDATE_PLUGIN_NAME(): # pylint: disable-msg=C6409
164 """Returns the value of the UPDATE_PLUGIN_NAME define for the C++ code."""
165 return _UPDATE_PLUGIN_NAME
166
167
168 def GetBHO_NAME(): # pylint: disable-msg=C6409
169 """Returns the value of the BHO_NAME define for the C++ code."""
170 return _BHO_NAME
171
172
173 def GetCRASH_HANDLER_NAME(): # pylint: disable-msg=C6409
174 """Returns the value of the CRASH_HANDLER_NAME define for the C++ code."""
175 return _CRASH_HANDLER_NAME
176
177
178 def GetLanguagesForVersion(omaha_version):
179 """Returns a list of languages supported by omaha_version."""
180 # Make a copy in case the list is modified below.
181 supported_languages = list(_OMAHA_LANGUAGES)
182
183 # When languages are added, add a version check for older versions without the
184 # new languages and remove the new languages from supported_languages.
185
186 if (omaha_version[0] == 1 and
187 omaha_version[1] == 3 and
188 omaha_version[2] >= 21):
189 # All languages are supported.
190 pass
191 elif _IsSupportedOmaha2Version(omaha_version):
192 # All current languages are supported. 'or' was also supported.
193 supported_languages += ['or']
194 supported_languages.remove('am')
195 supported_languages.remove('sw')
196 else:
197 raise Exception('Unsupported version: ' +
198 ConvertVersionToString(omaha_version))
199
200 return supported_languages
201
202
203 def GetShellLanguagesForVersion(omaha_version):
204 """Returns a list of languages supported by the omaha_version shell."""
205
206 # Silence PyLint. All languages supported by this script currently have the
207 # same set of languages, so this variable is unused.
208 omaha_version = omaha_version
209
210 return _OMAHA_LANGUAGES + _ADDITIONAL_SHELL_LANGUAGES
211
212
213 class OmahaVersionInfo(object):
214 """Contains information about a specific version of Omaha.
215
216 Attributes:
217 filename_prefix: Prefix to use for all output files.
218 version_major: Major version.
219 version_minor: Minor version.
220 version_build: Build version.
221 version_patch: Patch version.
222 oneclick_plugin_version: Version of the OneClick plug-in.
223 oneclick_plugin_filename: Name of the signed OneClick DLL.
224 update_plugin_version: Version of the Omaha 3 plug-in.
225 update_plugin_filename: Name of the signed Omaha 3 plug-in DLL.
226 bho_filename: Name of the signed BHO DLL.
227 crash_handler_filename: Name of the Crash Handler EXE.
228 oneclick_signed_file_info: SignedFileInfo object for the OneClick DLL.
229 bho_signed_file_info: SignedFileInfo object for the BHO DLL.
230
231 """
232
233 def __init__(self, version_file):
234 """Initializes the class based on data from a VERSION file."""
235 self._ReadFile(version_file)
236
237 self.filename_prefix = ''
238
239 # Objects containing more properties used to build the file.
240 self.oneclick_signed_file_info = SignedFileInfo(
241 _ONECLICK_PLUGIN_NAME,
242 'dll',
243 self.oneclick_plugin_version)
244 self.plugin_signed_file_info = SignedFileInfo(
245 _UPDATE_PLUGIN_NAME,
246 'dll',
247 self.update_plugin_version)
248 self.bho_signed_file_info = SignedFileInfo(_BHO_NAME, 'dll')
249
250 # Simple properties for callers that only need the final filename. Not
251 # affected by internal build changes.
252 self.oneclick_plugin_filename = self.oneclick_signed_file_info.filename
253 self.update_plugin_filename = self.plugin_signed_file_info.filename
254 self.bho_filename = self.bho_signed_file_info.filename
255 self.crash_handler_filename = _CRASH_HANDLER_NAME
256
257 def _ReadFile(self, version_file):
258 """Reads and stores data from a VERSION file."""
259
260 execfile(version_file, globals())
261
262 # Silence Pylint. Values from version_file are not defined in this file.
263 # E0602: Undefined variable.
264 # pylint: disable-msg=E0602
265
266 if version_patch > 0:
267 incrementing_value = version_patch
268 incrementing_value_name = 'patch'
269 else:
270 incrementing_value = version_build
271 incrementing_value_name = 'build'
272 if 0 == incrementing_value % 2:
273 raise Exception('ERROR: By convention, the %s number in VERSION '
274 '(currently %d) should be odd.' %
275 (incrementing_value_name, incrementing_value))
276
277 self.version_major = version_major
278 self.version_minor = version_minor
279 self.version_build = version_build
280 self.version_patch = version_patch
281
282 self.oneclick_plugin_version = oneclick_plugin_version
283
284 # update_plugin_version does not exist in Omaha 2 VERSION file. Handle this.
285 try:
286 self.update_plugin_version = update_plugin_version
287 except NameError:
288 if _IsSupportedOmaha2Version(self.GetVersion()):
289 self.update_plugin_version = -1
290 else:
291 raise
292
293 # pylint: enable-msg=E0602
294
295 def MakeTestVersion(self, delta=1):
296 """Changes this object to be for a TEST version of Omaha."""
297
298 if delta <= 0:
299 raise Exception('Delta must be greater than 0.')
300
301 # If we're doing a patch, increment patch; else, increment build.
302 if self.version_patch > 0:
303 self.version_patch += delta
304 else:
305 self.version_build += delta
306
307 self.filename_prefix = 'TEST_'
308
309 def GetVersion(self):
310 """Returns the version elements as a list."""
311 return [self.version_major,
312 self.version_minor,
313 self.version_build,
314 self.version_patch
315 ]
316
317 def GetVersionString(self):
318 """Returns the version as a string."""
319 return ConvertVersionToString(self.GetVersion())
320
321 def GetSupportedLanguages(self):
322 """Returns a list of languages supported by this version."""
323 return GetLanguagesForVersion(self.GetVersion())
324
325 def GetMetainstallerPayloadFilenames(self):
326 """Returns list of metainstaller payload files for this version of Omaha."""
327 return _GetMetainstallerPayloadFilenames(self.filename_prefix,
328 self.update_plugin_filename,
329 self.bho_filename,
330 self.GetSupportedLanguages(),
331 self.GetVersion())
332
333
334 class SignedFileInfo(object):
335 """Contains information, including intermediate names, for signed file."""
336
337 def __init__(self, unversioned_name, extension, file_version=None):
338 """Initializes the class members based on the parameters."""
339
340 if file_version:
341 base_name = '%s%d' % (unversioned_name, file_version)
342 else:
343 base_name = unversioned_name
344
345 self.filename_base = base_name
346 self.filename = '%s.%s' % (self.filename_base, extension)
347
348 self.unsigned_filename_base = '%s_unsigned' % base_name
349 self.unsigned_filename = '%s.%s' % (self.unsigned_filename_base, extension)
OLDNEW
« no previous file with comments | « official/plugins/update/activex/update_control_idl.idl ('k') | plugins/base/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698