| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 import hashlib | 6 import hashlib |
| 7 import os | 7 import os |
| 8 import string | 8 import string |
| 9 import win32api | 9 import win32api |
| 10 import win32com.client | 10 import win32com.client |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 user_sid, _ = win32security.GetTokenInformation(token_handle, | 49 user_sid, _ = win32security.GetTokenInformation(token_handle, |
| 50 win32security.TokenUser) | 50 win32security.TokenUser) |
| 51 user_sid_string = win32security.ConvertSidToStringSid(user_sid) | 51 user_sid_string = win32security.ConvertSidToStringSid(user_sid) |
| 52 md5_digest = hashlib.md5(user_sid_string).digest() | 52 md5_digest = hashlib.md5(user_sid_string).digest() |
| 53 return '.' + base64.b32encode(md5_digest).rstrip('=') | 53 return '.' + base64.b32encode(md5_digest).rstrip('=') |
| 54 | 54 |
| 55 | 55 |
| 56 class VariableExpander: | 56 class VariableExpander: |
| 57 """Expands variables in strings.""" | 57 """Expands variables in strings.""" |
| 58 | 58 |
| 59 def __init__(self, mini_installer_path): | 59 def __init__(self, mini_installer_path, next_version_mini_installer_path): |
| 60 """Constructor. | 60 """Constructor. |
| 61 | 61 |
| 62 The constructor initializes a variable dictionary that maps variables to | 62 The constructor initializes a variable dictionary that maps variables to |
| 63 their values. These are the only acceptable variables: | 63 their values. These are the only acceptable variables: |
| 64 * $CHROME_DIR: the directory of Chrome (or Chromium) from the base | 64 * $CHROME_DIR: the directory of Chrome (or Chromium) from the base |
| 65 installation directory. | 65 installation directory. |
| 66 * $CHROME_HTML_PROG_ID: 'ChromeHTML' (or 'ChromiumHTM'). | 66 * $CHROME_HTML_PROG_ID: 'ChromeHTML' (or 'ChromiumHTM'). |
| 67 * $CHROME_LONG_NAME: 'Google Chrome' (or 'Chromium'). | 67 * $CHROME_LONG_NAME: 'Google Chrome' (or 'Chromium'). |
| 68 * $CHROME_LONG_NAME_SXS: 'Google Chrome SxS' if $SUPPORTS_SXS. | 68 * $CHROME_LONG_NAME_SXS: 'Google Chrome SxS' if $SUPPORTS_SXS. |
| 69 * $CHROME_SHORT_NAME: 'Chrome' (or 'Chromium'). | 69 * $CHROME_SHORT_NAME: 'Chrome' (or 'Chromium'). |
| 70 * $CHROME_SHORT_NAME_SXS: 'ChromeCanary' if $SUPPORTS_SXS. | 70 * $CHROME_SHORT_NAME_SXS: 'ChromeCanary' if $SUPPORTS_SXS. |
| 71 * $CHROME_UPDATE_REGISTRY_SUBKEY: the registry key, excluding the root | 71 * $CHROME_UPDATE_REGISTRY_SUBKEY: the registry key, excluding the root |
| 72 key, of Chrome for Google Update. | 72 key, of Chrome for Google Update. |
| 73 * $CHROME_UPDATE_REGISTRY_SUBKEY_SXS: the registry key, excluding the | 73 * $CHROME_UPDATE_REGISTRY_SUBKEY_SXS: the registry key, excluding the |
| 74 root key, of Chrome SxS for Google Update. | 74 root key, of Chrome SxS for Google Update. |
| 75 * $LAUNCHER_UPDATE_REGISTRY_SUBKEY: the registry key, excluding the root | 75 * $LAUNCHER_UPDATE_REGISTRY_SUBKEY: the registry key, excluding the root |
| 76 key, of the app launcher for Google Update if $SUPPORTS_SXS. | 76 key, of the app launcher for Google Update if $SUPPORTS_SXS. |
| 77 * $LOCAL_APPDATA: the unquoted path to the Local Application Data | 77 * $LOCAL_APPDATA: the unquoted path to the Local Application Data |
| 78 folder. | 78 folder. |
| 79 * $MINI_INSTALLER: the unquoted path to the mini_installer. | 79 * $MINI_INSTALLER: the unquoted path to the mini_installer. |
| 80 * $MINI_INSTALLER_FILE_VERSION: the file version of the mini_installer. | 80 * $MINI_INSTALLER_FILE_VERSION: the file version of $MINI_INSTALLER. |
| 81 * $NEXT_VERSION_MINI_INSTALLER: the unquoted path to a mini_installer |
| 82 whose version is higher than $MINI_INSTALLER. |
| 83 * $NEXT_VERSION_MINI_INSTALLER_FILE_VERSION: the file version of |
| 84 $NEXT_VERSION_MINI_INSTALLER. |
| 81 * $PROGRAM_FILES: the unquoted path to the Program Files folder. | 85 * $PROGRAM_FILES: the unquoted path to the Program Files folder. |
| 82 * $SUPPORTS_SXS: a boolean indicating whether or not SxS installs | 86 * $SUPPORTS_SXS: a boolean indicating whether or not SxS installs |
| 83 are supported by the mini_installer under test. | 87 are supported by the mini_installer under test. |
| 84 * $USER_SPECIFIC_REGISTRY_SUFFIX: the output from the function | 88 * $USER_SPECIFIC_REGISTRY_SUFFIX: the output from the function |
| 85 _GetUserSpecificRegistrySuffix(). | 89 _GetUserSpecificRegistrySuffix(). |
| 86 * $VERSION_[XP/SERVER_2003/VISTA/WIN7/WIN8/WIN8_1/WIN10]: a 2-tuple | 90 * $VERSION_[XP/SERVER_2003/VISTA/WIN7/WIN8/WIN8_1/WIN10]: a 2-tuple |
| 87 representing the version of the corresponding OS. | 91 representing the version of the corresponding OS. |
| 88 * $WINDOWS_VERSION: a 2-tuple representing the current Windows version. | 92 * $WINDOWS_VERSION: a 2-tuple representing the current Windows version. |
| 89 | 93 |
| 90 Args: | 94 Args: |
| 91 mini_installer_path: The path to mini_installer.exe. | 95 mini_installer_path: The path to a mini_installer. |
| 96 next_version_mini_installer_path: The path to a mini_installer whose |
| 97 version is higher than |mini_installer_path|. |
| 92 """ | 98 """ |
| 93 mini_installer_abspath = os.path.abspath(mini_installer_path) | 99 mini_installer_abspath = os.path.abspath(mini_installer_path) |
| 100 next_version_mini_installer_abspath = os.path.abspath( |
| 101 next_version_mini_installer_path) |
| 94 windows_major_ver, windows_minor_ver, _, _, _ = win32api.GetVersionEx() | 102 windows_major_ver, windows_minor_ver, _, _, _ = win32api.GetVersionEx() |
| 95 self._variable_mapping = { | 103 self._variable_mapping = { |
| 96 'LOCAL_APPDATA': shell.SHGetFolderPath(0, shellcon.CSIDL_LOCAL_APPDATA, | 104 'LOCAL_APPDATA': shell.SHGetFolderPath(0, shellcon.CSIDL_LOCAL_APPDATA, |
| 97 None, 0), | 105 None, 0), |
| 98 'MINI_INSTALLER': mini_installer_abspath, | 106 'MINI_INSTALLER': mini_installer_abspath, |
| 99 'MINI_INSTALLER_FILE_VERSION': _GetFileVersion(mini_installer_abspath), | 107 'MINI_INSTALLER_FILE_VERSION': _GetFileVersion(mini_installer_abspath), |
| 108 'NEXT_VERSION_MINI_INSTALLER': next_version_mini_installer_abspath, |
| 109 'NEXT_VERSION_MINI_INSTALLER_FILE_VERSION': _GetFileVersion( |
| 110 next_version_mini_installer_abspath), |
| 100 'PROGRAM_FILES': shell.SHGetFolderPath(0, shellcon.CSIDL_PROGRAM_FILES, | 111 'PROGRAM_FILES': shell.SHGetFolderPath(0, shellcon.CSIDL_PROGRAM_FILES, |
| 101 None, 0), | 112 None, 0), |
| 102 'USER_SPECIFIC_REGISTRY_SUFFIX': _GetUserSpecificRegistrySuffix(), | 113 'USER_SPECIFIC_REGISTRY_SUFFIX': _GetUserSpecificRegistrySuffix(), |
| 103 'VERSION_SERVER_2003': '(5, 2)', | 114 'VERSION_SERVER_2003': '(5, 2)', |
| 104 'VERSION_VISTA': '(6, 0)', | 115 'VERSION_VISTA': '(6, 0)', |
| 105 'VERSION_WIN10': '(10, 0)', | 116 'VERSION_WIN10': '(10, 0)', |
| 106 'VERSION_WIN7': '(6, 1)', | 117 'VERSION_WIN7': '(6, 1)', |
| 107 'VERSION_WIN8': '(6, 2)', | 118 'VERSION_WIN8': '(6, 2)', |
| 108 'VERSION_WIN8_1': '(6, 3)', | 119 'VERSION_WIN8_1': '(6, 3)', |
| 109 'VERSION_XP': '(5, 1)', | 120 'VERSION_XP': '(5, 1)', |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 variables must be escaped with $$, otherwise a KeyError or a ValueError will | 172 variables must be escaped with $$, otherwise a KeyError or a ValueError will |
| 162 be raised. | 173 be raised. |
| 163 | 174 |
| 164 Args: | 175 Args: |
| 165 str: A string. | 176 str: A string. |
| 166 | 177 |
| 167 Returns: | 178 Returns: |
| 168 A new string created by replacing variables with their values. | 179 A new string created by replacing variables with their values. |
| 169 """ | 180 """ |
| 170 return string.Template(str).substitute(self._variable_mapping) | 181 return string.Template(str).substitute(self._variable_mapping) |
| OLD | NEW |