nncli

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

commit fb854e230abfb27224cb8bbcacaa60e259540d6f
parent cb5ef04d3fa8a45054a16d517e3525071045848e
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sat, 18 Dec 2021 08:18:39 -0500

nncli: Always check do_server_sync before syncing

Diffstat:
Mnncli/nncli.py | 30++++++++++++++++++++++++------
Mnncli/notes_db.py | 4++--
2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/nncli/nncli.py b/nncli/nncli.py @@ -130,7 +130,10 @@ def cli_note_create(self, from_stdin, title): if content: self.logger.log('New note created') self.ndb.create_note(content) - self.ndb.sync_now() + if self.config.state.do_server_sync: + self.ndb.sync_now() + else: + self.ndb.save_note(note['localkey'], note) def cli_note_import(self, from_stdin): """Import a note from the command line""" @@ -145,7 +148,10 @@ def cli_note_import(self, from_stdin): note = json.loads(raw) self.logger.log('New note created') self.ndb.import_note(note) - self.ndb.sync_now() + if self.config.state.do_server_sync: + self.ndb.sync_now() + else: + self.ndb.save_note(note['localkey'], note) except ValueError as ex: self.logger.log('(IMPORT) ValueError: {}'.format(ex)) sys.exit(1) @@ -191,7 +197,10 @@ def cli_note_edit(self, from_stdin, key): if md5_old != md5_new: self.logger.log('Note updated') self.ndb.set_note_content(note['localkey'], content) - self.ndb.sync_now() + if self.config.state.do_server_sync: + self.ndb.sync_now() + else: + self.ndb.save_note(note['localkey'], note) else: self.logger.log('Note unchanged') @@ -203,7 +212,10 @@ def cli_note_delete(self, key, delete): return self.ndb.set_note_deleted(key, delete) - self.ndb.sync_now() + if self.config.state.do_server_sync: + self.ndb.sync_now() + else: + self.ndb.save_note(note['localkey'], note) def cli_note_favorite(self, key, favorite): """Favorite a note from the command line""" @@ -213,7 +225,10 @@ def cli_note_favorite(self, key, favorite): return self.ndb.set_note_favorite(key, favorite) - self.ndb.sync_now() + if self.config.state.do_server_sync: + self.ndb.sync_now() + else: + self.ndb.save_note(note['localkey'], note) def cli_note_category_get(self, key): """Get a note category from the command line""" @@ -233,7 +248,10 @@ def cli_note_category_set(self, key, category): return self.ndb.set_note_category(key, category.lower()) - self.ndb.sync_now() + if self.config.state.do_server_sync: + self.ndb.sync_now() + else: + self.ndb.save_note(note['localkey'], note) def cli_note_category_rm(self, key): """Remove a note category from the command line""" diff --git a/nncli/notes_db.py b/nncli/notes_db.py @@ -422,7 +422,7 @@ def _helper_key_to_fname(self, k): """Convert a note key into a file name""" return os.path.join(self.config.get_config('db_path'), str(k)) + '.json' - def _helper_save_note(self, k, note): + def save_note(self, k, note): """Save a note to the file system""" # Save a single note to disc. func = self._helper_key_to_fname(k) @@ -634,7 +634,7 @@ def sync_notes(self, server_sync=True, full_sync=True): for key in list(local_updates.keys()): try: - self._helper_save_note(key, self.notes[key]) + self.save_note(key, self.notes[key]) except WriteError as ex: raise WriteError(str(ex)) self.log("Saved note to disk (key={0})".format(key))