diff options
Diffstat (limited to 'import-layers/yocto-poky/meta/lib/oeqa/utils/ftools.py')
-rw-r--r-- | import-layers/yocto-poky/meta/lib/oeqa/utils/ftools.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/import-layers/yocto-poky/meta/lib/oeqa/utils/ftools.py b/import-layers/yocto-poky/meta/lib/oeqa/utils/ftools.py new file mode 100644 index 000000000..a7233d4ca --- /dev/null +++ b/import-layers/yocto-poky/meta/lib/oeqa/utils/ftools.py @@ -0,0 +1,46 @@ +import os +import re +import errno + +def write_file(path, data): + # In case data is None, return immediately + if data is None: + return + wdata = data.rstrip() + "\n" + with open(path, "w") as f: + f.write(wdata) + +def append_file(path, data): + # In case data is None, return immediately + if data is None: + return + wdata = data.rstrip() + "\n" + with open(path, "a") as f: + f.write(wdata) + +def read_file(path): + data = None + with open(path) as f: + data = f.read() + return data + +def remove_from_file(path, data): + # In case data is None, return immediately + if data is None: + return + 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 + + contents = rdata.strip().splitlines() + for r in data.strip().splitlines(): + try: + contents.remove(r) + except ValueError: + pass + write_file(path, "\n".join(contents)) |