OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Generic utils.""" | 5 """Generic utils.""" |
6 | 6 |
7 import errno | 7 import errno |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import Queue | 10 import Queue |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 # shell=True to allow the shell to handle all forms of quotes in | 727 # shell=True to allow the shell to handle all forms of quotes in |
728 # $EDITOR. | 728 # $EDITOR. |
729 subprocess2.check_call(cmd, shell=True) | 729 subprocess2.check_call(cmd, shell=True) |
730 except subprocess2.CalledProcessError: | 730 except subprocess2.CalledProcessError: |
731 return None | 731 return None |
732 return FileRead(filename) | 732 return FileRead(filename) |
733 finally: | 733 finally: |
734 os.remove(filename) | 734 os.remove(filename) |
735 | 735 |
736 | 736 |
| 737 def UpgradeToHttps(url): |
| 738 """Upgrades random urls to https://. |
| 739 |
| 740 Do not touch unknown urls like ssh:// or git://. |
| 741 Fixes invalid GAE url. |
| 742 """ |
| 743 if not url: |
| 744 return url |
| 745 if not re.match(r'[a-z\-]+\://.*', url): |
| 746 # Make sure it is a valid uri. |
| 747 url = 'https://%s' % url |
| 748 url = re.sub(r'^http\:', r'https:', url) |
| 749 url = re.sub( |
| 750 '^https\:\/\/codereview.chromium.org', |
| 751 'https://chromiumcodereview.appspot.com', |
| 752 url) |
| 753 return url |
| 754 |
| 755 |
737 def ParseCodereviewSettingsContent(content): | 756 def ParseCodereviewSettingsContent(content): |
738 """Process a codereview.settings file properly.""" | 757 """Process a codereview.settings file properly.""" |
739 lines = (l for l in content.splitlines() if not l.strip().startswith("#")) | 758 lines = (l for l in content.splitlines() if not l.strip().startswith("#")) |
740 try: | 759 try: |
741 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) | 760 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) |
742 except ValueError: | 761 except ValueError: |
743 raise Error( | 762 raise Error( |
744 'Failed to process settings, please fix. Content:\n\n%s' % content) | 763 'Failed to process settings, please fix. Content:\n\n%s' % content) |
745 # TODO(maruel): Post-process | 764 def fix_url(key): |
| 765 if keyvals.get(key): |
| 766 keyvals[key] = UpgradeToHttps(keyvals[key]) |
| 767 fix_url('CODE_REVIEW_SERVER') |
| 768 fix_url('VIEW_VC') |
746 return keyvals | 769 return keyvals |
OLD | NEW |