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 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1031 keyvals['ORIGIN_URL_CONFIG']]) | 1031 keyvals['ORIGIN_URL_CONFIG']]) |
| 1032 | 1032 |
| 1033 | 1033 |
| 1034 def urlretrieve(source, destination): | 1034 def urlretrieve(source, destination): |
| 1035 """urllib is broken for SSL connections via a proxy therefore we | 1035 """urllib is broken for SSL connections via a proxy therefore we |
| 1036 can't use urllib.urlretrieve().""" | 1036 can't use urllib.urlretrieve().""" |
| 1037 with open(destination, 'w') as f: | 1037 with open(destination, 'w') as f: |
| 1038 f.write(urllib2.urlopen(source).read()) | 1038 f.write(urllib2.urlopen(source).read()) |
| 1039 | 1039 |
| 1040 | 1040 |
| 1041 def checkHookScript(fname): | |
|
M-A Ruel
2013/11/26 14:06:56
s/checkHookScript/hasSheBang/
ukai
2013/11/26 14:17:20
Done.
| |
| 1042 """Checks fname is a script.""" | |
| 1043 with open(fname) as f: | |
| 1044 s = f.read() | |
|
M-A Ruel
2013/11/26 14:06:56
return f.read(2).startswith('#!'):
ukai
2013/11/26 14:17:20
Done.
| |
| 1045 if not s.startswith('#!'): | |
| 1046 raise Exception('unexpected script') | |
| 1047 | |
| 1048 | |
| 1041 def DownloadHooks(force): | 1049 def DownloadHooks(force): |
| 1042 """downloads hooks | 1050 """downloads hooks |
| 1043 | 1051 |
| 1044 Args: | 1052 Args: |
| 1045 force: True to update hooks. False to install hooks if not present. | 1053 force: True to update hooks. False to install hooks if not present. |
| 1046 """ | 1054 """ |
| 1047 if not settings.GetIsGerrit(): | 1055 if not settings.GetIsGerrit(): |
| 1048 return | 1056 return |
| 1049 server_url = settings.GetDefaultServerUrl() | 1057 src = 'https://gerrit-review.googlesource.com/tools/hooks/commit-msg' |
| 1050 src = '%s/tools/hooks/commit-msg' % server_url | |
| 1051 dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg') | 1058 dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg') |
| 1052 if not os.access(dst, os.X_OK): | 1059 if not os.access(dst, os.X_OK): |
| 1053 if os.path.exists(dst): | 1060 if os.path.exists(dst): |
| 1054 if not force: | 1061 if not force: |
| 1055 return | 1062 return |
| 1056 os.remove(dst) | |
| 1057 try: | 1063 try: |
| 1058 urlretrieve(src, dst) | 1064 urlretrieve(src, dst) |
| 1065 checkHookScript(dst) | |
|
M-A Ruel
2013/11/26 14:06:56
if not hasSheBang(dst):
DieWithError('Not a scri
ukai
2013/11/26 14:17:20
Done.
| |
| 1059 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) | 1066 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) |
| 1060 except Exception: | 1067 except Exception: |
| 1061 if os.path.exists(dst): | 1068 if os.path.exists(dst): |
| 1062 os.remove(dst) | 1069 os.remove(dst) |
| 1063 DieWithError('\nFailed to download hooks from %s' % src) | 1070 DieWithError('\nFailed to download hooks.\n' |
| 1071 'You need to download from\n%s\n' | |
| 1072 'into .git/hooks/commit-msg and ' | |
| 1073 'chmod +x .git/hooks/commit-msg' % src) | |
| 1064 | 1074 |
| 1065 | 1075 |
| 1066 @subcommand.usage('[repo root containing codereview.settings]') | 1076 @subcommand.usage('[repo root containing codereview.settings]') |
| 1067 def CMDconfig(parser, args): | 1077 def CMDconfig(parser, args): |
| 1068 """Edits configuration for this tree.""" | 1078 """Edits configuration for this tree.""" |
| 1069 | 1079 |
| 1070 _, args = parser.parse_args(args) | 1080 _, args = parser.parse_args(args) |
| 1071 if len(args) == 0: | 1081 if len(args) == 0: |
| 1072 GetCodereviewSettingsInteractively() | 1082 GetCodereviewSettingsInteractively() |
| 1073 DownloadHooks(True) | 1083 DownloadHooks(True) |
| (...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2321 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2331 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 2322 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2332 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 2323 | 2333 |
| 2324 | 2334 |
| 2325 if __name__ == '__main__': | 2335 if __name__ == '__main__': |
| 2326 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2336 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 2327 # unit testing. | 2337 # unit testing. |
| 2328 fix_encoding.fix_encoding() | 2338 fix_encoding.fix_encoding() |
| 2329 colorama.init() | 2339 colorama.init() |
| 2330 sys.exit(main(sys.argv[1:])) | 2340 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |