| 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): |
| 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 normpath(self, path): |
| 36 return os.path.normpath(path) |
| 37 |
| 38 def read_text_file(self, path): |
| 39 with open(path) as fp: |
| 40 return fp.read() |
| 41 |
| 42 def relpath(self, path, start='.'): |
| 43 return os.path.relpath(path, start) |
| 44 |
| 45 def write_text_file(self, path, contents): |
| 46 with open(path, 'w') as fp: |
| 47 fp.write(contents) |
| OLD | NEW |