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

All Samples(14)  |  Call(9)  |  Derive(0)  |  Import(5)
Atomically write a string <contents> into a file <file> with mode
<mode>.  If <binary>, binary mode will be used.

If the file exists, it will be replaced.

If two processes attempt to writeFile the same file at once,
the one finishing last wins.

If fsync is true, we call fsync on the file before closing it.

        def writeFile(fn, contents, mode=0600, binary=0, fsync=0):
    """Atomically write a string  into a file  with mode
       .  If , binary mode will be used.

       If the file exists, it will be replaced.

       If two processes attempt to writeFile the same file at once,
       the one finishing last wins.

       If fsync is true, we call fsync on the file before closing it.
       """
    tmpname = fn+".tmp"
    f, tmpname = openUnique(tmpname, ['w','wb'][binary], mode)
    try:
        try:
            f.write(contents)
            if fsync:
                os.fsync(f.fileno())
        finally:
            f.close()
    except:
        if os.path.exists(tmpname): os.unlink(tmpname)
        raise

    replaceFile(tmpname, fn)
        


src/m/i/mixminion-HEAD/lib/mixminion/server/ServerKeys.py   mixminion(Download)
from mixminion.ServerInfo import ServerInfo, PACKET_KEY_BYTES, MMTP_KEY_BYTES,\
     signServerInfo
from mixminion.Common import AtomicFile, LOG, MixError, MixFatalError, \
     ceilDiv, createPrivateDir, checkPrivateFile, englishSequence, \
     formatBase64, formatDate, formatTime, previousMidnight, readFile, \
        self.pingerSeed = r = mixminion.Crypto.trng(mixminion.Crypto.DIGEST_LEN)
        createPrivateDir(self.keyDir)
        writeFile(fn, r, 0600)
        return r
 
 
        if statusFile:
            writeFile(statusFile,
                    "".join(["%s\n"%k.getDescriptorFileName() for k in keys]),
                    0644)
    def markAsPublished(self):
        """Mark this keyset as published."""
        contents = "%s\n"%formatTime(time.time(),1)
        writeFile(self.publishedFile, contents, mode=0600)
        self.published = 1
 
    # Write the desciptor
    writeFile(serverKeys.getDescriptorFileName(), info, mode=0644)
 
    # This is for debugging: we try to parse and validate the descriptor

src/m/i/mixminion-HEAD/lib/mixminion/server/ServerMain.py   mixminion(Download)
 
from bisect import insort
from mixminion.Common import LOG, LogStream, MixError, MixFatalError,\
     UIError, ceilDiv, createPrivateDir, disp64, formatTime, \
     installSIGCHLDHandler, Lockfile, LockfileLocked, readFile, secureDelete, \
        if exists != SERVER_HOMEDIR_VERSION:
            # If we reach this point, the homedir is uninitialized.
            writeFile(os.path.join(homeDir, "version"),
                      SERVER_HOMEDIR_VERSION, 0644)
 
    print "Homedir is upgraded"
 
    writeFile(os.path.join(homeDir, 'version'),
              SERVER_HOMEDIR_VERSION, 0644)
 

src/m/i/mixminion-HEAD/lib/mixminion/ClientUtils.py   mixminion(Download)
import mixminion.Packet
 
from mixminion.Common import LOG, MixError, UIError, ceilDiv, \
     createPrivateDir, floorDiv, previousMidnight, readFile, \
     succeedingMidnight, writeFile, armorText, unarmorText, MixFatalError
    encrypted = ctr_crypt(data+digest, key)
    contents = "".join([magic,"\x00",salt,encrypted])
    writeFile(fname, armorText(contents,
                               "TYPE III KEYRING", [("Version","0.1")]))
 

src/m/i/mixminion-HEAD/lib/mixminion/ClientMain.py   mixminion(Download)
import mixminion.MMTPClient
 
from mixminion.Common import LOG, Lockfile, LockfileLocked, MixError, \
     MixFatalError, MixProtocolBadAuth, MixProtocolError, STATUS, UIError, \
     UsageError, createPrivateDir, englishSequence, floorDiv, formatTime, \
    fields = { 'ud_default' : mixminion.Config.DEFAULT_USER_DIR }
 
    writeFile(os.path.expanduser(fname),
              """\
# This file contains your options for the mixminion client.

src/m/i/mixminion-HEAD/lib/mixminion/directory/ServerList.py   mixminion(Download)
from mixminion.Crypto import pk_decode_public_key, pk_encode_public_key, \
     pk_same_public_key
from mixminion.Common import IntervalSet, LOG, MixError, MixFatalError, \
     UIError, createPrivateDir, formatBase64, formatDate, formatFnameTime, \
     formatTime, iterFileLines, Lockfile, openUnique, previousMidnight, readFile,\