Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import os | |
| 6 | |
| 7 | |
| 8 class Filesystem(object): | |
| 
 
agable
2014/12/09 21:13:24
Seems like this should be in a tests/ directory so
 
Dirk Pranke
2014/12/09 21:32:00
It's used by buildbot-tool directly, not just by t
 
 | |
| 9 """A simple filesystem abstraction, useful for faking out for testing. | |
| 10 | |
| 11 This is a stripped-down version of the Filesystem class provided in the | |
| 12 TYP (Test Your Project) framework: https://github.com/dpranke/typ. | |
| 13 """ | |
| 14 | |
| 15 def abspath(self, path): | |
| 16 return os.path.abspath(path) | |
| 17 | |
| 18 def basename(self, path): | |
| 19 return os.path.basename(path) | |
| 20 | |
| 21 def dirname(self, path): | |
| 22 return os.path.dirname(path) | |
| 23 | |
| 24 def exists(self, *comps): | |
| 25 return os.path.exists(self.join(*comps)) | |
| 26 | |
| 27 def join(self, *comps): | |
| 28 return os.path.join(*comps) | |
| 29 | |
| 30 def listfiles(self, path): | |
| 31 return [path for path in os.listdir(path) | |
| 32 if not os.path.isdir(path) and | |
| 33 not os.path.basename(path).startswith('.')] | |
| 34 | |
| 35 def read_text_file(self, path): | |
| 36 with open(path) as fp: | |
| 37 return fp.read() | |
| 38 | |
| 39 def write_text_file(self, path, contents): | |
| 40 with open(path, 'w') as fp: | |
| 41 fp.write(contents) | |
| OLD | NEW |