nncli

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

commit 34392edc521e59850568293f56971c65c4188762
parent bfcac97591b757230d6a23549d1023ac054218c2
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Mon, 10 Sep 2018 06:30:14 -0400

Final de-linting effort

Closes #10

Diffstat:
M.pylintrc | 3++-
M.travis.yml | 6+++---
M.vulture_whitelist.py | 31+++++++++++++------------------
MMakefile | 2+-
Mnncli/gui.py | 104++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mnncli/notes_db.py | 10+++-------
Mnncli/view_titles.py | 2+-
7 files changed, 76 insertions(+), 82 deletions(-)

diff --git a/.pylintrc b/.pylintrc @@ -140,7 +140,8 @@ disable=unsubscriptable-object, xreadlines-attribute, deprecated-sys-function, exception-escape, - comprehension-escape + comprehension-escape, + duplicate-code # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/.travis.yml b/.travis.yml @@ -35,9 +35,9 @@ jobs: script: make test <<: *xenial-mixin python: 3.7 - # - stage: lint - # script: make lint - # python: 3.6 + - stage: lint + script: make lint + python: 3.6 - stage: coverage script: make coverage after_success: coveralls diff --git a/.vulture_whitelist.py b/.vulture_whitelist.py @@ -1,18 +1,13 @@ -loop # unused variable (nncli/nncli.py:185) -loop # unused variable (nncli/nncli.py:735) -_.widget # unused attribute (nncli/nncli.py:746) -_.widget # unused attribute (nncli/nncli.py:750) -all_notes_cnt # unused variable (nncli/nncli.py:885) -match_regex # unused variable (nncli/nncli.py:885) -all_notes_cnt # unused variable (nncli/nncli.py:922) -match_regex # unused variable (nncli/nncli.py:922) -all_notes_cnt # unused variable (nncli/nncli.py:976) -match_regex # unused variable (nncli/nncli.py:976) -frame # unused variable (nncli/nncli.py:1057) -signum # unused variable (nncli/nncli.py:1057) -note_index # unused variable (nncli/notes_db.py:410) -note_index # unused variable (nncli/notes_db.py:510) -_.all_notes_cnt # unused attribute (nncli/view_titles.py:13) -_.match_regex # unused attribute (nncli/view_titles.py:13) -_.all_notes_cnt # unused attribute (nncli/view_titles.py:20) -_.match_regex # unused attribute (nncli/view_titles.py:20) +convert # unused function (nncli/cli.py:12) +param # unused variable (nncli/cli.py:12) +loop # unused variable (nncli/gui.py:826) +_.widget # unused attribute (nncli/gui.py:839) +_.widget # unused attribute (nncli/gui.py:844) +arg # unused variable (nncli/gui.py:888) +loop # unused variable (nncli/gui.py:888) +frame # unused variable (nncli/nncli.py:254) +signum # unused variable (nncli/nncli.py:254) +_.all_notes_cnt # unused attribute (nncli/view_titles.py:21) +_.match_regex # unused attribute (nncli/view_titles.py:21) +_.all_notes_cnt # unused attribute (nncli/view_titles.py:33) +_.match_regex # unused attribute (nncli/view_titles.py:33) diff --git a/Makefile b/Makefile @@ -57,7 +57,7 @@ clean-test: ## remove test and coverage artifacts lint: ## check style with pylint $(PIPRUN) pylint nncli tests --disable=parse-error - $(PIPRUN) vulture nncli .vulture_whitelist + $(PIPRUN) vulture nncli .vulture_whitelist.py test: ## run tests quickly with the default Python $(PIPRUN) python -m pytest diff --git a/nncli/gui.py b/nncli/gui.py @@ -17,6 +17,8 @@ def __init__(self, config, logger, ndb, key=None): self.config = config self.last_view = [] self.status_bar = self.config.get_config('status_bar') + self.config.state.current_sort_mode = \ + self.config.get_config('sort_mode') self.log_lock = threading.Lock() @@ -243,7 +245,7 @@ def _gui_body_set(self, widget): self._gui_update_status_bar() self.nncli_loop.draw_screen() - def _gui_body_get(self): + def gui_body_get(self): """Get the GUI body""" return self.master_frame.contents['body'][0] @@ -268,7 +270,7 @@ def gui_update_view(self): ) self.view_titles.focus_note(cur_key) - if self._gui_body_get().__class__ == view_note.ViewNote: + if self.gui_body_get().__class__ == view_note.ViewNote: self.view_note.update_note_view() self._gui_update_status_bar() @@ -278,7 +280,7 @@ def _gui_update_status_bar(self): if self.status_bar != 'yes': self._gui_header_clear() else: - self._gui_header_set(self._gui_body_get().get_status_bar()) + self._gui_header_set(self.gui_body_get().get_status_bar()) def _gui_switch_frame_body(self, new_view, save_current_view=True): """ @@ -291,9 +293,9 @@ def _gui_switch_frame_body(self, new_view, save_current_view=True): else: self._gui_body_set(self.last_view.pop()) else: - if self._gui_body_get().__class__ != new_view.__class__: + if self.gui_body_get().__class__ != new_view.__class__: if save_current_view: - self.last_view.append(self._gui_body_get()) + self.last_view.append(self.gui_body_get()) self._gui_body_set(new_view) def _delete_note_callback(self, key, delete): @@ -302,7 +304,7 @@ def _delete_note_callback(self, key, delete): return self.ndb.set_note_deleted(key, True) - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: self.view_titles.update_note_title() self._gui_update_status_bar() @@ -324,7 +326,7 @@ def _gui_search_input(self, args, search_string): self._gui_body_focus() self.master_frame.keypress = self._gui_frame_keypress if search_string: - if self._gui_body_get() == self.view_note: + if self.gui_body_get() == self.view_note: self.config.state.search_direction = args[1] self.view_note.search_note_view_next( search_string=search_string, @@ -344,17 +346,17 @@ def _gui_category_input(self, args, category): self._gui_body_focus() self.master_frame.keypress = self._gui_frame_keypress if category is not None: - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: note = self.view_titles.note_list \ [self.view_titles.focus_position].note - else: # self._gui_body_get().__class__ == view_note.ViewNote: + else: # self.gui_body_get().__class__ == view_note.ViewNote: note = self.view_note.note self.ndb.set_note_category(note['localkey'], category) - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: self.view_titles.update_note_title() - else: # self._gui_body_get().__class__ == view_note.ViewNote: + else: # self.gui_body_get().__class__ == view_note.ViewNote: self.view_note.update_note_view() self._gui_update_status_bar() @@ -366,10 +368,10 @@ def _gui_pipe_input(self, args, cmd): self._gui_body_focus() self.master_frame.keypress = self._gui_frame_keypress if cmd is not None: - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: note = self.view_titles.note_list \ [self.view_titles.focus_position].note - else: # self._gui_body_get().__class__ == view_note.ViewNote: + else: # self.gui_body_get().__class__ == view_note.ViewNote: note = self.view_note.old_note \ if self.view_note.old_note \ else self.view_note.note @@ -392,7 +394,7 @@ def _gui_frame_keypress(self, size, key): if key == ' ': key = 'space' - contents = self._gui_body_get() + contents = self.gui_body_get() if key == self.config.get_keybind('quit'): self._gui_switch_frame_body(None) @@ -490,7 +492,7 @@ def _gui_frame_keypress(self, size, key): coming_from='below') elif key == self.config.get_keybind('view_next_note'): - if self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_note.ViewNote: return key if not self.view_titles.body.positions(): @@ -507,7 +509,7 @@ def _gui_frame_keypress(self, size, key): self._gui_switch_frame_body(self.view_note) elif key == self.config.get_keybind('view_prev_note'): - if self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_note.ViewNote: return key if not self.view_titles.body.positions(): @@ -529,7 +531,7 @@ def _gui_frame_keypress(self, size, key): self.status_bar = self.config.get_config('status_bar') elif key == self.config.get_keybind('create_note'): - if self._gui_body_get().__class__ != view_titles.ViewTitles: + if self.gui_body_get().__class__ != view_titles.ViewTitles: return key self._gui_clear() @@ -545,15 +547,15 @@ def _gui_frame_keypress(self, size, key): elif key == self.config.get_keybind('edit_note') or \ key == self.config.get_keybind('view_note_ext') or \ key == self.config.get_keybind('view_note_json'): - if self._gui_body_get().__class__ != view_titles.ViewTitles and \ - self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: return key - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: if not contents.body.positions(): return None note = contents.note_list[contents.focus_position].note - else: # self._gui_body_get().__class__ == view_note.ViewNote: + else: # self.gui_body_get().__class__ == view_note.ViewNote: if key == self.config.get_keybind('edit_note'): note = contents.note else: @@ -592,16 +594,16 @@ def _gui_frame_keypress(self, size, key): if md5_old != md5_new: self.log('Note updated') self.ndb.set_note_content(note['localkey'], content) - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: contents.update_note_title() - else: # self._gui_body_get().__class__ == view_note.ViewNote: + else: # self.gui_body_get().__class__ == view_note.ViewNote: contents.update_note_view() self.ndb.sync_worker_go() else: self.log('Note unchanged') elif key == self.config.get_keybind('view_note'): - if self._gui_body_get().__class__ != view_titles.ViewTitles: + if self.gui_body_get().__class__ != view_titles.ViewTitles: return key if not contents.body.positions(): @@ -612,15 +614,15 @@ def _gui_frame_keypress(self, size, key): self._gui_switch_frame_body(self.view_note) elif key == self.config.get_keybind('pipe_note'): - if self._gui_body_get().__class__ != view_titles.ViewTitles and \ - self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: return key - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: if not contents.body.positions(): return None note = contents.note_list[contents.focus_position].note - else: # self._gui_body_get().__class__ == view_note.ViewNote: + else: # self.gui_body_get().__class__ == view_note.ViewNote: note = contents.old_note if contents.old_note else contents.note self._gui_footer_input_set( @@ -640,15 +642,15 @@ def _gui_frame_keypress(self, size, key): self._gui_footer_input_get().keypress elif key == self.config.get_keybind('note_delete'): - if self._gui_body_get().__class__ != view_titles.ViewTitles and \ - self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: return key - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: if not contents.body.positions(): return None note = contents.note_list[contents.focus_position].note - else: # self._gui_body_get().__class__ == view_note.ViewNote: + else: # self.gui_body_get().__class__ == view_note.ViewNote: note = contents.note self._gui_footer_input_set( @@ -671,36 +673,36 @@ def _gui_frame_keypress(self, size, key): self._gui_footer_input_get().keypress elif key == self.config.get_keybind('note_favorite'): - if self._gui_body_get().__class__ != view_titles.ViewTitles and \ - self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: return key - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: if not contents.body.positions(): return None note = contents.note_list[contents.focus_position].note - else: # self._gui_body_get().__class__ == view_note.ViewNote: + else: # self.gui_body_get().__class__ == view_note.ViewNote: note = contents.note favorite = not note['favorite'] self.ndb.set_note_favorite(note['localkey'], favorite) - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: contents.update_note_title() self.ndb.sync_worker_go() elif key == self.config.get_keybind('note_category'): - if self._gui_body_get().__class__ != view_titles.ViewTitles and \ - self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: return key - if self._gui_body_get().__class__ == view_titles.ViewTitles: + if self.gui_body_get().__class__ == view_titles.ViewTitles: if not contents.body.positions(): return None note = contents.note_list[contents.focus_position].note - else: # self._gui_body_get().__class__ == view_note.ViewNote: + else: # self.gui_body_get().__class__ == view_note.ViewNote: note = contents.note self._gui_footer_input_set( @@ -723,11 +725,11 @@ def _gui_frame_keypress(self, size, key): key == self.config.get_keybind('search_regex') or \ key == self.config.get_keybind('search_prev_gstyle') or \ key == self.config.get_keybind('search_prev_regex'): - if self._gui_body_get().__class__ != view_titles.ViewTitles and \ - self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_titles.ViewTitles and \ + self.gui_body_get().__class__ != view_note.ViewNote: return key - if self._gui_body_get().__class__ == view_note.ViewNote: + if self.gui_body_get().__class__ == view_note.ViewNote: if key == self.config.get_keybind('search_prev_gstyle') or \ key == self.config.get_keybind('search_prev_regex'): self.view_note.search_direction = 'backward' @@ -767,19 +769,19 @@ def _gui_frame_keypress(self, size, key): self._gui_footer_input_get().keypress elif key == self.config.get_keybind('search_next'): - if self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_note.ViewNote: return key self.view_note.search_note_view_next() elif key == self.config.get_keybind('search_prev'): - if self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_note.ViewNote: return key self.view_note.search_note_view_prev() elif key == self.config.get_keybind('clear_search'): - if self._gui_body_get().__class__ != view_titles.ViewTitles: + if self.gui_body_get().__class__ != view_titles.ViewTitles: return key self.view_titles.update_note_list( @@ -789,28 +791,28 @@ def _gui_frame_keypress(self, size, key): self._gui_body_set(self.view_titles) elif key == self.config.get_keybind('sort_date'): - if self._gui_body_get().__class__ != view_titles.ViewTitles: + if self.gui_body_get().__class__ != view_titles.ViewTitles: return key self.config.state.current_sort_mode = 'date' self.view_titles.sort_note_list('date') elif key == self.config.get_keybind('sort_alpha'): - if self._gui_body_get().__class__ != view_titles.ViewTitles: + if self.gui_body_get().__class__ != view_titles.ViewTitles: return key self.config.state.current_sort_mode = 'alpha' self.view_titles.sort_note_list('alpha') elif key == self.config.get_keybind('sort_categories'): - if self._gui_body_get().__class__ != view_titles.ViewTitles: + if self.gui_body_get().__class__ != view_titles.ViewTitles: return key self.config.state.current_sort_mode = 'categories' self.view_titles.sort_note_list('categories') elif key == self.config.get_keybind('copy_note_text'): - if self._gui_body_get().__class__ != view_note.ViewNote: + if self.gui_body_get().__class__ != view_note.ViewNote: return key self.view_note.copy_note_text() diff --git a/nncli/notes_db.py b/nncli/notes_db.py @@ -367,10 +367,6 @@ def get_note(self, key): """Get a note from the database""" return self.notes[key] - def _get_note_category(self, key): - """Get a category for a note""" - return self.notes[key].get('category') - @staticmethod def _flag_what_changed(note, what_changed): """Flag a note field as changed""" @@ -671,7 +667,7 @@ def _get_note_status(self, key): obj.saved = True return obj - def _verify_all_saved(self): + def verify_all_saved(self): """ Verify all notes in the local database are saved to the server @@ -693,7 +689,7 @@ def sync_now(self, do_server_sync=True): full_sync=True if not self.last_sync else False) self.sync_lock.release() - def _sync_worker(self, do_server_sync): + def sync_worker(self, do_server_sync): """The sync worker thread""" time.sleep(1) # give some time to wait for GUI initialization self.log('Sync worker: started') @@ -704,7 +700,7 @@ def _sync_worker(self, do_server_sync): self.sync_now(do_server_sync) self.go_cond.release() - def _sync_worker_go(self): + def sync_worker_go(self): """Start the sync worker""" self.go_cond.acquire() self.go_cond.notify() diff --git a/nncli/view_titles.py b/nncli/view_titles.py @@ -36,7 +36,7 @@ def update_note_list(self, search_string, ) self.body[:] = \ urwid.SimpleFocusListWalker(self.get_note_titles()) - if self.note_list: + if not self.note_list: self.log('No notes found!') else: self.focus_position = 0