Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 ''' | 2 ''' |
| 3 Copyright 2012 Google Inc. | 3 Copyright 2012 Google Inc. |
| 4 | 4 |
| 5 Use of this source code is governed by a BSD-style license that can be | 5 Use of this source code is governed by a BSD-style license that can be |
| 6 found in the LICENSE file. | 6 found in the LICENSE file. |
| 7 ''' | 7 ''' |
| 8 | 8 |
| 9 ''' | 9 ''' |
| 10 Generates a visual diff of all pending changes in the local SVN (or git!) | 10 Generates a visual diff of all pending changes in the local SVN (or git!) |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 # the 'tools' directory containing this script, which will be the case if | 39 # the 'tools' directory containing this script, which will be the case if |
| 40 # 'trunk' was checked out as a single unit. | 40 # 'trunk' was checked out as a single unit. |
| 41 GM_DIRECTORY = os.path.realpath( | 41 GM_DIRECTORY = os.path.realpath( |
| 42 os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) | 42 os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) |
| 43 if GM_DIRECTORY not in sys.path: | 43 if GM_DIRECTORY not in sys.path: |
| 44 sys.path.append(GM_DIRECTORY) | 44 sys.path.append(GM_DIRECTORY) |
| 45 import gm_json | 45 import gm_json |
| 46 import jsondiff | 46 import jsondiff |
| 47 import svn | 47 import svn |
| 48 | 48 |
| 49 from common.py.utils import git_utils | |
|
tfarina
2014/10/09 03:07:10
is this right? I'm not familiar with python way to
borenet
2014/10/09 12:14:36
It depends on what's in PYTHONPATH. I'm fine with
tfarina
2014/10/10 00:03:59
Done.
| |
| 50 | |
| 49 USAGE_STRING = 'Usage: %s [options]' | 51 USAGE_STRING = 'Usage: %s [options]' |
| 50 HELP_STRING = ''' | 52 HELP_STRING = ''' |
| 51 | 53 |
| 52 Generates a visual diff of all pending changes in the local SVN/git checkout. | 54 Generates a visual diff of all pending changes in the local SVN/git checkout. |
| 53 | 55 |
| 54 This includes a list of all files that have been added, deleted, or modified | 56 This includes a list of all files that have been added, deleted, or modified |
| 55 (as far as SVN/git knows about). For any image modifications, pixel diffs will | 57 (as far as SVN/git knows about). For any image modifications, pixel diffs will |
| 56 be generated. | 58 be generated. |
| 57 | 59 |
| 58 ''' | 60 ''' |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 @param args a list of arguments | 180 @param args a list of arguments |
| 179 """ | 181 """ |
| 180 proc = subprocess.Popen(args, | 182 proc = subprocess.Popen(args, |
| 181 stdout=subprocess.PIPE, | 183 stdout=subprocess.PIPE, |
| 182 stderr=subprocess.PIPE) | 184 stderr=subprocess.PIPE) |
| 183 (stdout, stderr) = proc.communicate() | 185 (stdout, stderr) = proc.communicate() |
| 184 if proc.returncode is not 0: | 186 if proc.returncode is not 0: |
| 185 raise Exception('command "%s" failed: %s' % (args, stderr)) | 187 raise Exception('command "%s" failed: %s' % (args, stderr)) |
| 186 return stdout | 188 return stdout |
| 187 | 189 |
| 188 def _GitGetModifiedFiles(): | |
| 189 """Returns a list of locally modified files within the current working dir. | |
| 190 | |
| 191 TODO(epoger): Move this into a git utility package? | |
| 192 """ | |
| 193 return _RunCommand(['git', 'ls-files', '-m']).splitlines() | |
| 194 | 190 |
| 195 def _GitExportBaseVersionOfFile(file_within_repo, dest_path): | 191 def _GitExportBaseVersionOfFile(file_within_repo, dest_path): |
| 196 """Retrieves a copy of the base version of a file within the repository. | 192 """Retrieves a copy of the base version of a file within the repository. |
| 197 | 193 |
| 198 @param file_within_repo path to the file within the repo whose base | 194 @param file_within_repo path to the file within the repo whose base |
| 199 version you wish to obtain | 195 version you wish to obtain |
| 200 @param dest_path destination to which to write the base content | 196 @param dest_path destination to which to write the base content |
| 201 | 197 |
| 202 TODO(epoger): Move this into a git utility package? | 198 TODO(epoger): Move this into a git utility package? |
| 203 """ | 199 """ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 for dir in [modified_flattened_dir, original_flattened_dir, diff_dir] : | 243 for dir in [modified_flattened_dir, original_flattened_dir, diff_dir] : |
| 248 shutil.rmtree(dir, ignore_errors=True) | 244 shutil.rmtree(dir, ignore_errors=True) |
| 249 os.mkdir(dir) | 245 os.mkdir(dir) |
| 250 | 246 |
| 251 # Get a list of all locally modified (including added/deleted) files, | 247 # Get a list of all locally modified (including added/deleted) files, |
| 252 # descending subdirectories. | 248 # descending subdirectories. |
| 253 if using_svn: | 249 if using_svn: |
| 254 modified_file_paths = svn_repo.GetFilesWithStatus( | 250 modified_file_paths = svn_repo.GetFilesWithStatus( |
| 255 svn.STATUS_ADDED | svn.STATUS_DELETED | svn.STATUS_MODIFIED) | 251 svn.STATUS_ADDED | svn.STATUS_DELETED | svn.STATUS_MODIFIED) |
| 256 else: | 252 else: |
| 257 modified_file_paths = _GitGetModifiedFiles() | 253 modified_file_paths = git_utils.GetModifiedFiles() |
| 258 | 254 |
| 259 # For each modified file: | 255 # For each modified file: |
| 260 # 1. copy its current contents into modified_flattened_dir | 256 # 1. copy its current contents into modified_flattened_dir |
| 261 # 2. copy its original contents into original_flattened_dir | 257 # 2. copy its original contents into original_flattened_dir |
| 262 for modified_file_path in modified_file_paths: | 258 for modified_file_path in modified_file_paths: |
| 263 if modified_file_path.endswith('.json'): | 259 if modified_file_path.endswith('.json'): |
| 264 # Special handling for JSON files, in the hopes that they | 260 # Special handling for JSON files, in the hopes that they |
| 265 # contain GM result summaries. | 261 # contain GM result summaries. |
| 266 original_file = tempfile.NamedTemporaryFile(delete = False) | 262 original_file = tempfile.NamedTemporaryFile(delete = False) |
| 267 original_file.close() | 263 original_file.close() |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 help='path to already-built skdiff tool; if not set, ' | 323 help='path to already-built skdiff tool; if not set, ' |
| 328 'will search for it in typical directories near this ' | 324 'will search for it in typical directories near this ' |
| 329 'script') | 325 'script') |
| 330 parser.add_option(OPTION_SOURCE_DIR, | 326 parser.add_option(OPTION_SOURCE_DIR, |
| 331 action='store', type='string', | 327 action='store', type='string', |
| 332 default=os.path.join('expectations', 'gm'), | 328 default=os.path.join('expectations', 'gm'), |
| 333 help='root directory within which to compare all ' + | 329 help='root directory within which to compare all ' + |
| 334 'files; defaults to "%default"') | 330 'files; defaults to "%default"') |
| 335 (options, args) = parser.parse_args() | 331 (options, args) = parser.parse_args() |
| 336 Main(options, args) | 332 Main(options, args) |
| OLD | NEW |