| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Small utility library of python functions used by the various package | 5 """Small utility library of python functions used by the various package |
| 6 installers. | 6 installers. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import datetime | 9 import datetime |
| 10 import errno | 10 import errno |
| 11 import fileinput | 11 import fileinput |
| 12 import os | 12 import os |
| 13 import platform | 13 import platform |
| 14 import re | 14 import re |
| 15 import shutil | 15 import shutil |
| 16 import subprocess | 16 import subprocess |
| 17 import sys | 17 import sys |
| 18 | 18 |
| 19 # pylint: disable=E0602 |
| 19 | 20 |
| 20 # Reuse last change utility code. | 21 # Reuse last change utility code. |
| 21 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 22 SRC_DIR = os.path.dirname(os.path.dirname(os.path.dirname(SCRIPT_DIR))) | 23 SRC_DIR = os.path.dirname(os.path.dirname(os.path.dirname(SCRIPT_DIR))) |
| 23 sys.path.append(os.path.join(SRC_DIR, 'build/util')) | 24 sys.path.append(os.path.join(SRC_DIR, 'build/util')) |
| 24 import lastchange | 25 import lastchange |
| 25 | 26 |
| 26 | 27 |
| 27 # Location of chrome's version file. | 28 # Location of chrome's version file. |
| 28 VERSION_PATH = os.path.join(SRC_DIR, 'chrome', 'VERSION') | 29 VERSION_PATH = os.path.join(SRC_DIR, 'chrome', 'VERSION') |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 # file, it is removed before an attempt to make the directories. If |abs_path| | 77 # file, it is removed before an attempt to make the directories. If |abs_path| |
| 77 # already points to a directory, this method does nothing. | 78 # already points to a directory, this method does nothing. |
| 78 def ForceMakeDirs(abs_path, mode=0755): | 79 def ForceMakeDirs(abs_path, mode=0755): |
| 79 if os.path.isdir(abs_path): | 80 if os.path.isdir(abs_path): |
| 80 return | 81 return |
| 81 try: | 82 try: |
| 82 # Remove an existing regular file; ignore errors (e.g. file doesn't exist). | 83 # Remove an existing regular file; ignore errors (e.g. file doesn't exist). |
| 83 # If there are permission problems, they will be caught by the exception | 84 # If there are permission problems, they will be caught by the exception |
| 84 # handler around the os.makedirs call. | 85 # handler around the os.makedirs call. |
| 85 os.remove(abs_path) | 86 os.remove(abs_path) |
| 86 except: | 87 except OSError: |
| 87 pass | 88 pass |
| 88 try: | 89 try: |
| 89 os.makedirs(abs_path, mode) | 90 os.makedirs(abs_path, mode) |
| 90 except OSError, (os_errno, os_strerr): | 91 except OSError, e: |
| 91 # If the error is anything but EEXIST (file already exists), then print an | 92 # If the error is anything but EEXIST (file already exists), then print an |
| 92 # informative message and re-raise. It is not and error if the directory | 93 # informative message and re-raise. It is not and error if the directory |
| 93 # already exists. | 94 # already exists. |
| 95 (os_errno, os_strerr) = e |
| 94 if os_errno != errno.EEXIST: | 96 if os_errno != errno.EEXIST: |
| 95 print 'ForceMakeDirs(%s, 0%o) FAILED: %s' % (abs_path, mode, os_strerr) | 97 print 'ForceMakeDirs(%s, 0%o) FAILED: %s' % (abs_path, mode, os_strerr) |
| 96 raise | 98 raise |
| 97 pass | |
| 98 | 99 |
| 99 | 100 |
| 100 # patch version 2.6 doesn't work. Most of our Linux distros use patch 2.6. | 101 # patch version 2.6 doesn't work. Most of our Linux distros use patch 2.6. |
| 101 # Returns |True| if the version of patch is usable (that is, not version 2.6). | 102 # Returns |True| if the version of patch is usable (that is, not version 2.6). |
| 102 # |shell_env| is the enviromnent used to run the subprocesses like patch and | 103 # |shell_env| is the enviromnent used to run the subprocesses like patch and |
| 103 # sed. If |shell_env| is None, then os.environ is used. | 104 # sed. If |shell_env| is None, then os.environ is used. |
| 104 def CheckPatchVersion(shell_env=None): | 105 def CheckPatchVersion(shell_env=None): |
| 105 if shell_env is None: | 106 if shell_env is None: |
| 106 shell_env = os.environ | 107 shell_env = os.environ |
| 107 patch = subprocess.Popen("patch --version", | 108 patch = subprocess.Popen("patch --version", |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 283 |
| 283 | 284 |
| 284 def UpdateReadMe(filename): | 285 def UpdateReadMe(filename): |
| 285 '''Updates the README file in the SDK with the current date and version''' | 286 '''Updates the README file in the SDK with the current date and version''' |
| 286 | 287 |
| 287 for line in fileinput.input(filename, inplace=1): | 288 for line in fileinput.input(filename, inplace=1): |
| 288 sys.stdout.write(line.replace('${VERSION}', PLATFORM_VERSION) | 289 sys.stdout.write(line.replace('${VERSION}', PLATFORM_VERSION) |
| 289 .replace('${REVISION}', str(SVNRevision())) | 290 .replace('${REVISION}', str(SVNRevision())) |
| 290 .replace('${DATE}', str(datetime.date.today()))) | 291 .replace('${DATE}', str(datetime.date.today()))) |
| 291 | 292 |
| 292 def CleanDirectory(dir): | 293 def CleanDirectory(dirname): |
| 293 '''Cleans all the contents of a given directory. | 294 '''Cleans all the contents of a given directory. |
| 294 This works even when there are Windows Junctions in the directory | 295 This works even when there are Windows Junctions in the directory |
| 295 | 296 |
| 296 Args: | 297 Args: |
| 297 dir: The directory to clean | 298 dirname: The directory to clean |
| 298 ''' | 299 ''' |
| 299 if sys.platform != 'win32': | 300 if sys.platform != 'win32': |
| 300 shutil.rmtree(dir, ignore_errors=True) | 301 shutil.rmtree(dirname, ignore_errors=True) |
| 301 else: | 302 else: |
| 302 # Intentionally ignore return value since a directory might be in use. | 303 # Intentionally ignore return value since a directory might be in use. |
| 303 subprocess.call(['rmdir', '/Q', '/S', dir], | 304 subprocess.call(['rmdir', '/Q', '/S', dirname], |
| 304 env=os.environ.copy(), | 305 env=os.environ.copy(), |
| 305 shell=True) | 306 shell=True) |
| OLD | NEW |