| OLD | NEW |
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Wraps os, os.path and shutil functions to work around MAX_PATH on Windows.""" | 5 """Wraps os, os.path and shutil functions to work around MAX_PATH on Windows.""" |
| 6 | 6 |
| 7 import __builtin__ | 7 import __builtin__ |
| 8 import inspect | 8 import inspect |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 | 84 |
| 85 def renames(old, new): | 85 def renames(old, new): |
| 86 return os.renames(extend(old), extend(new)) | 86 return os.renames(extend(old), extend(new)) |
| 87 | 87 |
| 88 | 88 |
| 89 def symlink(source, link_name): | 89 def symlink(source, link_name): |
| 90 return os.symlink(source, extend(link_name)) | 90 return os.symlink(source, extend(link_name)) |
| 91 | 91 |
| 92 | 92 |
| 93 | |
| 94 | |
| 95 ## shutil | 93 ## shutil |
| 96 | 94 |
| 97 | 95 |
| 98 def copy2(src, dst): | 96 def copy2(src, dst): |
| 99 return shutil.copy2(extend(src), extend(dst)) | 97 return shutil.copy2(extend(src), extend(dst)) |
| 100 | 98 |
| 101 | 99 |
| 102 def rmtree(path, *args, **kwargs): | 100 def rmtree(path, *args, **kwargs): |
| 103 return shutil.rmtree(extend(path), *args, **kwargs) | 101 return shutil.rmtree(extend(path), *args, **kwargs) |
| 104 | 102 |
| 105 | 103 |
| 104 copyfileobj = shutil.copyfileobj |
| 105 |
| 106 |
| 106 ## The rest | 107 ## The rest |
| 107 | 108 |
| 108 | 109 |
| 109 def _get_lambda(func): | 110 def _get_lambda(func): |
| 110 return lambda path, *args, **kwargs: func(extend(path), *args, **kwargs) | 111 return lambda path, *args, **kwargs: func(extend(path), *args, **kwargs) |
| 111 | 112 |
| 112 | 113 |
| 113 def _is_path_fn(func): | 114 def _is_path_fn(func): |
| 114 return (inspect.getargspec(func)[0] or [None]) == 'path' | 115 return (inspect.getargspec(func)[0] or [None]) == 'path' |
| 115 | 116 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 127 for _fn in _os_fns: | 128 for _fn in _os_fns: |
| 128 if hasattr(os, _fn): | 129 if hasattr(os, _fn): |
| 129 sys.modules[__name__].__dict__.setdefault( | 130 sys.modules[__name__].__dict__.setdefault( |
| 130 _fn, _get_lambda(getattr(os, _fn))) | 131 _fn, _get_lambda(getattr(os, _fn))) |
| 131 | 132 |
| 132 | 133 |
| 133 for _fn in _os_path_fns: | 134 for _fn in _os_path_fns: |
| 134 if hasattr(os.path, _fn): | 135 if hasattr(os.path, _fn): |
| 135 sys.modules[__name__].__dict__.setdefault( | 136 sys.modules[__name__].__dict__.setdefault( |
| 136 _fn, _get_lambda(getattr(os.path, _fn))) | 137 _fn, _get_lambda(getattr(os.path, _fn))) |
| OLD | NEW |