summaryrefslogtreecommitdiffstats
path: root/scripts/lib/bsp/engine.py
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@intel.com>2012-12-12 22:56:35 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-12-13 16:54:33 +0000
commit125eb6f390b4882778f1a5179dca5f78675e19e5 (patch)
treec54bc65ece16bf5f3eb51237463034b3e7ed9ca0 /scripts/lib/bsp/engine.py
parent205872b7b88f64dcb5a725e53811aedacac21da1 (diff)
downloadast2050-yocto-poky-125eb6f390b4882778f1a5179dca5f78675e19e5.zip
ast2050-yocto-poky-125eb6f390b4882778f1a5179dca5f78675e19e5.tar.gz
yocto-bsp: add replace_file()
Add a function that can be used to replace a template file by a user-specified file. The initial use of this capability is to allow users-specified defconfigs. (From meta-yocto rev: b52a22d40d4701a9515490bdd31c8d0341fb12bc) Signed-off-by: Tom Zanussi <tom.zanussi@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/bsp/engine.py')
-rw-r--r--scripts/lib/bsp/engine.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/scripts/lib/bsp/engine.py b/scripts/lib/bsp/engine.py
index 6309e29..8985544 100644
--- a/scripts/lib/bsp/engine.py
+++ b/scripts/lib/bsp/engine.py
@@ -38,6 +38,7 @@ from tags import *
import shlex
import json
import subprocess
+import shutil
class Line():
"""
@@ -83,7 +84,7 @@ class NormalLine(Line):
def gen(self, context = None):
if self.is_filename:
- line = "of = open(\"" + os.path.join(self.out_filebase, self.escape(self.line)) + "\", \"w\")"
+ line = "current_file = \"" + os.path.join(self.out_filebase, self.escape(self.line)) + "\"; of = open(current_file, \"w\")"
elif self.is_dirname:
dirname = os.path.join(self.out_filebase, self.escape(self.line))
line = "if not os.path.exists(\"" + dirname + "\"): os.mkdir(\"" + dirname + "\")"
@@ -134,7 +135,7 @@ class AssignmentLine(NormalLine):
idx = line.find(ASSIGN_TAG)
line = line[:idx] + replacement + line[idx + assignment.end - assignment.start:]
if self.is_filename:
- return "of = open(\"" + os.path.join(self.out_filebase, line) + "\", \"w\")"
+ return "current_file = \"" + os.path.join(self.out_filebase, line) + "\"; of = open(current_file, \"w\")"
elif self.is_dirname:
dirname = os.path.join(self.out_filebase, line)
return "if not os.path.exists(\"" + dirname + "\"): os.mkdir(\"" + dirname + "\")"
@@ -564,6 +565,17 @@ def get_verified_file(input_str, name, filename_can_be_null):
filename = default(raw_input(msg), name)
+def replace_file(replace_this, with_this):
+ """
+ Replace the given file with the contents of filename, retaining
+ the original filename.
+ """
+ try:
+ shutil.copy(with_this, replace_this)
+ except IOError:
+ pass
+
+
def boolean(input_str, name):
"""
Return lowercase version of first char in string, or value in name.
@@ -1197,7 +1209,7 @@ def gen_program_header_lines(program_lines):
"""
Generate any imports we need.
"""
- pass
+ program_lines.append("current_file = \"\"")
def gen_supplied_property_vals(properties, program_lines):
OpenPOWER on IntegriCloud