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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 codecs.open(filename, mode=mode, encoding='utf-8') as f: |
81 return f.read() | 81 content = f.read() |
| 82 if mode.endswith('U'): |
| 83 # codecs.open() has different behavior than open() on python 2.6. |
| 84 return content.replace('\r\n', '\n') |
| 85 return content |
82 | 86 |
83 | 87 |
84 def FileWrite(filename, content, mode='w'): | 88 def FileWrite(filename, content, mode='w'): |
85 with codecs.open(filename, mode=mode, encoding='utf-8') as f: | 89 with codecs.open(filename, mode=mode, encoding='utf-8') as f: |
86 f.write(content) | 90 f.write(content) |
87 | 91 |
88 | 92 |
89 def rmtree(path): | 93 def rmtree(path): |
90 """shutil.rmtree() on steroids. | 94 """shutil.rmtree() on steroids. |
91 | 95 |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) | 763 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) |
760 except ValueError: | 764 except ValueError: |
761 raise Error( | 765 raise Error( |
762 'Failed to process settings, please fix. Content:\n\n%s' % content) | 766 'Failed to process settings, please fix. Content:\n\n%s' % content) |
763 def fix_url(key): | 767 def fix_url(key): |
764 if keyvals.get(key): | 768 if keyvals.get(key): |
765 keyvals[key] = UpgradeToHttps(keyvals[key]) | 769 keyvals[key] = UpgradeToHttps(keyvals[key]) |
766 fix_url('CODE_REVIEW_SERVER') | 770 fix_url('CODE_REVIEW_SERVER') |
767 fix_url('VIEW_VC') | 771 fix_url('VIEW_VC') |
768 return keyvals | 772 return keyvals |
OLD | NEW |