| 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 """Generic utilities for all python scripts.""" | 5 """Generic utilities for all python scripts.""" |
| 6 | 6 |
| 7 import atexit | 7 import atexit |
| 8 import httplib |
| 8 import os | 9 import os |
| 9 import signal | 10 import signal |
| 10 import stat | 11 import stat |
| 11 import subprocess | 12 import subprocess |
| 12 import sys | 13 import sys |
| 13 import tempfile | 14 import tempfile |
| 15 import urlparse |
| 14 | 16 |
| 15 | 17 |
| 16 def GetPlatformName(): | 18 def GetPlatformName(): |
| 17 """Return a string to be used in paths for the platform.""" | 19 """Return a string to be used in paths for the platform.""" |
| 18 if IsWindows(): | 20 if IsWindows(): |
| 19 return 'win' | 21 return 'win' |
| 20 if IsMac(): | 22 if IsMac(): |
| 21 return 'mac' | 23 return 'mac' |
| 22 if IsLinux(): | 24 if IsLinux(): |
| 23 return 'linux' | 25 return 'linux' |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 cmd: list of command arguments. | 118 cmd: list of command arguments. |
| 117 cwd: working directory to execute the command, or None if the current | 119 cwd: working directory to execute the command, or None if the current |
| 118 working directory should be used. | 120 working directory should be used. |
| 119 | 121 |
| 120 Returns: | 122 Returns: |
| 121 The exit code of the command. | 123 The exit code of the command. |
| 122 """ | 124 """ |
| 123 process = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, cwd=cwd) | 125 process = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, cwd=cwd) |
| 124 process.wait() | 126 process.wait() |
| 125 return process.returncode | 127 return process.returncode |
| 128 |
| 129 |
| 130 def DoesUrlExist(url): |
| 131 """Determines whether a resource exists at the given URL. |
| 132 |
| 133 Args: |
| 134 url: URL to be verified. |
| 135 |
| 136 Returns: |
| 137 True if url exists, otherwise False. |
| 138 """ |
| 139 parsed = urlparse.urlparse(url) |
| 140 try: |
| 141 conn = httplib.HTTPConnection(parsed.netloc) |
| 142 conn.request('HEAD', parsed.path) |
| 143 response = conn.getresponse() |
| 144 except (socket.gaierror, socket.error): |
| 145 return False |
| 146 finally: |
| 147 conn.close() |
| 148 # Follow both permanent (301) and temporary (302) redirects. |
| 149 if response.status == 302 or response.status == 301: |
| 150 return DoesUrlExist(response.getheader('location')) |
| 151 return response.status == 200 |
| OLD | NEW |