summaryrefslogtreecommitdiffstats
path: root/yocto-poky/meta/lib/oeqa/utils/ftools.py
blob: 64ebe3d217352ff139cc5fd5403b05c10b14c240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import re

def write_file(path, data):
    wdata = data.rstrip() + "\n"
    with open(path, "w") as f:
        f.write(wdata)

def append_file(path, data):
    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):
    lines = read_file(path).splitlines()
    rmdata = data.strip().splitlines()
    for l in rmdata:
        for c in range(0, lines.count(l)):
            i = lines.index(l)
            del(lines[i])
    write_file(path, "\n".join(lines))
OpenPOWER on IntegriCloud