def _load_entries(self): """ loads the file entries """ # decrypt entries file to a temporary file key = self.get_key() fname = "cryptbox.00000001" srcpath = os.path.join(self._rootpath, fname) if not os.path.isfile(srcpath): # entry file does not exist return tempname = NamedTemporaryFile().name decrypt_file(srcpath, tempname, key) # read decrypted file line = None try: tempfile = open(tempname, "r") line = tempfile.readline() tempfile.close() except IOError: show_error_message("Unable to read temporary file %s." % tempname, True) # parse JSON content try: store_dict = json.loads(line) if type(store_dict) == dict: self._max_id = store_dict["max_id"] entry_list = store_dict["entries"] self._entries = [] self._entry_dict = {} for entry_dict in entry_list: filepath = entry_dict["filepath"] timestamp = entry_dict["timestamp"] state = entry_dict["state"] entry_id = entry_dict["entry_id"] entry = CryptStoreEntry(filepath, timestamp, state, entry_id) self._entries.append(entry) self._entry_dict[unicode(filepath)] = entry except ValueError: show_error_message("Unable to parse entry file.", False) # delete temporary file try: os.remove(tempname) except OSError: show_error_message("Unable to remove temporary file %s." % tempname)
def reply_handler (self, conn, none): tmpfd = os.open (self._filename, os.O_RDONLY) tmpfile = os.fdopen (tmpfd, 'r') if self._kwds.has_key ("fd"): fd = self._kwds["fd"] os.lseek (fd, 0, os.SEEK_SET) line = tmpfile.readline () while line != '': os.write (fd, line) line = tempfile.readline () else: file_object = self._kwds["file"] file_object.seek (0) line = tmpfile.readline () while line != '': file_object.write (line) line = tmpfile.readline () tmpfile.close () self._reply_handler (conn, none)
def reply_handler(self, conn, none): tmpfd = os.open(self._filename, os.O_RDONLY) tmpfile = os.fdopen(tmpfd, 'r') if self._kwds.has_key("fd"): fd = self._kwds["fd"] os.lseek(fd, 0, os.SEEK_SET) line = tmpfile.readline() while line != '': os.write(fd, line) line = tempfile.readline() else: file_object = self._kwds["file"] file_object.seek(0) line = tmpfile.readline() while line != '': file_object.write(line) line = tmpfile.readline() tmpfile.close() self._reply_handler(conn, none)