Exemplo n.º 1
0
    def save_database(self):
        if self.save_running is False and self.changes is True:
            self.save_running = True

            kdbx = KDBX.build(self.db.kdbx,
                              password=self.db.password,
                              keyfile=self.db.keyfile)

            try:
                output_stream = self.database_file_descriptor.replace(
                    None, False, Gio.FileCreateFlags.REPLACE_DESTINATION
                    | Gio.FileCreateFlags.PRIVATE, None)
                output_stream.write_all(kdbx)
                output_stream.close()
                self.logging_manager.debug("Saved database")
                self.changes = False
            except Exception:
                self.logging_manager.error(
                    "Error occured while saving database")

            # Workaround
            # Fix created and proposed: https://github.com/pschmitt/pykeepass/pull/102
            self.db.kdbx = KDBX.parse_file(self.db.filename,
                                           password=self.db.password,
                                           keyfile=self.db.keyfile)

            self.save_running = False
Exemplo n.º 2
0
    def save(self, filename=None):
        if not filename:
            filename = self.filename

        with open(filename, 'wb') as f:
            f.write(
                KDBX.build(self.kdbx,
                           password=self.password,
                           keyfile=self.keyfile))