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 codecs | 7 import codecs |
8 import errno | 8 import errno |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if i.startswith('__'): | 73 if i.startswith('__'): |
74 continue | 74 continue |
75 output += '%s = %s\n' % (i, str(getattr(self, i, ''))) | 75 output += '%s = %s\n' % (i, str(getattr(self, i, ''))) |
76 return output | 76 return output |
77 | 77 |
78 | 78 |
79 def FileRead(filename, mode='rU'): | 79 def FileRead(filename, mode='rU'): |
80 with open(filename, mode=mode) as f: | 80 with open(filename, mode=mode) as f: |
81 # codecs.open() has different behavior than open() on python 2.6 so use | 81 # codecs.open() has different behavior than open() on python 2.6 so use |
82 # open() and decode manually. | 82 # open() and decode manually. |
83 return f.read().decode('utf-8') | 83 s = f.read() |
| 84 try: |
| 85 return s.decode('utf-8') |
| 86 except UnicodeDecodeError: |
| 87 return s |
84 | 88 |
85 | 89 |
86 def FileWrite(filename, content, mode='w'): | 90 def FileWrite(filename, content, mode='w'): |
87 with codecs.open(filename, mode=mode, encoding='utf-8') as f: | 91 with codecs.open(filename, mode=mode, encoding='utf-8') as f: |
88 f.write(content) | 92 f.write(content) |
89 | 93 |
90 | 94 |
91 def rmtree(path): | 95 def rmtree(path): |
92 """shutil.rmtree() on steroids. | 96 """shutil.rmtree() on steroids. |
93 | 97 |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) | 765 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) |
762 except ValueError: | 766 except ValueError: |
763 raise Error( | 767 raise Error( |
764 'Failed to process settings, please fix. Content:\n\n%s' % content) | 768 'Failed to process settings, please fix. Content:\n\n%s' % content) |
765 def fix_url(key): | 769 def fix_url(key): |
766 if keyvals.get(key): | 770 if keyvals.get(key): |
767 keyvals[key] = UpgradeToHttps(keyvals[key]) | 771 keyvals[key] = UpgradeToHttps(keyvals[key]) |
768 fix_url('CODE_REVIEW_SERVER') | 772 fix_url('CODE_REVIEW_SERVER') |
769 fix_url('VIEW_VC') | 773 fix_url('VIEW_VC') |
770 return keyvals | 774 return keyvals |
OLD | NEW |