diff options
| -rw-r--r-- | meta/lib/oe/path.py | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py index da7811fac4..74674bfee8 100644 --- a/meta/lib/oe/path.py +++ b/meta/lib/oe/path.py | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | import shutil | 1 | import shutil |
| 2 | import subprocess | ||
| 2 | 3 | ||
| 3 | def join(*paths): | 4 | def join(*paths): |
| 4 | """Like os.path.join but doesn't treat absolute RHS specially""" | 5 | """Like os.path.join but doesn't treat absolute RHS specially""" |
| @@ -45,24 +46,16 @@ def format_display(path, metadata): | |||
| 45 | else: | 46 | else: |
| 46 | return rel | 47 | return rel |
| 47 | 48 | ||
| 48 | |||
| 49 | class CopyFailed(Exception): | ||
| 50 | pass | ||
| 51 | |||
| 52 | def copytree(src, dst): | 49 | def copytree(src, dst): |
| 53 | # We could use something like shutil.copytree here but it turns out to | 50 | # We could use something like shutil.copytree here but it turns out to |
| 54 | # to be slow. It takes twice as long copying to an empty directory. | 51 | # to be slow. It takes twice as long copying to an empty directory. |
| 55 | # If dst already has contents performance can be 15 time slower | 52 | # If dst already has contents performance can be 15 time slower |
| 56 | # This way we also preserve hardlinks between files in the tree. | 53 | # This way we also preserve hardlinks between files in the tree. |
| 57 | 54 | ||
| 58 | import subprocess | ||
| 59 | |||
| 60 | bb.mkdirhier(dst) | 55 | bb.mkdirhier(dst) |
| 61 | cmd = 'tar -cf - -C %s -ps . | tar -xf - -C %s' % (src, dst) | 56 | cmd = 'tar -cf - -C %s -ps . | tar -xf - -C %s' % (src, dst) |
| 62 | ret = subprocess.call(cmd, shell=True) | 57 | check_output(cmd, shell=True, stderr=subprocess.STDOUT) |
| 63 | if ret != 0: | 58 | |
| 64 | raise CopyFailed("Command %s failed with return value %s" % (cmd, ret)) | ||
| 65 | return | ||
| 66 | 59 | ||
| 67 | def remove(path): | 60 | def remove(path): |
| 68 | """Equivalent to rm -f or rm -rf""" | 61 | """Equivalent to rm -f or rm -rf""" |
| @@ -86,3 +79,38 @@ def symlink(source, destination, force=False): | |||
| 86 | except OSError, e: | 79 | except OSError, e: |
| 87 | if e.errno != errno.EEXIST or os.readlink(destination) != source: | 80 | if e.errno != errno.EEXIST or os.readlink(destination) != source: |
| 88 | raise | 81 | raise |
| 82 | |||
| 83 | |||
| 84 | # Not needed when we move to python 2.7 | ||
| 85 | def check_output(*popenargs, **kwargs): | ||
| 86 | r"""Run command with arguments and return its output as a byte string. | ||
| 87 | |||
| 88 | If the exit code was non-zero it raises a CalledProcessError. The | ||
| 89 | CalledProcessError object will have the return code in the returncode | ||
| 90 | attribute and output in the output attribute. | ||
| 91 | |||
| 92 | The arguments are the same as for the Popen constructor. Example: | ||
| 93 | |||
| 94 | >>> check_output(["ls", "-l", "/dev/null"]) | ||
| 95 | 'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' | ||
| 96 | |||
| 97 | The stdout argument is not allowed as it is used internally. | ||
| 98 | To capture standard error in the result, use stderr=STDOUT. | ||
| 99 | |||
| 100 | >>> check_output(["/bin/sh", "-c", | ||
| 101 | ... "ls -l non_existent_file ; exit 0"], | ||
| 102 | ... stderr=STDOUT) | ||
| 103 | 'ls: non_existent_file: No such file or directory\n' | ||
| 104 | """ | ||
| 105 | if 'stdout' in kwargs: | ||
| 106 | raise ValueError('stdout argument not allowed, it will be overridden.') | ||
| 107 | process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs) | ||
| 108 | output, unused_err = process.communicate() | ||
| 109 | retcode = process.poll() | ||
| 110 | if retcode: | ||
| 111 | cmd = kwargs.get("args") | ||
| 112 | if cmd is None: | ||
| 113 | cmd = popenargs[0] | ||
| 114 | raise subprocess.CalledProcessError(retcode, cmd, output=output) | ||
| 115 | return output | ||
| 116 | |||
