from editor import FileEditor

# filename to test with
fn = "test.conf"

f = FileEditor(fn)

# turn off REs for hunter ('$' is a special RE char)
f.flags(regexs=False)
f.replace("root:$1$balhkk;kjjhhgdhdj", "root:$1$newblablablahhjjj")
f.flags(regexs=True)

# Test simple RE replace
# use python's raw string feature
f.replace(r"^jack=([0-9]+)", r"bob=\1")

# Test insert after blob
f.insert(r"(^\w+=(\w+)\n)+", r"Jack \2 was here\n")

# insert text before blob
f.insertBefore("^root:", "No root for you\n")

# append if unique
f.appendUnique("jjneely\n")
f.appendUnique("aekirby\n")
f.appendUnique("sue=1\n")
print f