Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(3)  |  Derive(0)  |  Import(1)

        def file_contents_replace(filename, new_filename, pattern=None, replace=None, mode="og"):

    lines = []
    try:
        fp = open(filename,"r")
        fcntl.lockf(fp.fileno(), fcntl.LOCK_SH)
        for line in fp.readlines():
            lines.append(line)
        fcntl.lockf(fp.fileno(), fcntl.LOCK_UN)
        fp.close()
    except:
        return False

    if len(lines) > 0:
        lines = array_replace(lines,pattern,replace,mode)
        try:
            fp = open(new_filename,"w")
            fcntl.lockf(fp.fileno(), fcntl.LOCK_EX)
            for line in lines:
                fp.write(line)
            fcntl.lockf(fp.fileno(), fcntl.LOCK_UN)
            fp.close()
        except:
            return False

    return True
        


src/k/a/karesansui-HEAD/karesansui/lib/virt/virt.py   karesansui(Download)
from karesansui.lib.utils import copy_file            as CopyFile
from karesansui.lib.net.http import wget              as DownloadFile
from karesansui.lib.utils import is_uuid, get_ifconfig_info, r_chgrp, r_chmod, \
  getfilesize_str, get_filesize_MB, get_disk_img_info, available_virt_uris, \
  is_iso9660_filesystem_format, is_windows_bootable_iso, is_darwin_bootable_iso, \
                old_pattern = "<uuid>.{36}</uuid>"
                new_string  = "<uuid>%s</uuid>" % uuid
                file_contents_replace(snapshot_xml,new_snapshot_xml,old_pattern,new_string)
            if os.getuid() == 0:
                if os.path.exists(domain_snapshot_dir):
                old_pattern = "<uuid>.{36}</uuid>"
                new_string  = "<uuid>%s</uuid>" % uuid
                file_contents_replace(export_xml_file,xml_file,old_pattern,new_string)
                old_pattern = "^uuid = .*"
                new_string  = "uuid = '%s'" % str(uuid)
                file_contents_replace(export_config_file ,config_file,old_pattern,new_string)