import os, errno, time, socket

HOSTNAME = socket.gethostname().replace('/', r'\057').replace(':', r'\072')
PID = os.getpid()

def getTime(path):
    try:
        f=open(path)
    except IOError, e:
        if e.errno == errno.ENOENT:
            return -1
        else:
            raise

    l=f.readline()
    return float(l)

def writeFile(path, content, temp=None):
    if temp is None:
        temp = '%s.%d.%s.%d.tmp' % (
            path,
            int((time.time())*10e6),
            HOSTNAME,
            PID,
            )
    f = file(temp, 'w')
    f.write(content)
    f.close()
    os.rename(temp, path)
