def _save(self, now=None): """Implements 'save' method. For internal use. Must hold self._lock to invoke.""" log.debug("Syncing statistics to disk") if not now: now = time() tmpfile = self.filename + "_tmp" tryUnlink(tmpfile) self.accumulatedTime += int(now-self.lastSave) self.lastSave = now writePickled(self.filename, { 'count' : self.count, 'lastRotation' : self.lastRotation, 'accumulatedTime' : self.accumulatedTime, })
def _save(self, now=None): """Implements 'save' method. For internal use. Must hold self._lock to invoke.""" LOG.debug("Syncing statistics to disk") if not now: now = time() tmpfile = self.filename + "_tmp" tryUnlink(tmpfile) self.accumulatedTime += int(now - self.lastSave) self.lastSave = now writePickled( self.filename, { 'count': self.count, 'lastRotation': self.lastRotation, 'accumulatedTime': self.accumulatedTime, })
that flushes the database's contents to disk. """ parent = os.path.split(filename)[0] createPrivateDir(parent) # If the file exists, but can't be read, bail. try: st = os.stat(filename) except OSError, e: if e.errno != errno.ENOENT: raise st = None # If the file is empty, delete it and start over. if st and st[stat.ST_SIZE] == 0: LOG.warn("Half-created database %s found; cleaning up.", filename) tryUnlink(filename) dbtype = whichdb.whichdb(filename) LOG.debug("Opening %s database at %s", purpose, filename) try: if dbtype != 'dbhash': db = _openDBHash(filename, 'c', 0600) else: db = anydbm.open(filename, 'c', 0600) except anydbm.error, e: raise MixFatalError("Can't open %s database: %s"%(purpose,e)) except ImportError: raise MixFatalError("Unsupported type for %s database: %s" %(purpose, dbtype)) if hasattr(db, 'sync'):
def delPendingServers(self, fnames): """Remove a list of pending servers with filename 'filename' from the incoming directory.""" for fname in fnames: if not tryUnlink(os.path.join(self.incomingDir, fname)): LOG.warn("delPendingServers: no such server %s"%fname)
that flushes the database's contents to disk. """ parent = os.path.split(filename)[0] createPrivateDir(parent) # If the file exists, but can't be read, bail. try: st = os.stat(filename) except OSError, e: if e.errno != errno.ENOENT: raise st = None # If the file is empty, delete it and start over. if st and st[stat.ST_SIZE] == 0: LOG.warn("Half-created database %s found; cleaning up.", filename) tryUnlink(filename) dbtype = whichdb.whichdb(filename) LOG.debug("Opening %s database at %s", purpose, filename) try: if dbtype != 'dbhash': db = _openDBHash(filename, 'c', 0600) else: db = anydbm.open(filename, 'c', 0600) except anydbm.error, e: raise MixFatalError("Can't open %s database: %s" % (purpose, e)) except ImportError: raise MixFatalError("Unsupported type for %s database: %s" % (purpose, dbtype)) if hasattr(db, 'sync'):
def markAsUnpublished(self): """Mark this keyset as unpublished.""" tryUnlink(self.publishedFile) self.published = 0