| 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 errno | 8 import errno |
| 8 import logging | 9 import logging |
| 9 import os | 10 import os |
| 10 import Queue | 11 import Queue |
| 11 import re | 12 import re |
| 12 import stat | 13 import stat |
| 13 import sys | 14 import sys |
| 14 import tempfile | 15 import tempfile |
| 15 import threading | 16 import threading |
| 16 import time | 17 import time |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 def __str__(self): | 70 def __str__(self): |
| 70 output = '' | 71 output = '' |
| 71 for i in dir(self): | 72 for i in dir(self): |
| 72 if i.startswith('__'): | 73 if i.startswith('__'): |
| 73 continue | 74 continue |
| 74 output += '%s = %s\n' % (i, str(getattr(self, i, ''))) | 75 output += '%s = %s\n' % (i, str(getattr(self, i, ''))) |
| 75 return output | 76 return output |
| 76 | 77 |
| 77 | 78 |
| 78 def FileRead(filename, mode='rU'): | 79 def FileRead(filename, mode='rU'): |
| 79 content = None | 80 with codecs.open(filename, mode=mode, encoding='utf-8') as f: |
| 80 f = open(filename, mode) | 81 return f.read() |
| 81 try: | |
| 82 content = f.read() | |
| 83 finally: | |
| 84 f.close() | |
| 85 return content | |
| 86 | 82 |
| 87 | 83 |
| 88 def FileWrite(filename, content, mode='w'): | 84 def FileWrite(filename, content, mode='w'): |
| 89 f = open(filename, mode) | 85 with codecs.open(filename, mode=mode, encoding='utf-8') as f: |
| 90 try: | |
| 91 f.write(content) | 86 f.write(content) |
| 92 finally: | |
| 93 f.close() | |
| 94 | 87 |
| 95 | 88 |
| 96 def rmtree(path): | 89 def rmtree(path): |
| 97 """shutil.rmtree() on steroids. | 90 """shutil.rmtree() on steroids. |
| 98 | 91 |
| 99 Recursively removes a directory, even if it's marked read-only. | 92 Recursively removes a directory, even if it's marked read-only. |
| 100 | 93 |
| 101 shutil.rmtree() doesn't work on Windows if any of the files or directories | 94 shutil.rmtree() doesn't work on Windows if any of the files or directories |
| 102 are read-only, which svn repositories and some .svn files are. We need to | 95 are read-only, which svn repositories and some .svn files are. We need to |
| 103 be able to force the files to be writable (i.e., deletable) as we traverse | 96 be able to force the files to be writable (i.e., deletable) as we traverse |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) | 759 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) |
| 767 except ValueError: | 760 except ValueError: |
| 768 raise Error( | 761 raise Error( |
| 769 'Failed to process settings, please fix. Content:\n\n%s' % content) | 762 'Failed to process settings, please fix. Content:\n\n%s' % content) |
| 770 def fix_url(key): | 763 def fix_url(key): |
| 771 if keyvals.get(key): | 764 if keyvals.get(key): |
| 772 keyvals[key] = UpgradeToHttps(keyvals[key]) | 765 keyvals[key] = UpgradeToHttps(keyvals[key]) |
| 773 fix_url('CODE_REVIEW_SERVER') | 766 fix_url('CODE_REVIEW_SERVER') |
| 774 fix_url('VIEW_VC') | 767 fix_url('VIEW_VC') |
| 775 return keyvals | 768 return keyvals |
| OLD | NEW |