예제 #1
0
def replaceStr(full_path, source_str, target_str):
    os.chmod(full_path, stat.S_IREAD|stat.S_IWRITE)
    file = None
    try:
        file = io.open(full_path, 'r+')
        content = file.read()
        content = str(content).replace(source_str, target_str)

        io_util.repcontent(file, content)
    finally:
        if not file == None:
            file.close()
예제 #2
0
def fixcontent(filepath, replace_items):
    os.chmod(filepath, stat.S_IREAD|stat.S_IWRITE)
    file = None
    try:
        file = io.open(filepath, 'r+')
        content = file.read()
        for item in replace_items:
            content = str(content).replace(item, replace_items[item])

        io_util.repcontent(file, content)

    finally:
        if not file == None:
            file.close()