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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 def __str__(self): | 70 def __str__(self): |
71 output = '' | 71 output = '' |
72 for i in dir(self): | 72 for i in dir(self): |
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 codecs.open(filename, mode=mode, encoding='utf-8') as f: | 80 with open(filename, mode=mode) as f: |
81 content = f.read() | 81 # codecs.open() has different behavior than open() on python 2.6. |
cmp
2012/07/10 01:27:02
since you're no longer calling codecs.open(), this
| |
82 if mode.endswith('U'): | 82 return f.read().decode('utf-8') |
83 # codecs.open() has different behavior than open() on python 2.6. | |
84 return content.replace('\r\n', '\n') | |
85 return content | |
86 | 83 |
87 | 84 |
88 def FileWrite(filename, content, mode='w'): | 85 def FileWrite(filename, content, mode='w'): |
89 with codecs.open(filename, mode=mode, encoding='utf-8') as f: | 86 with codecs.open(filename, mode=mode, encoding='utf-8') as f: |
90 f.write(content) | 87 f.write(content) |
91 | 88 |
92 | 89 |
93 def rmtree(path): | 90 def rmtree(path): |
94 """shutil.rmtree() on steroids. | 91 """shutil.rmtree() on steroids. |
95 | 92 |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 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) |
764 except ValueError: | 761 except ValueError: |
765 raise Error( | 762 raise Error( |
766 'Failed to process settings, please fix. Content:\n\n%s' % content) | 763 'Failed to process settings, please fix. Content:\n\n%s' % content) |
767 def fix_url(key): | 764 def fix_url(key): |
768 if keyvals.get(key): | 765 if keyvals.get(key): |
769 keyvals[key] = UpgradeToHttps(keyvals[key]) | 766 keyvals[key] = UpgradeToHttps(keyvals[key]) |
770 fix_url('CODE_REVIEW_SERVER') | 767 fix_url('CODE_REVIEW_SERVER') |
771 fix_url('VIEW_VC') | 768 fix_url('VIEW_VC') |
772 return keyvals | 769 return keyvals |
OLD | NEW |