def blankFile(self): """ `blankFile` simply blanks out the bfile loaded. """ l.l(l.PEDANTIC,"creating blank file: %s" % self.file) self.setContent("") self.write()
def blankFile(self): """ `blankFile` blanks a file. """ l.l(l.PEDANTIC,"creating blank file: %s" % self.file) self.setContent({}) self.write()
def blankFile(self): """ @see: bfile.bfile.blankFile """ l.l(l.PEDANTIC,"creating blank file: %s" % self.file) self.setContent({}) self.write()
def setContent(self, content): """ Set the internal cache. Might want to use this with the `getContent` method. @param content: the content to set the cache to. """ self.content = content l.l(l.PEDANTIC,"Setting internal cache: %s" % self.file)
def setContent(self, content): """ `setContent` sets the content of the cache, klobbering what was there before. @arg content: content to cache, and prepare for write. """ self.content = content l.l(l.PEDANTIC,"Setting internal cache: %s" % self.file)
def write(self): """ @see: bfile.bfile.write """ l.l(l.PEDANTIC,"Writing JSON file: %s" % self.file) f = gzip.open(self.file, 'wb') f.write(json.dumps(self.getContent())) f.close()
def update(self): """ @see: bfile.bfile.update """ l.l(l.PEDANTIC,"Updating JSON file: %s" % self.file) f = gzip.open(self.file, 'rb') self.setContent(json.loads(f.read())) f.close()
def update(self): """ Update re-reads the file from the filesystem and updates it's internal cache. """ l.l(l.PEDANTIC,"Updating JSON file: %s" % self.file) f = open(self.file, 'rb') self.setContent(json.loads(f.read())) f.close()
def write(self): """ `write` writes the cached file to the filesystem, overwriting whatever was on that file moments ago. """ l.l(l.PEDANTIC,"Writing file: %s" % self.file) f = gzip.open(self.file, 'wb') f.write(self.getContent()) f.close()
def write(self): """ Write writes out the cache to the filesystem, klobbering whatever's there without shame or second thought. """ l.l(l.PEDANTIC,"Writing JSON file: %s" % self.file) f = open(self.file, 'wb') f.write(json.dumps(self.getContent())) f.close()
def update(self): """ `update` syncs the file in the filesystem into this object, if the file has been written while the file has been cached in memory. """ l.l(l.PEDANTIC,"Updating file: %s" % self.file) f = gzip.open(self.file, 'rb') self.setContent(f.read()) f.close()
def __loaddb(self, path): """ Load a database into the cache. Called by the constructor. """ try: self.ff = flatfile.JsonBfile(path) except IOError as e: l.l(l.CRITICAL, "Database does not exist.") raise Syn.Exceptions.SynDirectoryFailure("%s does not exist." % path)
def __init__(self, fil): """ Basic run of the mill constructor @param fil: File to use """ self.file = fil l.l(l.PEDANTIC,"Using file: %s" % fil) try: self.update() l.l(l.PEDANTIC,"existing file loaded: %s" % fil) except IOError as e: # OK, we need to create it. self.blankFile()
def __init__(self, fil): """ Simple constructor. @arg fil: File to load, or create if it does not exist. """ self.file = fil l.l(l.PEDANTIC,"Using file: %s" % fil) try: self.update() l.l(l.PEDANTIC,"existing file loaded: %s" % fil) except IOError as e: # OK, we need to create it. self.blankFile()