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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 | 80 |
81 @param user_set_path if None, the user did not specify a path, so look in | 81 @param user_set_path if None, the user did not specify a path, so look in |
82 some likely places; otherwise, only check at this path | 82 some likely places; otherwise, only check at this path |
83 """ | 83 """ |
84 if user_set_path is not None: | 84 if user_set_path is not None: |
85 if os.path.isfile(user_set_path): | 85 if os.path.isfile(user_set_path): |
86 return user_set_path | 86 return user_set_path |
87 raise Exception('unable to find skdiff at user-set path %s' % | 87 raise Exception('unable to find skdiff at user-set path %s' % |
88 user_set_path) | 88 user_set_path) |
89 trunk_path = os.path.join(os.path.dirname(__file__), os.pardir) | 89 trunk_path = os.path.join(os.path.dirname(__file__), os.pardir) |
90 possible_paths = [os.path.join(trunk_path, 'out', 'Release', 'skdiff'), | 90 |
91 os.path.join(trunk_path, 'out', 'Debug', 'skdiff')] | 91 extension = "" |
bsalomon
2013/10/28 21:07:22
is it really dumb to init to an empty string? I do
epoger
2013/10/28 21:14:41
Probably a "real" Python programmer would scoff at
bsalomon
2013/10/29 14:23:43
Done.
| |
92 if os.name is "nt": | |
93 extension = ".exe" | |
94 | |
95 possible_paths = [os.path.join(trunk_path, 'out', 'Release', 'skdiff' + exte nsion), | |
epoger
2013/10/28 21:14:41
wrap at 80 chars please (I love enforcing rules th
bsalomon
2013/10/29 14:23:43
Done.
| |
96 os.path.join(trunk_path, 'out', 'Debug', 'skdiff' + extens ion)] | |
92 for try_path in possible_paths: | 97 for try_path in possible_paths: |
93 if os.path.isfile(try_path): | 98 if os.path.isfile(try_path): |
94 return try_path | 99 return try_path |
95 raise Exception('cannot find skdiff in paths %s; maybe you need to ' | 100 raise Exception('cannot find skdiff in paths %s; maybe you need to ' |
96 'specify the %s option or build skdiff?' % ( | 101 'specify the %s option or build skdiff?' % ( |
97 possible_paths, OPTION_PATH_TO_SKDIFF)) | 102 possible_paths, OPTION_PATH_TO_SKDIFF)) |
98 | 103 |
99 def _DownloadUrlToFile(source_url, dest_path): | 104 def _DownloadUrlToFile(source_url, dest_path): |
100 """Download source_url, and save its contents to dest_path. | 105 """Download source_url, and save its contents to dest_path. |
101 Raises an exception if there were any problems.""" | 106 Raises an exception if there were any problems.""" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 """ | 200 """ |
196 # TODO(epoger): Replace use of "git show" command with lower-level git | 201 # TODO(epoger): Replace use of "git show" command with lower-level git |
197 # commands? senorblanco points out that "git show" is a "porcelain" | 202 # commands? senorblanco points out that "git show" is a "porcelain" |
198 # command, intended for human use, as opposed to the "plumbing" commands | 203 # command, intended for human use, as opposed to the "plumbing" commands |
199 # generally more suitable for scripting. (See | 204 # generally more suitable for scripting. (See |
200 # http://git-scm.com/book/en/Git-Internals-Plumbing-and-Porcelain ) | 205 # http://git-scm.com/book/en/Git-Internals-Plumbing-and-Porcelain ) |
201 # | 206 # |
202 # For now, though, "git show" is the most straightforward implementation | 207 # For now, though, "git show" is the most straightforward implementation |
203 # I could come up with. I tried using "git cat-file", but I had trouble | 208 # I could come up with. I tried using "git cat-file", but I had trouble |
204 # getting it to work as desired. | 209 # getting it to work as desired. |
205 args = ['git', 'show', os.path.join('HEAD:.', file_within_repo)] | 210 args = ['git', 'show', 'HEAD:./' + file_within_repo] |
bsalomon
2013/10/28 21:07:22
we're passing a path from a path that was extracte
epoger
2013/10/28 21:14:41
Makes sense. Please add your explanation to the c
bsalomon
2013/10/29 14:23:43
Done.
| |
206 with open(dest_path, 'wb') as outfile: | 211 with open(dest_path, 'wb') as outfile: |
207 proc = subprocess.Popen(args, stdout=outfile) | 212 proc = subprocess.Popen(args, stdout=outfile) |
208 proc.communicate() | 213 proc.communicate() |
209 if proc.returncode is not 0: | 214 if proc.returncode is not 0: |
210 raise Exception('command "%s" failed' % args) | 215 raise Exception('command "%s" failed' % args) |
211 | 216 |
212 def SvnDiff(path_to_skdiff, dest_dir, source_dir): | 217 def SvnDiff(path_to_skdiff, dest_dir, source_dir): |
213 """Generates a visual diff of all pending changes in source_dir. | 218 """Generates a visual diff of all pending changes in source_dir. |
214 | 219 |
215 @param path_to_skdiff | 220 @param path_to_skdiff |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 help='path to already-built skdiff tool; if not set, ' | 322 help='path to already-built skdiff tool; if not set, ' |
318 'will search for it in typical directories near this ' | 323 'will search for it in typical directories near this ' |
319 'script') | 324 'script') |
320 parser.add_option(OPTION_SOURCE_DIR, | 325 parser.add_option(OPTION_SOURCE_DIR, |
321 action='store', type='string', | 326 action='store', type='string', |
322 default=os.path.join('expectations', 'gm'), | 327 default=os.path.join('expectations', 'gm'), |
323 help='root directory within which to compare all ' + | 328 help='root directory within which to compare all ' + |
324 'files; defaults to "%default"') | 329 'files; defaults to "%default"') |
325 (options, args) = parser.parse_args() | 330 (options, args) = parser.parse_args() |
326 Main(options, args) | 331 Main(options, args) |
OLD | NEW |