nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit 14a31805879d6002936c8519e545c599f3b0d1bc
parent fe9b261e4e3a79b5fa97b19e344f9dfa7713db5d
Author: Samuel Walladge <samuel@swalladge.id.au>
Date:   Thu,  7 Jul 2016 09:30:58 +0930

fixes to stabilise localkey handling

Diffstat:
Msimplenote_cli/notes_db.py | 15+++++++--------
Msimplenote_cli/simplenote.py | 1-
Msimplenote_cli/sncli.py | 2--
Msimplenote_cli/view_titles.py | 2+-
4 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/simplenote_cli/notes_db.py b/simplenote_cli/notes_db.py @@ -49,8 +49,7 @@ def __init__(self, config, log, update_view): raise ReadError ('Error reading {0}: {1}'.format(fn, str(e))) else: # we always have a localkey, also when we don't have a note['key'] yet (no sync) - localkey = os.path.splitext(os.path.basename(fn))[0] - self.notes[localkey] = n + localkey = n.get('localkey', os.path.splitext(os.path.basename(fn))[0]) # we maintain in memory a timestamp of the last save # these notes have just been read, so at this moment # they're in sync with the disc. @@ -58,6 +57,8 @@ def __init__(self, config, log, update_view): # set a localkey to each note in memory n['localkey'] = localkey + self.notes[localkey] = n + # initialise the simplenote instance we're going to use # this does not yet need network access self.simplenote = Simplenote(self.config.get_config('sn_username'), @@ -374,10 +375,6 @@ def helper_key_to_fname(self, k): def helper_save_note(self, k, note): # Save a single note to disc. fn = self.helper_key_to_fname(k) - # TODO: don't save localkey - # - can't do the following because it updates the note everywhere - # if 'localkey' in note: - # note.pop('localkey') json.dump(note, open(fn, 'w'), indent=2) # record that we saved this to disc. @@ -431,7 +428,6 @@ def sync_notes(self, server_sync=True, full_sync=True): # save note to server, update note with response for note_index, local_key in enumerate(self.notes.keys()): n = self.notes[local_key] - # TODO: don't send localkey with this if not n.get('key') or \ float(n.get('modifydate')) > float(n.get('syncdate')): @@ -453,6 +449,9 @@ def sync_notes(self, server_sync=True, full_sync=True): if 'what_changed' in n: del n['what_changed'] + if 'localkey' in cn: + del cn['localkey'] + if 'minversion' in cn: del cn['minversion'] del cn['createdate'] @@ -462,7 +461,7 @@ def sync_notes(self, server_sync=True, full_sync=True): if 'what_changed' in cn: if 'deleted' not in cn['what_changed']: del cn['deleted'] - if 'systemtags' not in cn['what_changed']: + if 'systemtags' not in cn['what_changed'] and 'systemtags' in cn: del cn['systemtags'] if 'tags' not in cn['what_changed']: del cn['tags'] diff --git a/simplenote_cli/simplenote.py b/simplenote_cli/simplenote.py @@ -158,7 +158,6 @@ def update_note(self, note): else: url = self.DATA_URL - # TODO: remove localkey temporarily before posting #logging.debug('REQUEST: ' + url + ' - ' + str(note)) try: res = requests.post(url, data=json.dumps(note), params=params) diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -652,7 +652,6 @@ def gui_frame_keypress(self, size, key): if md5_old != md5_new: self.log('Note updated') - self.log(note.__repr__()) self.ndb.set_note_content(note['localkey'], content) if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title() @@ -668,7 +667,6 @@ def gui_frame_keypress(self, size, key): if len(lb.body.positions()) <= 0: return None - self.log(lb.note_list[lb.focus_position].note.__repr__()) self.view_note.update_note_view( lb.note_list[lb.focus_position].note['localkey']) self.gui_switch_frame_body(self.view_note) diff --git a/simplenote_cli/view_titles.py b/simplenote_cli/view_titles.py @@ -179,7 +179,7 @@ def update_note_title(self, key=None): def focus_note(self, key): for i in range(len(self.note_list)): - if 'key' in self.note_list[i].note and \ + if 'localkey' in self.note_list[i].note and \ self.note_list[i].note['localkey'] == key: self.focus_position = i