Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 lastchange.py -- Chromium revision fetching utility. | 7 lastchange.py -- Chromium revision fetching utility. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import re | 12 import re |
| 13 import subprocess | 13 import subprocess |
| 14 import sys | 14 import sys |
| 15 | 15 |
| 16 | 16 |
| 17 def svn_fetch_revision(): | 17 def svn_fetch_revision(): |
| 18 """ | 18 """ |
| 19 Fetch the Subversion revision for the local tree. | 19 Fetch the Subversion revision for the local tree. |
| 20 | 20 |
| 21 Errors are swallowed. | 21 Errors are swallowed. |
| 22 """ | 22 """ |
| 23 try: | 23 try: |
| 24 p = subprocess.Popen(['svn', 'info'], | 24 p = subprocess.Popen(['svn', 'info'], |
| 25 stdout=subprocess.PIPE, | 25 stdout=subprocess.PIPE, |
| 26 stderr=subprocess.PIPE) | 26 stderr=subprocess.PIPE, |
| 27 except OSError: | 27 shell=(sys.platform=='win32')) |
| 28 except OSError, e: | |
|
Mark Mentovai
2009/06/16 21:21:28
You don't need the ,e here.
| |
| 28 # 'svn' is apparently either not installed or not executable. | 29 # 'svn' is apparently either not installed or not executable. |
| 29 return None | 30 return None |
| 30 revision = None | 31 revision = None |
| 31 if p: | 32 if p: |
| 32 svn_re = re.compile('^Revision:\s+(\S+)$', re.M) | 33 svn_re = re.compile('^Revision:\s+(\d+)', re.M) |
| 33 m = svn_re.search(p.stdout.read()) | 34 m = svn_re.search(p.stdout.read()) |
| 34 if m: | 35 if m: |
| 35 revision = m.group(1) | 36 revision = m.group(1) |
| 36 return revision | 37 return revision |
| 37 | 38 |
| 38 | 39 |
| 39 def git_fetch_id(): | 40 def git_fetch_id(): |
| 40 """ | 41 """ |
| 41 Fetch the GIT identifier for the local tree. | 42 Fetch the GIT identifier for the local tree. |
| 42 | 43 |
| 43 Errors are swallowed. | 44 Errors are swallowed. |
| 44 """ | 45 """ |
| 45 try: | 46 try: |
| 46 p = subprocess.Popen(['git', 'log', '-1'], | 47 p = subprocess.Popen(['git', 'log', '-1'], |
| 47 stdout=subprocess.PIPE, | 48 stdout=subprocess.PIPE, |
| 48 stderr=subprocess.PIPE) | 49 stderr=subprocess.PIPE, |
| 50 shell=(sys.platform=='win32')) | |
| 49 except OSError: | 51 except OSError: |
| 50 # 'git' is apparently either not installed or not executable. | 52 # 'git' is apparently either not installed or not executable. |
| 51 return None | 53 return None |
| 52 id = None | 54 id = None |
| 53 if p: | 55 if p: |
| 54 git_re = re.compile('^\s*git-svn-id:\s+(\S+)@(\d+)', re.M) | 56 git_re = re.compile('^\s*git-svn-id:\s+(\S+)@(\d+)', re.M) |
| 55 m = git_re.search(p.stdout.read()) | 57 m = git_re.search(p.stdout.read()) |
| 56 if m: | 58 if m: |
| 57 id = m.group(2) | 59 id = m.group(2) |
| 58 return id | 60 return id |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 if out_file: | 114 if out_file: |
| 113 write_if_changed(out_file, contents) | 115 write_if_changed(out_file, contents) |
| 114 else: | 116 else: |
| 115 sys.stdout.write(contents) | 117 sys.stdout.write(contents) |
| 116 | 118 |
| 117 return 0 | 119 return 0 |
| 118 | 120 |
| 119 | 121 |
| 120 if __name__ == '__main__': | 122 if __name__ == '__main__': |
| 121 sys.exit(main()) | 123 sys.exit(main()) |
| OLD | NEW |