diff options
| -rw-r--r-- | meta/lib/oe/path.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py index 08ddbf22aa..8eaa3c5da4 100644 --- a/meta/lib/oe/path.py +++ b/meta/lib/oe/path.py | |||
| @@ -1,9 +1,12 @@ | |||
| 1 | import bb | ||
| 2 | import errno | ||
| 3 | import glob | ||
| 4 | import os | ||
| 1 | import shutil | 5 | import shutil |
| 2 | import subprocess | 6 | import subprocess |
| 3 | 7 | ||
| 4 | def join(*paths): | 8 | def join(*paths): |
| 5 | """Like os.path.join but doesn't treat absolute RHS specially""" | 9 | """Like os.path.join but doesn't treat absolute RHS specially""" |
| 6 | import os.path | ||
| 7 | return os.path.normpath("/".join(paths)) | 10 | return os.path.normpath("/".join(paths)) |
| 8 | 11 | ||
| 9 | def relative(src, dest): | 12 | def relative(src, dest): |
| @@ -18,7 +21,6 @@ def relative(src, dest): | |||
| 18 | >>> relative("/tmp", "/tmp/foo/bar") | 21 | >>> relative("/tmp", "/tmp/foo/bar") |
| 19 | foo/bar | 22 | foo/bar |
| 20 | """ | 23 | """ |
| 21 | import os.path | ||
| 22 | 24 | ||
| 23 | if hasattr(os.path, "relpath"): | 25 | if hasattr(os.path, "relpath"): |
| 24 | return os.path.relpath(dest, src) | 26 | return os.path.relpath(dest, src) |
| @@ -57,21 +59,19 @@ def copytree(src, dst): | |||
| 57 | check_output(cmd, shell=True, stderr=subprocess.STDOUT) | 59 | check_output(cmd, shell=True, stderr=subprocess.STDOUT) |
| 58 | 60 | ||
| 59 | 61 | ||
| 60 | def remove(path): | 62 | def remove(path, recurse=True): |
| 61 | """Equivalent to rm -f or rm -rf""" | 63 | """Equivalent to rm -f or rm -rf""" |
| 62 | import os, errno, shutil, glob | ||
| 63 | for name in glob.glob(path): | 64 | for name in glob.glob(path): |
| 64 | try: | 65 | try: |
| 65 | os.unlink(name) | 66 | os.unlink(name) |
| 66 | except OSError, exc: | 67 | except OSError, exc: |
| 67 | if exc.errno == errno.EISDIR: | 68 | if recurse and exc.errno == errno.EISDIR: |
| 68 | shutil.rmtree(path) | 69 | shutil.rmtree(name) |
| 69 | elif exc.errno != errno.ENOENT: | 70 | elif exc.errno != errno.ENOENT: |
| 70 | raise | 71 | raise |
| 71 | 72 | ||
| 72 | def symlink(source, destination, force=False): | 73 | def symlink(source, destination, force=False): |
| 73 | """Create a symbolic link""" | 74 | """Create a symbolic link""" |
| 74 | import os, errno | ||
| 75 | try: | 75 | try: |
| 76 | if force: | 76 | if force: |
| 77 | remove(destination) | 77 | remove(destination) |
| @@ -121,3 +121,10 @@ def check_output(*popenargs, **kwargs): | |||
| 121 | raise CalledProcessError(retcode, cmd, output=output) | 121 | raise CalledProcessError(retcode, cmd, output=output) |
| 122 | return output | 122 | return output |
| 123 | 123 | ||
| 124 | def find(dir, **walkoptions): | ||
| 125 | """ Given a directory, recurses into that directory, | ||
| 126 | returning all files as absolute paths. """ | ||
| 127 | |||
| 128 | for root, dirs, files in os.walk(dir, **walkoptions): | ||
| 129 | for file in files: | ||
| 130 | yield os.path.join(root, file) | ||
