| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 @param dest_dir existing directory within which to write results | 216 @param dest_dir existing directory within which to write results |
| 217 @param source_dir | 217 @param source_dir |
| 218 """ | 218 """ |
| 219 # Validate parameters, filling in default values if necessary and possible. | 219 # Validate parameters, filling in default values if necessary and possible. |
| 220 path_to_skdiff = os.path.abspath(FindPathToSkDiff(path_to_skdiff)) | 220 path_to_skdiff = os.path.abspath(FindPathToSkDiff(path_to_skdiff)) |
| 221 if not dest_dir: | 221 if not dest_dir: |
| 222 dest_dir = tempfile.mkdtemp() | 222 dest_dir = tempfile.mkdtemp() |
| 223 dest_dir = os.path.abspath(dest_dir) | 223 dest_dir = os.path.abspath(dest_dir) |
| 224 | 224 |
| 225 os.chdir(source_dir) | 225 os.chdir(source_dir) |
| 226 using_svn = os.path.isdir('.svn') | 226 svn_repo = svn.Svn('.') |
| 227 using_svn = True |
| 228 try: |
| 229 svn_repo.GetInfo() |
| 230 except: |
| 231 using_svn = False |
| 227 | 232 |
| 228 # Prepare temporary directories. | 233 # Prepare temporary directories. |
| 229 modified_flattened_dir = os.path.join(dest_dir, 'modified_flattened') | 234 modified_flattened_dir = os.path.join(dest_dir, 'modified_flattened') |
| 230 original_flattened_dir = os.path.join(dest_dir, 'original_flattened') | 235 original_flattened_dir = os.path.join(dest_dir, 'original_flattened') |
| 231 diff_dir = os.path.join(dest_dir, 'diffs') | 236 diff_dir = os.path.join(dest_dir, 'diffs') |
| 232 for dir in [modified_flattened_dir, original_flattened_dir, diff_dir] : | 237 for dir in [modified_flattened_dir, original_flattened_dir, diff_dir] : |
| 233 shutil.rmtree(dir, ignore_errors=True) | 238 shutil.rmtree(dir, ignore_errors=True) |
| 234 os.mkdir(dir) | 239 os.mkdir(dir) |
| 235 | 240 |
| 236 # Get a list of all locally modified (including added/deleted) files, | 241 # Get a list of all locally modified (including added/deleted) files, |
| 237 # descending subdirectories. | 242 # descending subdirectories. |
| 238 if using_svn: | 243 if using_svn: |
| 239 svn_repo = svn.Svn('.') | |
| 240 modified_file_paths = svn_repo.GetFilesWithStatus( | 244 modified_file_paths = svn_repo.GetFilesWithStatus( |
| 241 svn.STATUS_ADDED | svn.STATUS_DELETED | svn.STATUS_MODIFIED) | 245 svn.STATUS_ADDED | svn.STATUS_DELETED | svn.STATUS_MODIFIED) |
| 242 else: | 246 else: |
| 243 modified_file_paths = _GitGetModifiedFiles() | 247 modified_file_paths = _GitGetModifiedFiles() |
| 244 | 248 |
| 245 # For each modified file: | 249 # For each modified file: |
| 246 # 1. copy its current contents into modified_flattened_dir | 250 # 1. copy its current contents into modified_flattened_dir |
| 247 # 2. copy its original contents into original_flattened_dir | 251 # 2. copy its original contents into original_flattened_dir |
| 248 for modified_file_path in modified_file_paths: | 252 for modified_file_path in modified_file_paths: |
| 249 if modified_file_path.endswith('.json'): | 253 if modified_file_path.endswith('.json'): |
| 250 # Special handling for JSON files, in the hopes that they | 254 # Special handling for JSON files, in the hopes that they |
| 251 # contain GM result summaries. | 255 # contain GM result summaries. |
| 252 (_unused, original_file_path) = tempfile.mkstemp() | 256 original_file = tempfile.NamedTemporaryFile(delete = False) |
| 257 original_file.close() |
| 253 if using_svn: | 258 if using_svn: |
| 254 svn_repo.ExportBaseVersionOfFile( | 259 svn_repo.ExportBaseVersionOfFile( |
| 255 modified_file_path, original_file_path) | 260 modified_file_path, original_file.name) |
| 256 else: | 261 else: |
| 257 _GitExportBaseVersionOfFile( | 262 _GitExportBaseVersionOfFile( |
| 258 modified_file_path, original_file_path) | 263 modified_file_path, original_file.name) |
| 259 platform_prefix = re.sub(os.sep, '__', | 264 original_directory = os.path.dirname(original_file.name) |
| 260 os.path.dirname(modified_file_path)) + '__' | 265 platform_prefix = (re.sub(re.escape(os.sep), '__', |
| 261 _CallJsonDiff(old_json_path=original_file_path, | 266 os.path.splitdrive(original_directory)[1]) |
| 267 + '__') |
| 268 _CallJsonDiff(old_json_path=original_file.name, |
| 262 new_json_path=modified_file_path, | 269 new_json_path=modified_file_path, |
| 263 old_flattened_dir=original_flattened_dir, | 270 old_flattened_dir=original_flattened_dir, |
| 264 new_flattened_dir=modified_flattened_dir, | 271 new_flattened_dir=modified_flattened_dir, |
| 265 filename_prefix=platform_prefix) | 272 filename_prefix=platform_prefix) |
| 266 os.remove(original_file_path) | 273 os.remove(original_file.name) |
| 267 else: | 274 else: |
| 268 dest_filename = re.sub(os.sep, '__', modified_file_path) | 275 dest_filename = re.sub(re.escape(os.sep), '__', modified_file_path) |
| 269 # If the file had STATUS_DELETED, it won't exist anymore... | 276 # If the file had STATUS_DELETED, it won't exist anymore... |
| 270 if os.path.isfile(modified_file_path): | 277 if os.path.isfile(modified_file_path): |
| 271 shutil.copyfile(modified_file_path, | 278 shutil.copyfile(modified_file_path, |
| 272 os.path.join(modified_flattened_dir, | 279 os.path.join(modified_flattened_dir, |
| 273 dest_filename)) | 280 dest_filename)) |
| 274 if using_svn: | 281 if using_svn: |
| 275 svn_repo.ExportBaseVersionOfFile( | 282 svn_repo.ExportBaseVersionOfFile( |
| 276 modified_file_path, | 283 modified_file_path, |
| 277 os.path.join(original_flattened_dir, dest_filename)) | 284 os.path.join(original_flattened_dir, dest_filename)) |
| 278 else: | 285 else: |
| 279 _GitExportBaseVersionOfFile( | 286 _GitExportBaseVersionOfFile( |
| 280 modified_file_path, | 287 modified_file_path, |
| 281 os.path.join(original_flattened_dir, dest_filename)) | 288 os.path.join(original_flattened_dir, dest_filename)) |
| 282 | 289 |
| 283 # Run skdiff: compare original_flattened_dir against modified_flattened_dir | 290 # Run skdiff: compare original_flattened_dir against modified_flattened_dir |
| 284 RunCommand('%s %s %s %s' % (path_to_skdiff, original_flattened_dir, | 291 RunCommand('%s %s %s %s' % (path_to_skdiff, original_flattened_dir, |
| 285 modified_flattened_dir, diff_dir)) | 292 modified_flattened_dir, diff_dir)) |
| 293 |
| 286 print '\nskdiff results are ready in file://%s/index.html' % diff_dir | 294 print '\nskdiff results are ready in file://%s/index.html' % diff_dir |
| 287 | 295 |
| 288 def RaiseUsageException(): | 296 def RaiseUsageException(): |
| 289 raise Exception('%s\nRun with --help for more detail.' % ( | 297 raise Exception('%s\nRun with --help for more detail.' % ( |
| 290 USAGE_STRING % __file__)) | 298 USAGE_STRING % __file__)) |
| 291 | 299 |
| 292 def Main(options, args): | 300 def Main(options, args): |
| 293 """Allow other scripts to call this script with fake command-line args. | 301 """Allow other scripts to call this script with fake command-line args. |
| 294 """ | 302 """ |
| 295 num_args = len(args) | 303 num_args = len(args) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 310 help='path to already-built skdiff tool; if not set, ' | 318 help='path to already-built skdiff tool; if not set, ' |
| 311 'will search for it in typical directories near this ' | 319 'will search for it in typical directories near this ' |
| 312 'script') | 320 'script') |
| 313 parser.add_option(OPTION_SOURCE_DIR, | 321 parser.add_option(OPTION_SOURCE_DIR, |
| 314 action='store', type='string', | 322 action='store', type='string', |
| 315 default=os.path.join('expectations', 'gm'), | 323 default=os.path.join('expectations', 'gm'), |
| 316 help='root directory within which to compare all ' + | 324 help='root directory within which to compare all ' + |
| 317 'files; defaults to "%default"') | 325 'files; defaults to "%default"') |
| 318 (options, args) = parser.parse_args() | 326 (options, args) = parser.parse_args() |
| 319 Main(options, args) | 327 Main(options, args) |
| OLD | NEW |