Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Final de-linting effort
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
djmoch committed Sep 10, 2018
1 parent bfcac97 commit 34392ed
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 82 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 13 additions & 18 deletions .vulture_whitelist.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
104 changes: 53 additions & 51 deletions nncli/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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]

Expand All @@ -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()
Expand All @@ -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):
"""
Expand All @@ -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):
Expand All @@ -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()
Expand All @@ -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,
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand All @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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():
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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'
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand Down
Loading

0 comments on commit 34392ed

Please sign in to comment.