diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2010-08-06 10:57:32 +0100 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-08-12 14:41:31 +0100 |
commit | 19be6b407c6595f1d975d249bee3bf4271f0946f (patch) | |
tree | 6984ba9b9d64ad684409d972abc274031ee9b232 | |
parent | a5884df90d628b2dc13ac83c9d8045afa6b2a120 (diff) | |
download | poky-19be6b407c6595f1d975d249bee3bf4271f0946f.tar.gz |
lib/oe/path.py: Add copytree function that works
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
-rw-r--r-- | meta/lib/oe/path.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py index 183f205757..d671ce9216 100644 --- a/meta/lib/oe/path.py +++ b/meta/lib/oe/path.py | |||
@@ -1,3 +1,5 @@ | |||
1 | import shutil | ||
2 | |||
1 | def join(*paths): | 3 | def join(*paths): |
2 | """Like os.path.join but doesn't treat absolute RHS specially""" | 4 | """Like os.path.join but doesn't treat absolute RHS specially""" |
3 | import os.path | 5 | import os.path |
@@ -43,6 +45,45 @@ def format_display(path, metadata): | |||
43 | else: | 45 | else: |
44 | return rel | 46 | return rel |
45 | 47 | ||
48 | |||
49 | class Error(EnvironmentError): | ||
50 | pass | ||
51 | |||
52 | # Based on shutil.copytree but with features removed and | ||
53 | # No fatal error is dst already exists | ||
54 | # Handle symlinks that already exist | ||
55 | def copytree(src, dst): | ||
56 | names = os.listdir(src) | ||
57 | |||
58 | bb.mkdirhier(dst) | ||
59 | |||
60 | errors = [] | ||
61 | for name in names: | ||
62 | srcname = os.path.join(src, name) | ||
63 | dstname = os.path.join(dst, name) | ||
64 | try: | ||
65 | if os.path.islink(srcname): | ||
66 | linkto = os.readlink(srcname) | ||
67 | if os.path.lexists(dstname): | ||
68 | os.unlink(dstname) | ||
69 | os.symlink(linkto, dstname) | ||
70 | elif os.path.isdir(srcname): | ||
71 | copytree(srcname, dstname) | ||
72 | else: | ||
73 | shutil.copy2(srcname, dstname) | ||
74 | except (IOError, os.error), why: | ||
75 | errors.append((srcname, dstname, str(why))) | ||
76 | # catch the Error from the recursive copytree so that we can | ||
77 | # continue with other files | ||
78 | except Error, err: | ||
79 | errors.extend(err.args[0]) | ||
80 | try: | ||
81 | shutil.copystat(src, dst) | ||
82 | except OSError, why: | ||
83 | errors.extend((src, dst, str(why))) | ||
84 | if errors: | ||
85 | raise Error, errors | ||
86 | |||
46 | def remove(path): | 87 | def remove(path): |
47 | """Equivalent to rm -f or rm -rf""" | 88 | """Equivalent to rm -f or rm -rf""" |
48 | import os, errno, shutil, glob | 89 | import os, errno, shutil, glob |