nncli

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

commit c364a1abc7b3e1405bb2aaed41b0fe506fd53b69
parent d45d66ce377c881bd3f11968c605275c82df9f23
Author: Eric Davis <edavis@insanum.com>
Date:   Wed,  2 Jul 2014 19:53:27 -0700

added a background sync_worker thread

Diffstat:
Msncli.py | 49+++++++------------------------------------------
1 file changed, 7 insertions(+), 42 deletions(-)

diff --git a/sncli.py b/sncli.py @@ -44,18 +44,20 @@ def __init__(self, do_sync): self.status_message_alarm = None self.status_message_lock = threading.Lock() - self.sync_notes_alarm = None - self.sync_notes_lock = threading.Lock() self.thread_save = threading.Thread(target=self.ndb.save_worker) self.thread_save.setDaemon(True) + self.thread_sync = threading.Thread(target=self.ndb.sync_worker) + self.thread_sync.setDaemon(True) + self.ndb.add_observer('synced:note', self.observer_notes_db_synced_note) self.ndb.add_observer('change:note-status', self.observer_notes_db_change_note_status) self.ndb.add_observer('progress:sync_full', self.observer_notes_db_sync_full) def start_threads(self): self.thread_save.start() + self.thread_sync.start() def sync_full_threaded(self): thread.start_new_thread(self.ndb.sync_full, ()) @@ -63,39 +65,6 @@ def sync_full_threaded(self): def sync_full_initial(self, loop, arg): self.sync_full_threaded() - def sync_notes_cancel(self): - self.sync_notes_lock.acquire() - - if self.sync_notes_alarm: - self.sncli_loop.remove_alarm(self.sync_notes_alarm) - self.sync_notes_alarm = None - - self.sync_notes_lock.release() - - def sync_notes_timeout(self, loop, arg): - self.sync_notes_lock.acquire() - - self.sync_notes_alarm = None - self.status_message_set('Starting sync...') - self.ndb.sync_to_server_threaded() - self.status_message_set('Sync complete.') - - self.sync_notes_lock.release() - - def sync_notes_schedule(self): - self.sync_notes_lock.acquire() - - if self.sync_notes_alarm: - self.sncli_loop.remove_alarm(self.sync_notes_alarm) - self.sync_notes_alarm = None - - self.sync_notes_alarm = \ - self.sncli_loop.set_alarm_at(time.time() + 4, - self.sync_notes_timeout, - None) - - self.sync_notes_lock.release() - def observer_notes_db_change_note_status(self, ndb, evt_type, evt): logging.debug(evt.msg) self.status_message_set(evt.msg) @@ -231,8 +200,7 @@ def search_input(self, search_string): 'ndb' : self.ndb, 'search_string' : search_string, 'body_changer' : self.switch_frame_body, - 'status_message' : self.status_message_set, - 'sync_func' : self.sync_notes_schedule + 'status_message' : self.status_message_set })) else: self.footer_clear() @@ -249,7 +217,6 @@ def tags_input(self, tags): self.ndb.set_note_tags(lb.all_notes[lb.focus_position].note['key'], tags) lb.update_note_title(None, lb.focus_position) self.update_status_bar() - self.sync_notes_schedule() else: self.footer_clear() self.body_focus() @@ -391,8 +358,7 @@ def frame_keypress(self, size, key): 'ndb' : self.ndb, 'search_string' : None, 'body_changer' : self.switch_frame_body, - 'status_message' : self.status_message_set, - 'sync_func' : self.sync_notes_schedule + 'status_message' : self.status_message_set })) else: @@ -409,8 +375,7 @@ def init_view(self, loop, arg): 'ndb' : self.ndb, 'search_string' : None, 'body_changer' : self.switch_frame_body, - 'status_message' : self.status_message_set, - 'sync_func' : self.sync_notes_schedule + 'status_message' : self.status_message_set })) self.start_threads()