From: Johannes Berg Date: Sun, 31 Mar 2013 22:32:52 +0000 (+0200) Subject: allow renaming while copying X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=94322db3f3144bfc743b2b8cae09514c60a682c5;p=openwrt%2Fstaging%2Fblogic.git allow renaming while copying This will be useful for the rfkill backport. Signed-off-by: Johannes Berg --- diff --git a/copy-list b/copy-list index cff6240f15d7..11f606782011 100644 --- a/copy-list +++ b/copy-list @@ -5,6 +5,10 @@ # Directories must end with a slash (e.g. "net/wireless/") and # are then copied with all their contents. # +# It is also possible to rename while copying, to do so list +# old name -> new name +# Note that in this case the spaces are needed: " -> " +# # wireless stack include/linux/ieee80211.h diff --git a/gentree.py b/gentree.py index 8a5acb4cc979..162a1f5294e2 100755 --- a/gentree.py +++ b/gentree.py @@ -22,15 +22,21 @@ def read_copy_list(kerneldir, copyfile): continue if item[0] == '/': raise Exception("Input path '%s' is absolute path, this isn't allowed" % (item, )) + if ' -> ' in item: + srcitem, dstitem = item.split(' -> ') + if (srcitem[-1] == '/') != (dstitem[-1] == '/'): + raise Exception("Cannot copy file/dir to dir/file") + else: + srcitem = dstitem = item # check for expected input - src = os.path.join(kerneldir, item) + src = os.path.join(kerneldir, srcitem) if item[-1] == '/': if not os.path.isdir(src): - raise Exception("Input path '%s' isn't a directory in '%s'" % (item, kerneldir)) + raise Exception("Input path '%s' isn't a directory in '%s'" % (srcitem, kerneldir)) else: if not os.path.isfile(src): - raise Exception("Input path '%s' isn't a file in '%s'" % (item, kerneldir)) - ret.append((kerneldir, item)) + raise Exception("Input path '%s' isn't a file in '%s'" % (srcitem, kerneldir)) + ret.append((kerneldir, srcitem, dstitem)) return ret def check_output_dir(d, clean): @@ -82,10 +88,10 @@ def copytree(src, dst, symlinks=False, ignore=None): raise shutil.Error(errors) def copy_files(copy_list, outdir): - for src, tgt in copy_list: - if tgt == '': - copytree(src, outdir, ignore=shutil.ignore_patterns('*~')) - elif tgt[-1] == '/': + for srcpath, srcitem, tgtitem in copy_list: + if tgtitem == '': + copytree(srcpath, outdir, ignore=shutil.ignore_patterns('*~')) + elif tgtitem[-1] == '/': def copy_ignore(dir, entries): r = [] for i in entries: @@ -95,18 +101,18 @@ def copy_files(copy_list, outdir): not os.path.isdir(os.path.join(dir, i))): r.append(i) return r - copytree(os.path.join(src, tgt), - os.path.join(outdir, tgt), + copytree(os.path.join(srcpath, srcitem), + os.path.join(outdir, tgtitem), ignore=copy_ignore) else: try: - os.makedirs(os.path.join(outdir, os.path.dirname(tgt))) + os.makedirs(os.path.join(outdir, os.path.dirname(tgtitem))) except OSError, e: # ignore dirs we might have created just now if e.errno != errno.EEXIST: raise - shutil.copy(os.path.join(src, tgt), - os.path.join(outdir, tgt)) + shutil.copy(os.path.join(srcpath, srcitem), + os.path.join(outdir, tgtitem)) def git_debug_init(args): if not args.gitdebug: @@ -141,12 +147,12 @@ def main(): args = parser.parse_args() # first thing to copy is our own plumbing -- we start from that - copy_list = [(os.path.join(source_dir, 'plumbing'), '')] + copy_list = [(os.path.join(source_dir, 'plumbing'), '', '')] # then add stuff from the copy list file copy_list.extend(read_copy_list(args.kerneldir, args.copy_list)) # add compat to the list - copy_list.append((os.path.join(source_dir, 'compat'), 'compat/')) - copy_list.append((os.path.join(source_dir, 'compat'), 'include/')) + copy_list.append((os.path.join(source_dir, 'compat'), 'compat/', 'compat/')) + copy_list.append((os.path.join(source_dir, 'compat'), 'include/', 'include/')) # validate output directory check_output_dir(args.outdir, args.clean)