| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Copies necessary add-in files into place to install the add-in. | 6 """Copies necessary add-in files into place to install the add-in. |
| 7 | 7 |
| 8 This script will copy the necessary files for the Visual Studio add-in | 8 This script will copy the necessary files for the Visual Studio add-in |
| 9 to where Visual Studio can find them. It assumes the current directory | 9 to where Visual Studio can find them. It assumes the current directory |
| 10 contains the necessary files to copy. | 10 contains the necessary files to copy. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 ADDIN_FILES = ['NativeClientVSAddIn.AddIn', 'NativeClientVSAddIn.dll'] | 32 ADDIN_FILES = ['NativeClientVSAddIn.AddIn', 'NativeClientVSAddIn.dll'] |
| 33 | 33 |
| 34 class InstallError(Exception): | 34 class InstallError(Exception): |
| 35 """Error class for this installer indicating a fatal but expected error.""" | 35 """Error class for this installer indicating a fatal but expected error.""" |
| 36 pass | 36 pass |
| 37 | 37 |
| 38 def UninstallDirectory(directory): | 38 def UninstallDirectory(directory): |
| 39 if os.path.exists(directory): | 39 if os.path.exists(directory): |
| 40 shutil.rmtree(directory) | 40 shutil.rmtree(directory) |
| 41 print 'Removed: %s' % (directory) | 41 print 'Removed: %s' % (directory) |
| 42 else: | |
| 43 print 'Failed to remove non-existant directory: %s' % (directory) | |
| 44 | 42 |
| 45 | 43 |
| 46 def UninstallFile(file_path): | 44 def UninstallFile(file_path): |
| 47 if os.path.exists(file_path): | 45 if os.path.exists(file_path): |
| 48 os.remove(file_path) | 46 os.remove(file_path) |
| 49 print 'Removed: %s' % (file_path) | 47 print 'Removed: %s' % (file_path) |
| 50 else: | |
| 51 print 'Failed to remove non-existant file: %s' % (file_path) | |
| 52 | 48 |
| 53 | 49 |
| 54 def Uninstall(nacl_directory, pepper_directory, addin_directory): | 50 def Uninstall(nacl_directory, pepper_directory, addin_directory): |
| 55 UninstallDirectory(nacl_directory) | 51 UninstallDirectory(nacl_directory) |
| 56 UninstallDirectory(pepper_directory) | 52 UninstallDirectory(pepper_directory) |
| 57 for file_name in ADDIN_FILES: | 53 for file_name in ADDIN_FILES: |
| 58 UninstallFile(os.path.join(addin_directory, file_name)) | 54 UninstallFile(os.path.join(addin_directory, file_name)) |
| 59 | 55 |
| 60 | 56 |
| 61 def CheckForRunningProgams(): | 57 def CheckForRunningProgams(): |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if i == 5: | 115 if i == 5: |
| 120 print "Trying taskkill with /f" | 116 print "Trying taskkill with /f" |
| 121 os.system("taskkill.exe /IM devenv.exe /f") | 117 os.system("taskkill.exe /IM devenv.exe /f") |
| 122 if CheckForRunningProgams(): | 118 if CheckForRunningProgams(): |
| 123 raise InstallError('Failed to kill Visual Studio and MSBuild instances') | 119 raise InstallError('Failed to kill Visual Studio and MSBuild instances') |
| 124 | 120 |
| 125 if sys.version_info < (2, 6, 2): | 121 if sys.version_info < (2, 6, 2): |
| 126 print "\n\nWARNING: Only python version 2.6.2 or greater is supported. " \ | 122 print "\n\nWARNING: Only python version 2.6.2 or greater is supported. " \ |
| 127 "Current version is %s\n\n" % (sys.version_info[:3],) | 123 "Current version is %s\n\n" % (sys.version_info[:3],) |
| 128 | 124 |
| 129 # Admin is needed to write to the default platform directory. | |
| 130 if ctypes.windll.shell32.IsUserAnAdmin() != 1: | |
| 131 raise InstallError("Not running as administrator. The install script needs " | |
| 132 "write access to protected Visual Studio directories.") | |
| 133 | |
| 134 # Ensure install directories exist. | 125 # Ensure install directories exist. |
| 135 if not os.path.exists(options.vsuser_path): | 126 if not os.path.exists(options.vsuser_path): |
| 136 raise InstallError("Could not find user Visual Studio directory: %s" % ( | 127 raise InstallError("Could not find user Visual Studio directory: %s" % ( |
| 137 options.vsuser_path)) | 128 options.vsuser_path)) |
| 138 if not os.path.exists(options.msbuild_path): | 129 if not os.path.exists(options.msbuild_path): |
| 139 raise InstallError("Could not find MS Build directory: %s" % ( | 130 raise InstallError("Could not find MS Build directory: %s" % ( |
| 140 options.msbuild_path)) | 131 options.msbuild_path)) |
| 141 | 132 |
| 142 addin_directory = os.path.join(options.vsuser_path, 'Addins') | 133 addin_directory = os.path.join(options.vsuser_path, 'Addins') |
| 143 platform_directory = os.path.join( | 134 platform_root = os.path.join(options.msbuild_path, |
| 144 options.msbuild_path, 'Microsoft.Cpp\\v4.0\\Platforms') | 135 'Microsoft.Cpp', 'v4.0', 'Platforms') |
| 145 nacl_directory = os.path.join(platform_directory, NACL_PLATFORM_NAME) | 136 if not os.path.exists(platform_root): |
| 146 pepper_directory = os.path.join(platform_directory, PEPPER_PLATFORM_NAME) | 137 raise InstallError("Could not find path: %s" % platform_root) |
| 138 |
| 139 if (not os.access(addin_directory, os.W_OK) |
| 140 or not os.access(platform_root, os.W_OK)): |
| 141 # Admin is needed to write to the default platform directory. |
| 142 if ctypes.windll.shell32.IsUserAnAdmin() != 1: |
| 143 raise InstallError("Not running as administrator. The install script " |
| 144 "needs write access to protected Visual Studio " |
| 145 "directories.") |
| 146 raise InstallError("install script needs write access to: %s" |
| 147 % platform_root) |
| 148 |
| 149 nacl_directory = os.path.join(platform_root, NACL_PLATFORM_NAME) |
| 150 pepper_directory = os.path.join(platform_root, PEPPER_PLATFORM_NAME) |
| 147 | 151 |
| 148 # If uninstalling then redirect to uninstall program. | 152 # If uninstalling then redirect to uninstall program. |
| 149 if options.uninstall: | 153 if options.uninstall: |
| 150 Uninstall(nacl_directory, pepper_directory, addin_directory) | 154 Uninstall(nacl_directory, pepper_directory, addin_directory) |
| 151 print "\nUninstall complete!\n" | 155 print "\nUninstall complete!\n" |
| 152 sys.exit(0) | 156 sys.exit(0) |
| 153 | 157 |
| 154 if not os.path.exists(platform_directory): | 158 if not os.path.exists(platform_root): |
| 155 raise InstallError("Could not find path: %s" % platform_directory) | 159 raise InstallError("Could not find path: %s" % platform_root) |
| 156 if not os.path.exists(addin_directory): | 160 if not os.path.exists(addin_directory): |
| 157 os.mkdir(addin_directory) | 161 os.mkdir(addin_directory) |
| 158 | 162 |
| 159 # Ensure environment variables are set. | 163 # Ensure environment variables are set. |
| 160 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) | 164 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) |
| 161 chrome_path = os.getenv('CHROME_PATH', None) | 165 chrome_path = os.getenv('CHROME_PATH', None) |
| 162 if nacl_sdk_root is None: | 166 if nacl_sdk_root is None: |
| 163 raise InstallError('Environment Variable NACL_SDK_ROOT is not set') | 167 raise InstallError('Environment Variable NACL_SDK_ROOT is not set') |
| 164 if chrome_path is None: | 168 if chrome_path is None: |
| 165 raise InstallError('Environment Variable CHROME_PATH is not set') | 169 raise InstallError('Environment Variable CHROME_PATH is not set') |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 print e | 223 print e |
| 220 except shutil.Error as e: | 224 except shutil.Error as e: |
| 221 print "Error while copying file. Please ensure file is not in use." | 225 print "Error while copying file. Please ensure file is not in use." |
| 222 print e | 226 print e |
| 223 except WindowsError as e: | 227 except WindowsError as e: |
| 224 if e.winerror == 5: | 228 if e.winerror == 5: |
| 225 print "Access denied error. Please ensure Visual Studio and MSBuild" | 229 print "Access denied error. Please ensure Visual Studio and MSBuild" |
| 226 print "processes are closed." | 230 print "processes are closed." |
| 227 else: | 231 else: |
| 228 raise | 232 raise |
| 229 | |
| OLD | NEW |