Esempio n. 1
0
    def test_get_changed_content(self):
        notename = list(self.db_notes.keys())[0]
        note = self.db_notes[notename]
        filepath = note.filepath

        # Read data from file, not using NoteModel
        raw_data = NoteModel.enc_read(filepath)
        content, metadata = NoteModel.parse_note_content(raw_data)
        timestamp = os.stat(filepath).st_mtime

        self.assertEqual(note.content, content)
        self.assertEqual(note.timestamp, timestamp)

        # Make a change
        new_content = content + '\nNew line\n'
        self.assertNotEqual(note.content, new_content)

        # Write changed data not from NoteModel
        filedata = new_content + END_OF_TEXT + '\n'
        for key, value in list(metadata.items()):
            filedata = filedata + '{0}:{1}\n'.format(key, value)
        NoteModel.enc_write(filepath, filedata)

        # Change happened?
        self.assertNotEqual(note.timestamp, timestamp)

        # And the content automatically updates when accessed
        self.assertEqual(note.content, new_content)

        # Reset file
        filedata = content + END_OF_TEXT + '\n'
        for key, value in list(metadata.items()):
            filedata = filedata + '{0}:{1}\n'.format(key, value)
        NoteModel.enc_write(filepath, filedata)
Esempio n. 2
0
 def save_conf(self):
     filepath = os.path.join(self.app_data_dir, 'conf.yml')
     self.conf['motome_version'] = VERSION
     self.conf['conf_update'] = time.time()
     try:
         data = yaml.safe_dump(self.conf, default_flow_style=False)
         out = '# Motome configuration values\n---\n' + data + '...'
         NoteModel.enc_write(filepath, out)
     except IOError:
         pass
Esempio n. 3
0
def transition_versions(notes_dir):
    """ Change notes from the old metadata style to the new (0.1.0 - 0.2.0)

    :param notes_dir:
    :return:
    """
    notepaths = set(glob.glob(notes_dir + '/*' + '.txt'))

    for notepath in notepaths:
        try:
            data = NoteModel.enc_read(notepath)
            c, m = parse_note_content_old(data)
            if len(list(m.keys())) == 0:
                new_data = c
            else:
                new_data = c + YAML_BRACKET + '\n' + yaml.safe_dump(m, default_flow_style=False) + YAML_BRACKET

            NoteModel.enc_write(notepath, new_data)
        except Exception as e:
            logging.error('[transition_versions] %r' % e)
Esempio n. 4
0
def transition_versions(notes_dir):
    """ Change notes from the old metadata style to the new (0.1.0 - 0.2.0)

    :param notes_dir:
    :return:
    """
    notepaths = set(glob.glob(notes_dir + '/*' + '.txt'))

    for notepath in notepaths:
        try:
            data = NoteModel.enc_read(notepath)
            c, m = parse_note_content_old(data)
            if len(m.keys()) == 0:
                new_data = c
            else:
                new_data = c + YAML_BRACKET + '\n' + yaml.safe_dump(m, default_flow_style=False) + YAML_BRACKET

            NoteModel.enc_write(notepath, new_data)
        except Exception as e:
            logging.error('[transition_versions] %r' % e)