]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa/utils/ftools: Ignore the exception if file does not exist
authorLeonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Mon, 19 Oct 2015 21:38:42 +0000 (21:38 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 21 Oct 2015 21:52:40 +0000 (22:52 +0100)
There may be cases where the configuration file (path) does not exist,
thus the remove_from_file should catch this exception. In case the exception
is not the latter (errno.ENOENT), then re-raise it.

[YOCTO #8540]

Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/lib/oeqa/utils/ftools.py

index 64ebe3d217352ff139cc5fd5403b05c10b14c240..1ec8a0948f0d71da816b55c6d2f4e37c4480e8cd 100644 (file)
@@ -1,5 +1,6 @@
 import os
 import re
+import errno
 
 def write_file(path, data):
     wdata = data.rstrip() + "\n"
@@ -18,7 +19,15 @@ def read_file(path):
     return data
 
 def remove_from_file(path, data):
-    lines = read_file(path).splitlines()
+    try:
+        rdata = read_file(path)
+    except IOError as e:
+        # if file does not exit, just quit, otherwise raise an exception
+        if e.errno == errno.ENOENT:
+            return
+        else:
+            raise
+    lines = rdata.splitlines()
     rmdata = data.strip().splitlines()
     for l in rmdata:
         for c in range(0, lines.count(l)):