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

Side by Side Diff: visual_studio/NativeClientVSAddIn/InstallerResources/install.py

Issue 10830151: VS Add-in more properties and improvements (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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 12 matching lines...) Expand all
23 23
24 DEFAULT_VS_USER_DIRECTORY = os.path.expandvars( 24 DEFAULT_VS_USER_DIRECTORY = os.path.expandvars(
25 '%USERPROFILE%\\My Documents\\Visual Studio 2010') 25 '%USERPROFILE%\\My Documents\\Visual Studio 2010')
26 26
27 DEFAULT_MS_BUILD_DIRECTORY = os.path.expandvars('%ProgramFiles(x86)%\\MSBuild') 27 DEFAULT_MS_BUILD_DIRECTORY = os.path.expandvars('%ProgramFiles(x86)%\\MSBuild')
28 28
29 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 29 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
30 30
31 ADDIN_FILES = ['NativeClientVSAddIn.AddIn', 'NativeClientVSAddIn.dll'] 31 ADDIN_FILES = ['NativeClientVSAddIn.AddIn', 'NativeClientVSAddIn.dll']
32 32
33 class InstallError(Exception):
34 """Error class for this installer indicating a fatal but expected error."""
35 pass
36
33 def UninstallDirectory(directory): 37 def UninstallDirectory(directory):
34 if os.path.exists(directory): 38 if os.path.exists(directory):
35 shutil.rmtree(directory) 39 shutil.rmtree(directory)
36 print 'Removed: %s' % (directory) 40 print 'Removed: %s' % (directory)
37 else: 41 else:
38 print 'Failed to remove non-existant directory: %s' % (directory) 42 print 'Failed to remove non-existant directory: %s' % (directory)
39 43
40 44
41 def UninstallFile(file_path): 45 def UninstallFile(file_path):
42 if os.path.exists(file_path): 46 if os.path.exists(file_path):
(...skipping 21 matching lines...) Expand all
64 parser.add_option('-f', '--force', action="store_true", dest='overwrite', 68 parser.add_option('-f', '--force', action="store_true", dest='overwrite',
65 default=False, help='Force an overwrite of existing files') 69 default=False, help='Force an overwrite of existing files')
66 parser.add_option('-p', '--ppapi', action="store_true", dest='install_ppapi', 70 parser.add_option('-p', '--ppapi', action="store_true", dest='install_ppapi',
67 help='Install PPAPI template without asking.') 71 help='Install PPAPI template without asking.')
68 parser.add_option('-n', '--no-ppapi', action="store_false", 72 parser.add_option('-n', '--no-ppapi', action="store_false",
69 dest='install_ppapi', help='Do not install PPAPI template and do not ask') 73 dest='install_ppapi', help='Do not install PPAPI template and do not ask')
70 parser.add_option('-u', '--uninstall', action="store_true", 74 parser.add_option('-u', '--uninstall', action="store_true",
71 dest='uninstall', help='Remove the add-in.') 75 dest='uninstall', help='Remove the add-in.')
72 (options, args) = parser.parse_args() 76 (options, args) = parser.parse_args()
73 77
78 print "*************************************************"
79 print "Native-Client Visual Studio 2010 Add-in Installer"
80 print "*************************************************\n"
81 print "Please ensure Visual Studio and MSBuild are closed " \
82 "during installation.\n"
83
74 if platform.system() != 'Windows': 84 if platform.system() != 'Windows':
75 raise Exception('Must install to Windows system') 85 raise InstallError('Must install to Windows system')
76 86
77 if sys.version_info < (2, 6, 2): 87 if sys.version_info < (2, 6, 2):
78 print "\n\nWARNING: Only python version 2.6.2 or greater is supported. " \ 88 print "\n\nWARNING: Only python version 2.6.2 or greater is supported. " \
79 "Current version is %s\n\n" % (sys.version_info[:3],) 89 "Current version is %s\n\n" % (sys.version_info[:3],)
80 90
81 # Admin is needed to write to the default platform directory. 91 # Admin is needed to write to the default platform directory.
82 if ctypes.windll.shell32.IsUserAnAdmin() != 1: 92 if ctypes.windll.shell32.IsUserAnAdmin() != 1:
83 raise Exception("Not running as administrator. The install script needs " 93 raise InstallError("Not running as administrator. The install script needs "
84 "write access to protected Visual Studio directories.") 94 "write access to protected Visual Studio directories.")
85 95
86 # Ensure install directories exist. 96 # Ensure install directories exist.
87 if not os.path.exists(options.vsuser_path): 97 if not os.path.exists(options.vsuser_path):
88 raise Exception("Could not find user Visual Studio directory: %s" % ( 98 raise InstallError("Could not find user Visual Studio directory: %s" % (
89 options.vsuser_path)) 99 options.vsuser_path))
90 if not os.path.exists(options.msbuild_path): 100 if not os.path.exists(options.msbuild_path):
91 raise Exception("Could not find MS Build directory: %s" % ( 101 raise InstallError("Could not find MS Build directory: %s" % (
92 options.msbuild_path)) 102 options.msbuild_path))
93 103
94 addin_directory = os.path.join(options.vsuser_path, 'Addins') 104 addin_directory = os.path.join(options.vsuser_path, 'Addins')
95 platform_directory = os.path.join( 105 platform_directory = os.path.join(
96 options.msbuild_path, 'Microsoft.Cpp\\v4.0\\Platforms') 106 options.msbuild_path, 'Microsoft.Cpp\\v4.0\\Platforms')
97 nacl_directory = os.path.join(platform_directory, NACL_PLATFORM_NAME) 107 nacl_directory = os.path.join(platform_directory, NACL_PLATFORM_NAME)
98 pepper_directory = os.path.join(platform_directory, PEPPER_PLATFORM_NAME) 108 pepper_directory = os.path.join(platform_directory, PEPPER_PLATFORM_NAME)
99 109
100 # If uninstalling then redirect to uninstall program. 110 # If uninstalling then redirect to uninstall program.
101 if options.uninstall: 111 if options.uninstall:
102 Uninstall(nacl_directory, pepper_directory, addin_directory) 112 Uninstall(nacl_directory, pepper_directory, addin_directory)
103 print "\nUninstall complete!\n" 113 print "\nUninstall complete!\n"
104 exit(0) 114 exit(0)
105 115
106 if not os.path.exists(platform_directory): 116 if not os.path.exists(platform_directory):
107 raise Exception("Could not find path: %s" % platform_directory) 117 raise InstallError("Could not find path: %s" % platform_directory)
108 if not os.path.exists(addin_directory): 118 if not os.path.exists(addin_directory):
109 os.mkdir(addin_directory) 119 os.mkdir(addin_directory)
110 120
111 # Ensure environment variables are set. 121 # Ensure environment variables are set.
112 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) 122 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None)
113 chrome_path = os.getenv('CHROME_PATH', None) 123 chrome_path = os.getenv('CHROME_PATH', None)
114 if nacl_sdk_root is None: 124 if nacl_sdk_root is None:
115 raise Exception('Environment Variable NACL_SDK_ROOT is not set') 125 raise InstallError('Environment Variable NACL_SDK_ROOT is not set')
116 if chrome_path is None: 126 if chrome_path is None:
117 raise Exception('Environment Variable CHROME_PATH is not set') 127 raise InstallError('Environment Variable CHROME_PATH is not set')
118 128
119 # Remove existing installation. 129 # Remove existing installation.
120 if os.path.exists(nacl_directory) or os.path.exists(pepper_directory): 130 if os.path.exists(nacl_directory) or os.path.exists(pepper_directory):
121 # If not forced then ask user permission. 131 # If not forced then ask user permission.
122 if not options.overwrite: 132 if not options.overwrite:
123 print "Warning: Pre-existing add-in installation will be overwritten." 133 print "\nWarning: Pre-existing add-in installation will be overwritten."
124 print "Continue? ((Yes))/((No))" 134 print "Continue? ((Yes))/((No))"
125 remove_answer = raw_input().strip() 135 remove_answer = raw_input().strip()
126 if not (remove_answer.lower() == "yes" or remove_answer.lower() == "y"): 136 if not (remove_answer.lower() == "yes" or remove_answer.lower() == "y"):
127 raise Exception('User did not allow overwrite of existing install.') 137 raise InstallError('User did not allow overwrite of existing install.')
128 print "Removing existing install..." 138 print "Removing existing install..."
129 Uninstall(nacl_directory, pepper_directory, addin_directory) 139 Uninstall(nacl_directory, pepper_directory, addin_directory)
130 140
131 # Ask user before installing PPAPI template. 141 # Ask user before installing PPAPI template.
132 if options.install_ppapi is None: 142 if options.install_ppapi is None:
133 print "\n" 143 print "\n"
134 print "Set up configuration to enable Pepper development " \ 144 print "Set up configuration to enable Pepper development " \
135 "with Visual Studio?" 145 "with Visual Studio?"
136 print "((Yes)) - I want to create and copy relevant files into a " \ 146 print "((Yes)) - I want to create and copy relevant files into a " \
137 "Pepper subdirectory" 147 "Pepper subdirectory"
138 print "((No)) - I am not interested or will set up the configuration later" 148 print "((No)) - I am not interested or will set up the configuration later"
139 ppapi_answer = raw_input().strip() 149 ppapi_answer = raw_input().strip()
140 if ppapi_answer.lower() == "yes" or ppapi_answer.lower() == "y": 150 if ppapi_answer.lower() == "yes" or ppapi_answer.lower() == "y":
141 options.install_ppapi = True 151 options.install_ppapi = True
142 else: 152 else:
143 options.install_ppapi = False 153 options.install_ppapi = False
144 print "Not installing PPAPI platform." 154 print "Will not install PPAPI platform during installation."
145 155
146 print "Installing..." 156 print "\nBegin installing components..."
147 157
148 try: 158 try:
149 # Copy the necessary files into place. 159 # Copy the necessary files into place.
150 for file_name in ADDIN_FILES: 160 for file_name in ADDIN_FILES:
151 shutil.copy(os.path.join(SCRIPT_DIR, file_name), addin_directory) 161 shutil.copy(os.path.join(SCRIPT_DIR, file_name), addin_directory)
152 print "Add-in installed." 162 print "Add-in installed."
153 163
154 shutil.copytree(os.path.join(SCRIPT_DIR, 'NaCl'), nacl_directory) 164 shutil.copytree(os.path.join(SCRIPT_DIR, 'NaCl'), nacl_directory)
155 print "NaCl platform installed." 165 print "NaCl platform installed."
156 166
157 if options.install_ppapi: 167 if options.install_ppapi:
158 create_ppapi_platform.CreatePPAPI(options.msbuild_path) 168 create_ppapi_platform.CreatePPAPI(options.msbuild_path)
159 print "PPAPI platform installed." 169 print "PPAPI platform installed."
160 except: 170 except:
161 print "\nException occured! Rolling back install...\n" 171 print "\nException occured! Rolling back install...\n"
162 Uninstall(nacl_directory, pepper_directory, addin_directory) 172 Uninstall(nacl_directory, pepper_directory, addin_directory)
163 raise 173 raise
164 else: 174 else:
165 print "\nInstallation complete!\n" 175 print "\nInstallation complete!\n"
166 176
167 if __name__ == '__main__': 177 if __name__ == '__main__':
168 main() 178 try:
179 main()
180 except InstallError as e:
181 print
182 print e
183 except shutil.Error as e:
184 print "Error while copying file. Please ensure file is not in use."
185 print e
186 except WindowsError as e:
187 if e.winerror == 5:
188 print "Access denied error. Please ensure Visual Studio and MSBuild"
189 print "processes are closed."
190 else:
191 raise
192
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698