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 """Shim script for the SDK updater, to allow automatic updating. | 6 """Shim script for the SDK updater, to allow automatic updating. |
7 | 7 |
8 The purpose of this script is to be a shim which automatically updates | 8 The purpose of this script is to be a shim which automatically updates |
9 sdk_tools (the bundle containing the updater scripts) whenever this script is | 9 sdk_tools (the bundle containing the updater scripts) whenever this script is |
10 run. | 10 run. |
11 | 11 |
12 When the sdk_tools bundle has been updated to the most recent version, this | 12 When the sdk_tools bundle has been updated to the most recent version, this |
13 script forwards its arguments to sdk_updater_main.py. | 13 script forwards its arguments to sdk_updater_main.py. |
14 """ | 14 """ |
15 | 15 |
16 import os | 16 import os |
17 import subprocess | 17 import subprocess |
18 from sdk_update_common import * | 18 from sdk_update_common import RenameDir, RemoveDir, Error |
19 import sys | 19 import sys |
20 import tempfile | 20 import tempfile |
21 | 21 |
22 | 22 |
23 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 23 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
24 SDK_UPDATE_MAIN = os.path.join(SCRIPT_DIR, 'sdk_update_main.py') | 24 SDK_UPDATE_MAIN = os.path.join(SCRIPT_DIR, 'sdk_update_main.py') |
25 SDK_ROOT_DIR = os.path.dirname(SCRIPT_DIR) | 25 SDK_ROOT_DIR = os.path.dirname(SCRIPT_DIR) |
26 NACLSDK_SHELL_SCRIPT = os.path.join(SDK_ROOT_DIR, 'naclsdk') | 26 NACLSDK_SHELL_SCRIPT = os.path.join(SDK_ROOT_DIR, 'naclsdk') |
27 if sys.platform.startswith('win'): | 27 if sys.platform.startswith('win'): |
28 NACLSDK_SHELL_SCRIPT += '.bat' | 28 NACLSDK_SHELL_SCRIPT += '.bat' |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 ' viewing or accessing this directory and try again.\n' % ( | 76 ' viewing or accessing this directory and try again.\n' % ( |
77 SDK_TOOLS_DIR,)) | 77 SDK_TOOLS_DIR,)) |
78 sys.exit(1) | 78 sys.exit(1) |
79 | 79 |
80 try: | 80 try: |
81 RenameDir(SDK_TOOLS_UPDATE_DIR, SDK_TOOLS_DIR) | 81 RenameDir(SDK_TOOLS_UPDATE_DIR, SDK_TOOLS_DIR) |
82 except Error: | 82 except Error: |
83 # Failed for some reason, move the old dir back. | 83 # Failed for some reason, move the old dir back. |
84 try: | 84 try: |
85 RenameDir(temp_sdktools, SDK_TOOLS_DIR) | 85 RenameDir(temp_sdktools, SDK_TOOLS_DIR) |
86 except: | 86 except Error: |
87 # Not much to do here. sdk_tools won't exist, but sdk_tools_update | 87 # Not much to do here. sdk_tools won't exist, but sdk_tools_update |
88 # should. Hopefully running the batch script again will move | 88 # should. Hopefully running the batch script again will move |
89 # sdk_tools_update -> sdk_tools and it will work this time... | 89 # sdk_tools_update -> sdk_tools and it will work this time... |
90 sys.stderr.write('Unable to restore directory "%s" while auto-updating.' | 90 sys.stderr.write('Unable to restore directory "%s" while auto-updating.' |
91 'Make sure no programs are viewing or accessing this directory and' | 91 'Make sure no programs are viewing or accessing this directory and' |
92 'try again.\n' % (SDK_TOOLS_DIR,)) | 92 'try again.\n' % (SDK_TOOLS_DIR,)) |
93 sys.exit(1) | 93 sys.exit(1) |
94 finally: | 94 finally: |
95 RemoveDir(tempdir) | 95 RemoveDir(tempdir) |
96 | 96 |
97 | 97 |
98 def main(): | 98 def main(): |
99 args = sys.argv[1:] | 99 args = sys.argv[1:] |
100 if UpdateSDKTools(args): | 100 if UpdateSDKTools(args): |
101 RenameSdkToolsDirectory() | 101 RenameSdkToolsDirectory() |
102 # Call the shell script, just in case this script was updated in the next | 102 # Call the shell script, just in case this script was updated in the next |
103 # version of sdk_tools | 103 # version of sdk_tools |
104 return subprocess.call([NACLSDK_SHELL_SCRIPT] + args) | 104 return subprocess.call([NACLSDK_SHELL_SCRIPT] + args) |
105 else: | 105 else: |
106 return subprocess.call(MakeSdkUpdateMainCmd(args)) | 106 return subprocess.call(MakeSdkUpdateMainCmd(args)) |
107 | 107 |
108 | 108 |
109 if __name__ == '__main__': | 109 if __name__ == '__main__': |
110 sys.exit(main()) | 110 sys.exit(main()) |
OLD | NEW |