summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Remmet <j.remmet@phytec.de>2017-12-15 11:45:02 +0100
committerStefan Müller-Klieser <s.mueller-klieser@phytec.de>2017-12-15 16:36:37 +0100
commit161a2c74a7641b4b9612cfd88eb903a49523db22 (patch)
tree606f0f66dc483aa4a3d772d96e40d697f69e5f90
parentd34309ebaee98c05b016968d5e9e7cc27dc44318 (diff)
downloadmeta-phytec-161a2c74a7641b4b9612cfd88eb903a49523db22.tar.bz2
meta-phytec-161a2c74a7641b4b9612cfd88eb903a49523db22.zip
phylib: copy_file_by_priority: add script
Find file in project layer. Copy file from layer with highest layer priority. Ignore poky and meta-openembedded, because nested layers are not supported. Use copy_file_by_priority to deploy TEMPLATECONF. This allows to overwrite conf files from higher priority layers. Signed-off-by: Jan Remmet <j.remmet@phytec.de> Signed-off-by: Stefan Müller-Klieser <s.mueller-klieser@phytec.de>
-rwxr-xr-xscripts/copy_file_by_priority.py75
-rwxr-xr-xscripts/init7
2 files changed, 79 insertions, 3 deletions
diff --git a/scripts/copy_file_by_priority.py b/scripts/copy_file_by_priority.py
new file mode 100755
index 0000000..f3d64c6
--- /dev/null
+++ b/scripts/copy_file_by_priority.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright 2017, PHYTEC Messtechnik GmbH
+# Author: Jan Remmet <j.remmet@phytec.de>
+
+import sys
+import argparse
+import shutil
+from phylib import *
+
+
+class BSP_BBLayerFile(BoardSupportPackage):
+
+ """
+ Setup project priority list
+ """
+
+ def __init__(self):
+ super(BSP_BBLayerFile, self).__init__()
+ project_priority = []
+ # ignore repos with layer.conf in unusual places
+ project_filter = ["poky", "meta-openembedded"]
+ for p in set(self.project_paths).difference(project_filter):
+ abs_project_path = os.path.join(self.src.bsp_dir, 'sources', p)
+ layer_conf = os.path.join(abs_project_path, 'conf/layer.conf')
+ priority = self.__get_priority(layer_conf)
+ if priority:
+ project_priority.append((priority, abs_project_path))
+ self.project_paths_priority = sorted(project_priority, reverse=True)
+
+ def __get_priority(self, layer_conf):
+ with open(layer_conf) as lcfile:
+ for line in lcfile:
+ name, val = line.partition("=")[::2]
+ if 'BBFILE_PRIORITY_' in name:
+ priority = int(val.strip('" \n'))
+ lcfile.close
+ return priority
+
+ def copy_file(self, search_file, destination):
+ for _, ppath in self.project_paths_priority:
+ found = os.path.join(ppath, search_file)
+ try:
+ shutil.copy2(found, destination)
+ print("copy {} to {}".format(found, destination))
+ return
+ except IOError:
+ pass
+ raise IOError("file {} not found in any layer".format(search_file))
+
+ def print_all_files(self, search_file):
+ for prio, ppath in self.project_paths_priority:
+ dest_file = os.path.join(ppath, search_file)
+ if os.path.isfile(dest_file):
+ print("{} priority:{}".format(dest_file, prio))
+
+
+# Executable
+def main():
+ parser = argparse.ArgumentParser(
+ description='Find file in all included layers. Copy it from the layer with highest BBFILE_PRIORITY to the destination')
+
+ parser.add_argument('file', help="filename with relative path")
+ parser.add_argument('dest', nargs='?', help="copy to destination")
+
+ args = parser.parse_args()
+
+ bsp = BSP_BBLayerFile()
+ if args.dest:
+ bsp.copy_file(args.file, args.dest)
+ else:
+ bsp.print_all_files(args.file)
+
+if __name__ == "__main__":
+ main()
diff --git a/scripts/init b/scripts/init
index 68bf7e6..75ee050 100755
--- a/scripts/init
+++ b/scripts/init
@@ -39,10 +39,11 @@ install -m 0644 ${PHYTEC_DIR}/conf/doc/HOWTO ${ROOTDIR}
# Setup template directory. Allow caller to overwrite default TEMPLATECONF.
if [ -z "${TEMPLATECONF}" ]; then
export TEMPLATECONF="${ROOTDIR}/tools/templateconf"
+ copy_file_by_priority=${PHYTEC_DIR}/scripts/copy_file_by_priority.py
install -d ${TEMPLATECONF}
- install -m 0644 ${PHYTEC_DIR}/conf/bblayers.conf.sample ${TEMPLATECONF}
- install -m 0644 ${PHYTEC_DIR}/conf/local.conf.sample ${TEMPLATECONF}
- install -m 0644 ${PHYTEC_DIR}/conf/conf-notes.txt ${TEMPLATECONF}
+ $copy_file_by_priority conf/bblayers.conf.sample ${TEMPLATECONF}
+ $copy_file_by_priority conf/local.conf.sample ${TEMPLATECONF}
+ $copy_file_by_priority conf/conf-notes.txt ${TEMPLATECONF}
fi
# Init a build directory if we dont have one.