summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/__init__.py
diff options
context:
space:
mode:
authorLeonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>2017-08-21 17:39:47 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-08-23 08:47:02 +0100
commite798b4e9808c9297ee7de01ebb381ca649777501 (patch)
tree7aaf44fa30627005c51ad1803d989cbf5d26934b /scripts/lib/devtool/__init__.py
parentee21e81cffa8b7bd976777a46ae51cb87599fed6 (diff)
downloadpoky-e798b4e9808c9297ee7de01ebb381ca649777501.tar.gz
devtool: import: new plugin to import the devtool workspace
Takes a tar archive created by 'devtool export' and imports (untars) it into the workspace. Currently the whole tar archive is imported, there is no way to limit what is imported. https://bugzilla.yoctoproject.org/show_bug.cgi?id=10510 [YOCTO #10510] (From OE-Core rev: 2de8ba89ef10fefcc97246dfeb4b8d1e48ee8232) Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/devtool/__init__.py')
-rw-r--r--scripts/lib/devtool/__init__.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py
index b231e46b16..14170cb69e 100644
--- a/scripts/lib/devtool/__init__.py
+++ b/scripts/lib/devtool/__init__.py
@@ -261,3 +261,39 @@ def get_bbclassextend_targets(recipefile, pn):
261 targets.append('%s-%s' % (pn, variant)) 261 targets.append('%s-%s' % (pn, variant))
262 return targets 262 return targets
263 263
264def replace_from_file(path, old, new):
265 """Replace strings on a file"""
266
267 def read_file(path):
268 data = None
269 with open(path) as f:
270 data = f.read()
271 return data
272
273 def write_file(path, data):
274 if data is None:
275 return
276 wdata = data.rstrip() + "\n"
277 with open(path, "w") as f:
278 f.write(wdata)
279
280 # In case old is None, return immediately
281 if old is None:
282 return
283 try:
284 rdata = read_file(path)
285 except IOError as e:
286 # if file does not exit, just quit, otherwise raise an exception
287 if e.errno == errno.ENOENT:
288 return
289 else:
290 raise
291
292 old_contents = rdata.splitlines()
293 new_contents = []
294 for old_content in old_contents:
295 try:
296 new_contents.append(old_content.replace(old, new))
297 except ValueError:
298 pass
299 write_file(path, "\n".join(new_contents))