Example #1
0
	def blankFile(self):
		"""
		`blankFile` simply blanks out the bfile loaded.
		"""
		l.l(l.PEDANTIC,"creating blank file: %s" % self.file)
		self.setContent("")
		self.write()
Example #2
0
	def blankFile(self):
		"""
		`blankFile` blanks a file.
		"""
		l.l(l.PEDANTIC,"creating blank file: %s" % self.file)
		self.setContent({})
		self.write()
Example #3
0
	def blankFile(self):
		"""
		@see: bfile.bfile.blankFile
		"""
		l.l(l.PEDANTIC,"creating blank file: %s" % self.file)
		self.setContent({})
		self.write()
Example #4
0
	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)
Example #5
0
	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)
Example #6
0
	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()
Example #7
0
	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()
Example #8
0
	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()
Example #9
0
	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()
Example #10
0
	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()
Example #11
0
	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()
Example #12
0
    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)
Example #13
0
	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()
Example #14
0
	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()