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 logging | 10 import logging |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import re | 13 import re |
14 import stat | |
14 import sys | 15 import sys |
15 import textwrap | 16 import textwrap |
16 import urlparse | 17 import urlparse |
18 import urllib | |
17 import urllib2 | 19 import urllib2 |
18 | 20 |
19 try: | 21 try: |
20 import readline # pylint: disable=F0401,W0611 | 22 import readline # pylint: disable=F0401,W0611 |
21 except ImportError: | 23 except ImportError: |
22 pass | 24 pass |
23 | 25 |
24 try: | 26 try: |
25 import simplejson as json # pylint: disable=F0401 | 27 import simplejson as json # pylint: disable=F0401 |
26 except ImportError: | 28 except ImportError: |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 self.viewvc_url = None | 149 self.viewvc_url = None |
148 self.updated = False | 150 self.updated = False |
149 self.did_migrate_check = False | 151 self.did_migrate_check = False |
150 self.is_gerrit = None | 152 self.is_gerrit = None |
151 | 153 |
152 def LazyUpdateIfNeeded(self): | 154 def LazyUpdateIfNeeded(self): |
153 """Updates the settings from a codereview.settings file, if available.""" | 155 """Updates the settings from a codereview.settings file, if available.""" |
154 if not self.updated: | 156 if not self.updated: |
155 cr_settings_file = FindCodereviewSettingsFile() | 157 cr_settings_file = FindCodereviewSettingsFile() |
156 if cr_settings_file: | 158 if cr_settings_file: |
157 LoadCodereviewSettingsFromFile(cr_settings_file) | 159 LoadCodereviewSettingsFromFile(cr_settings_file) |
M-A Ruel
2012/02/10 15:50:05
That's where it should load the file if not presen
ukai
2012/02/13 02:57:43
Done.
| |
158 self.updated = True | 160 self.updated = True |
159 | 161 |
160 def GetDefaultServerUrl(self, error_ok=False): | 162 def GetDefaultServerUrl(self, error_ok=False): |
161 if not self.default_server: | 163 if not self.default_server: |
162 self.LazyUpdateIfNeeded() | 164 self.LazyUpdateIfNeeded() |
163 self.default_server = gclient_utils.UpgradeToHttps( | 165 self.default_server = gclient_utils.UpgradeToHttps( |
164 self._GetConfig('rietveld.server', error_ok=True)) | 166 self._GetConfig('rietveld.server', error_ok=True)) |
165 if error_ok: | 167 if error_ok: |
166 return self.default_server | 168 return self.default_server |
167 if not self.default_server: | 169 if not self.default_server: |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 SetProperty('server', 'CODE_REVIEW_SERVER') | 729 SetProperty('server', 'CODE_REVIEW_SERVER') |
728 # Only server setting is required. Other settings can be absent. | 730 # Only server setting is required. Other settings can be absent. |
729 # In that case, we ignore errors raised during option deletion attempt. | 731 # In that case, we ignore errors raised during option deletion attempt. |
730 SetProperty('cc', 'CC_LIST', unset_error_ok=True) | 732 SetProperty('cc', 'CC_LIST', unset_error_ok=True) |
731 SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) | 733 SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) |
732 SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) | 734 SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) |
733 | 735 |
734 if 'GERRIT_HOST' in keyvals and 'GERRIT_PORT' in keyvals: | 736 if 'GERRIT_HOST' in keyvals and 'GERRIT_PORT' in keyvals: |
735 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) | 737 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) |
736 RunGit(['config', 'gerrit.port', keyvals['GERRIT_PORT']]) | 738 RunGit(['config', 'gerrit.port', keyvals['GERRIT_PORT']]) |
737 # Install the standard commit-msg hook. | |
738 RunCommand(['scp', '-p', '-P', keyvals['GERRIT_PORT'], | |
739 '%s:hooks/commit-msg' % keyvals['GERRIT_HOST'], | |
740 os.path.join(settings.GetRoot(), | |
741 '.git', 'hooks', 'commit-msg')]) | |
742 | 739 |
743 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: | 740 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: |
744 #should be of the form | 741 #should be of the form |
745 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof | 742 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof |
746 #ORIGIN_URL_CONFIG: http://src.chromium.org/git | 743 #ORIGIN_URL_CONFIG: http://src.chromium.org/git |
747 RunGit(['config', keyvals['PUSH_URL_CONFIG'], | 744 RunGit(['config', keyvals['PUSH_URL_CONFIG'], |
748 keyvals['ORIGIN_URL_CONFIG']]) | 745 keyvals['ORIGIN_URL_CONFIG']]) |
749 | 746 |
750 | 747 |
748 def DownloadHooks(): | |
M-A Ruel
2012/02/10 15:50:05
Add force argument
ukai
2012/02/13 02:57:43
Done.
| |
749 """downloads hooks""" | |
750 if settings.GetIsGerrit(): | |
M-A Ruel
2012/02/10 15:50:05
if not settings.GetIsGerrit():
return
reduces i
ukai
2012/02/13 02:57:43
Done.
| |
751 server_url = settings.GetDefaultServerUrl() | |
752 src = '%s/tools/hooks/commit-msg' % server_url | |
753 dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg') | |
754 if not os.access(dst, os.X_OK): | |
755 if os.path.exists(dst): | |
M-A Ruel
2012/02/10 15:50:05
if os.path.exists(dst):
if not force:
return
ukai
2012/02/13 02:57:43
Done.
| |
756 os.remove(dst) | |
757 try: | |
758 urllib.urlretrieve(src, dst) | |
759 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) | |
760 except Exception, e: | |
761 print e | |
762 if os.path.exists(dst): | |
763 os.remove(dst) | |
764 DieWithError('\nFailed to download hooks from %s' % src) | |
765 | |
766 | |
751 @usage('[repo root containing codereview.settings]') | 767 @usage('[repo root containing codereview.settings]') |
752 def CMDconfig(parser, args): | 768 def CMDconfig(parser, args): |
753 """edit configuration for this tree""" | 769 """edit configuration for this tree""" |
754 | 770 |
755 _, args = parser.parse_args(args) | 771 _, args = parser.parse_args(args) |
756 if len(args) == 0: | 772 if len(args) == 0: |
757 GetCodereviewSettingsInteractively() | 773 GetCodereviewSettingsInteractively() |
774 DownloadHooks() | |
M-A Ruel
2012/02/10 15:50:05
True
ukai
2012/02/13 02:57:43
Done.
| |
758 return 0 | 775 return 0 |
759 | 776 |
760 url = args[0] | 777 url = args[0] |
761 if not url.endswith('codereview.settings'): | 778 if not url.endswith('codereview.settings'): |
762 url = os.path.join(url, 'codereview.settings') | 779 url = os.path.join(url, 'codereview.settings') |
763 | 780 |
764 # Load code review settings and download hooks (if available). | 781 # Load code review settings and download hooks (if available). |
765 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) | 782 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) |
783 DownloadHooks() | |
M-A Ruel
2012/02/10 15:50:05
True
ukai
2012/02/13 02:57:43
Done.
| |
766 return 0 | 784 return 0 |
767 | 785 |
768 | 786 |
769 def CMDstatus(parser, args): | 787 def CMDstatus(parser, args): |
770 """show status of changelists""" | 788 """show status of changelists""" |
771 parser.add_option('--field', | 789 parser.add_option('--field', |
772 help='print only specific field (desc|id|patch|url)') | 790 help='print only specific field (desc|id|patch|url)') |
773 (options, args) = parser.parse_args(args) | 791 (options, args) = parser.parse_args(args) |
774 | 792 |
775 # TODO: maybe make show_branches a flag if necessary. | 793 # TODO: maybe make show_branches a flag if necessary. |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1498 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1516 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1499 | 1517 |
1500 # Not a known command. Default to help. | 1518 # Not a known command. Default to help. |
1501 GenUsage(parser, 'help') | 1519 GenUsage(parser, 'help') |
1502 return CMDhelp(parser, argv) | 1520 return CMDhelp(parser, argv) |
1503 | 1521 |
1504 | 1522 |
1505 if __name__ == '__main__': | 1523 if __name__ == '__main__': |
1506 fix_encoding.fix_encoding() | 1524 fix_encoding.fix_encoding() |
1507 sys.exit(main(sys.argv[1:])) | 1525 sys.exit(main(sys.argv[1:])) |
OLD | NEW |