Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
| 7 | 7 |
| 8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
| 9 | 9 |
| 10 import json | 10 import json |
| 11 import logging | 11 import logging |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import re | 14 import re |
| 15 import stat | 15 import stat |
| 16 import sys | 16 import sys |
| 17 import textwrap | 17 import textwrap |
| 18 import urlparse | 18 import urlparse |
| 19 import urllib | |
| 20 import urllib2 | 19 import urllib2 |
| 21 | 20 |
| 22 try: | 21 try: |
| 23 import readline # pylint: disable=F0401,W0611 | 22 import readline # pylint: disable=F0401,W0611 |
| 24 except ImportError: | 23 except ImportError: |
| 25 pass | 24 pass |
| 26 | 25 |
| 27 | 26 |
| 28 from third_party import upload | 27 from third_party import upload |
| 29 import breakpad # pylint: disable=W0611 | 28 import breakpad # pylint: disable=W0611 |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 RunGit(['config', 'gerrit.port', keyvals['GERRIT_PORT']]) | 748 RunGit(['config', 'gerrit.port', keyvals['GERRIT_PORT']]) |
| 750 | 749 |
| 751 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: | 750 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: |
| 752 #should be of the form | 751 #should be of the form |
| 753 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof | 752 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof |
| 754 #ORIGIN_URL_CONFIG: http://src.chromium.org/git | 753 #ORIGIN_URL_CONFIG: http://src.chromium.org/git |
| 755 RunGit(['config', keyvals['PUSH_URL_CONFIG'], | 754 RunGit(['config', keyvals['PUSH_URL_CONFIG'], |
| 756 keyvals['ORIGIN_URL_CONFIG']]) | 755 keyvals['ORIGIN_URL_CONFIG']]) |
| 757 | 756 |
| 758 | 757 |
| 758 def urlretrieve(source, destination): | |
| 759 with open(destination, 'w+') as f: | |
|
M-A Ruel
2012/08/01 13:57:21
Why more 'w+'? Please use 'w'
Also add a doctring
joshuagl
2012/08/01 18:50:20
Will do both of the above.
| |
| 760 f.write(urllib2.urlopen(source).read()) | |
| 761 | |
| 762 | |
| 759 def DownloadHooks(force): | 763 def DownloadHooks(force): |
| 760 """downloads hooks | 764 """downloads hooks |
| 761 | 765 |
| 762 Args: | 766 Args: |
| 763 force: True to update hooks. False to install hooks if not present. | 767 force: True to update hooks. False to install hooks if not present. |
| 764 """ | 768 """ |
| 765 if not settings.GetIsGerrit(): | 769 if not settings.GetIsGerrit(): |
| 766 return | 770 return |
| 767 server_url = settings.GetDefaultServerUrl() | 771 server_url = settings.GetDefaultServerUrl() |
| 768 src = '%s/tools/hooks/commit-msg' % server_url | 772 src = '%s/tools/hooks/commit-msg' % server_url |
| 769 dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg') | 773 dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg') |
| 770 if not os.access(dst, os.X_OK): | 774 if not os.access(dst, os.X_OK): |
| 771 if os.path.exists(dst): | 775 if os.path.exists(dst): |
| 772 if not force: | 776 if not force: |
| 773 return | 777 return |
| 774 os.remove(dst) | 778 os.remove(dst) |
| 775 try: | 779 try: |
| 776 urllib.urlretrieve(src, dst) | 780 urlretrieve(src, dst) |
| 777 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) | 781 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) |
| 778 except Exception: | 782 except Exception: |
| 779 if os.path.exists(dst): | 783 if os.path.exists(dst): |
| 780 os.remove(dst) | 784 os.remove(dst) |
| 781 DieWithError('\nFailed to download hooks from %s' % src) | 785 DieWithError('\nFailed to download hooks from %s' % src) |
| 782 | 786 |
| 783 | 787 |
| 784 @usage('[repo root containing codereview.settings]') | 788 @usage('[repo root containing codereview.settings]') |
| 785 def CMDconfig(parser, args): | 789 def CMDconfig(parser, args): |
| 786 """edit configuration for this tree""" | 790 """edit configuration for this tree""" |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1602 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1606 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1603 | 1607 |
| 1604 # Not a known command. Default to help. | 1608 # Not a known command. Default to help. |
| 1605 GenUsage(parser, 'help') | 1609 GenUsage(parser, 'help') |
| 1606 return CMDhelp(parser, argv) | 1610 return CMDhelp(parser, argv) |
| 1607 | 1611 |
| 1608 | 1612 |
| 1609 if __name__ == '__main__': | 1613 if __name__ == '__main__': |
| 1610 fix_encoding.fix_encoding() | 1614 fix_encoding.fix_encoding() |
| 1611 sys.exit(main(sys.argv[1:])) | 1615 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |