OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 |
11 import re | 11 import re |
12 import stat | 12 import stat |
13 import sys | 13 import sys |
14 import tempfile | 14 import tempfile |
15 import threading | 15 import threading |
16 import time | 16 import time |
| 17 import urlparse |
17 | 18 |
18 import subprocess2 | 19 import subprocess2 |
19 | 20 |
20 | 21 |
21 class Error(Exception): | 22 class Error(Exception): |
22 """gclient exception class.""" | 23 """gclient exception class.""" |
23 pass | 24 pass |
24 | 25 |
25 | 26 |
26 def SplitUrlRevision(url): | 27 def SplitUrlRevision(url): |
(...skipping 700 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 | 728 # shell=True to allow the shell to handle all forms of quotes in |
728 # $EDITOR. | 729 # $EDITOR. |
729 subprocess2.check_call(cmd, shell=True) | 730 subprocess2.check_call(cmd, shell=True) |
730 except subprocess2.CalledProcessError: | 731 except subprocess2.CalledProcessError: |
731 return None | 732 return None |
732 return FileRead(filename) | 733 return FileRead(filename) |
733 finally: | 734 finally: |
734 os.remove(filename) | 735 os.remove(filename) |
735 | 736 |
736 | 737 |
| 738 def UpgradeToHttps(url): |
| 739 """Upgrades random urls to https://. |
| 740 |
| 741 Do not touch unknown urls like ssh:// or git://. |
| 742 Do not touch http:// urls with a port number, |
| 743 Fixes invalid GAE url. |
| 744 """ |
| 745 if not url: |
| 746 return url |
| 747 if not re.match(r'[a-z\-]+\://.*', url): |
| 748 # Make sure it is a valid uri. Otherwise, urlparse() will consider it a |
| 749 # relative url and will use http:///foo. Note that it defaults to http:// |
| 750 # for compatibility with naked url like "localhost:8080". |
| 751 url = 'http://%s' % url |
| 752 parsed = list(urlparse.urlparse(url)) |
| 753 # Do not automatically upgrade http to https if a port number is provided. |
| 754 if parsed[0] == 'http' and not re.match(r'^.+?\:\d+$', parsed[1]): |
| 755 parsed[0] = 'https' |
| 756 # Until GAE supports SNI, manually convert the url. |
| 757 if parsed[1] == 'codereview.chromium.org': |
| 758 parsed[1] = 'chromiumcodereview.appspot.com' |
| 759 return urlparse.urlunparse(parsed) |
| 760 |
| 761 |
737 def ParseCodereviewSettingsContent(content): | 762 def ParseCodereviewSettingsContent(content): |
738 """Process a codereview.settings file properly.""" | 763 """Process a codereview.settings file properly.""" |
739 lines = (l for l in content.splitlines() if not l.strip().startswith("#")) | 764 lines = (l for l in content.splitlines() if not l.strip().startswith("#")) |
740 try: | 765 try: |
741 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) | 766 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) |
742 except ValueError: | 767 except ValueError: |
743 raise Error( | 768 raise Error( |
744 'Failed to process settings, please fix. Content:\n\n%s' % content) | 769 'Failed to process settings, please fix. Content:\n\n%s' % content) |
745 # TODO(maruel): Post-process | 770 def fix_url(key): |
| 771 if keyvals.get(key): |
| 772 keyvals[key] = UpgradeToHttps(keyvals[key]) |
| 773 fix_url('CODE_REVIEW_SERVER') |
| 774 fix_url('VIEW_VC') |
746 return keyvals | 775 return keyvals |
OLD | NEW |