Beispiel #1
0
 def save_state_to(self, key):
     # TODO: this is a hack, for 0.50 this case should be covered by the
     # handler's protocol
     File.save_state_to(self, key)
     if key == self.key:
         self.added_records = []
         self.removed_records = []
Beispiel #2
0
 def save_state_to(self, key):
     # TODO: this is a hack, for 0.50 this case should be covered by the
     # handler's protocol
     File.save_state_to(self, key)
     if key == self.key:
         self.added_records = []
         self.removed_records = []
Beispiel #3
0
    def save_state(self):
        if self.incremental_save is False:
            File.save_state(self)
            self.incremental_save = True
            return

        # Incremental Save
        file = self.safe_open(self.key, 'a')
        try:
            # Added properties records
            for seq in self.added_properties:
                version = self.properties[seq]
                version = self._version_to_str(-1, seq, version)
                file.write(version)
            self.added_properties = []
            # Added records
            for id, seq in self.added_records:
                version = self.records[id][seq]
                version = self._version_to_str(id, seq, version)
                file.write(version)
            self.added_records = []
            # Removed records
            for id, ts in self.removed_records:
                file.write('id:%s/DELETED\n' % id)
                file.write('ts:%s\n' % DateTime.encode(ts))
                file.write('\n')
            self.removed_records = []
        finally:
            file.close()

        # Update the timestamp
        self.timestamp = self.database.fs.get_mtime(self.key)
        self.dirty = None
Beispiel #4
0
    def save_state(self):
        if self.incremental_save is False:
            File.save_state(self)
            self.incremental_save = True
            return

        # Incremental Save
        file = self.safe_open(self.key, 'a')
        try:
            # Added properties records
            for seq in self.added_properties:
                version = self.properties[seq]
                version = self._version_to_str(-1, seq, version)
                file.write(version)
            self.added_properties = []
            # Added records
            for id, seq in self.added_records:
                version = self.records[id][seq]
                version = self._version_to_str(id, seq, version)
                file.write(version)
            self.added_records = []
            # Removed records
            for id, ts in self.removed_records:
                file.write('id:%s/DELETED\n' % id)
                file.write('ts:%s\n' % DateTime.encode(ts))
                file.write('\n')
            self.removed_records = []
        finally:
            file.close()

        # Update the timestamp
        self.timestamp = self.database.fs.get_mtime(self.key)
        self.dirty = None
Beispiel #5
0
 def test_abort(self):
     handler = File('tests/hello.txt')
     self.assertEqual(handler.data, u'hello world\n')
     handler.set_data(u'bye world\n')
     self.assertEqual(handler.data, u'bye world\n')
     handler.abort_changes()
     self.assertEqual(handler.data, u'hello world\n')