nncli

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

commit 2580e5087491c5bc02c0c3a3193da1aca1923f18
parent 838537a8cb37f47b7a24ae14648a33fc46aa68be
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Wed,  5 Sep 2018 18:39:01 -0400

Address vulture findings

Diffstat:
A.vulture_whitelist.py | 18++++++++++++++++++
MMakefile | 1+
Mnncli/config.py | 4++--
Mnncli/nextcloud_note.py | 32--------------------------------
Mnncli/nncli.py | 52----------------------------------------------------
Mnncli/notes_db.py | 21---------------------
Mnncli/utils.py | 19-------------------
7 files changed, 21 insertions(+), 126 deletions(-)

diff --git a/.vulture_whitelist.py b/.vulture_whitelist.py @@ -0,0 +1,18 @@ +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) diff --git a/Makefile b/Makefile @@ -57,6 +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 test: ## run tests quickly with the default Python $(PIPRUN) python -m pytest diff --git a/nncli/config.py b/nncli/config.py @@ -118,9 +118,9 @@ def __init__(self, custom_file=None): cp = configparser.SafeConfigParser(defaults) if custom_file is not None: - self.configs_read = cp.read([custom_file]) + cp.read([custom_file]) else: - self.configs_read = cp.read([os.path.join(self.config_home, 'config')]) + cp.read([os.path.join(self.config_home, 'config')]) cfg_sec = 'nncli' diff --git a/nncli/nextcloud_note.py b/nncli/nextcloud_note.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- -import urllib.parse from requests.exceptions import RequestException, ConnectionError -import base64 import time import datetime import logging @@ -18,11 +16,6 @@ # For Google AppEngine from django.utils import simplejson as json -NOTE_FETCH_LENGTH = 100 - -class NextcloudLoginFailed(Exception): - pass - class NextcloudNote(object): """ Class for interacting with the NextCloud Notes web service """ @@ -127,31 +120,6 @@ def update_note(self, note): #logging.debug('RESPONSE OK: ' + str(note)) return note, 0 - def add_note(self, note): - """wrapper function to add a note - - The function can be passed the note as a dict with the `content` - property set, which is then directly send to the web service for - creation. Alternatively, only the body as string can also be passed. In - this case the parameter is used as `content` for the new note. - - Arguments: - - note (dict or string): the note to add - - Returns: - A tuple `(note, status)` - - - note (dict): the newly created note - - status (int): 0 on sucesss and -1 otherwise - - """ - if type(note) == str: - return self.update_note({"content": note}) - elif (type(note) == dict) and "content" in note: - return self.update_note(note) - else: - return "No string or valid note.", -1 - def get_note_list(self, category=None): """ function to get the note list diff --git a/nncli/nncli.py b/nncli/nncli.py @@ -75,13 +75,6 @@ def get_pager(self): return None return pager - def get_diff(self): - diff = self.config.get_config('diff') - if not diff: - self.log('No diff command configured!') - return None - return diff - def exec_cmd_on_note(self, note, cmd=None, raw=False): if not cmd: @@ -136,41 +129,6 @@ def exec_cmd_on_note(self, note, cmd=None, raw=False): return content - def exec_diff_on_note(self, note, old_note): - - diff = self.get_diff() - if not diff: - return None - - pager = self.get_pager() - if not pager: - return None - - ltf = temp.tempfile_create(note, tempdir=self.tempdir) - otf = temp.tempfile_create(old_note, tempdir=self.tempdir) - out = temp.tempfile_create(None, tempdir=self.tempdir) - - try: - subprocess.call(diff + ' ' + - temp.tempfile_name(ltf) + ' ' + - temp.tempfile_name(otf) + ' > ' + - temp.tempfile_name(out), - shell=True) - subprocess.check_call(pager + ' ' + - temp.tempfile_name(out), - shell=True) - except Exception as e: - self.log('Command error: ' + str(e)) - temp.tempfile_delete(ltf) - temp.tempfile_delete(otf) - temp.tempfile_delete(out) - return None - - temp.tempfile_delete(ltf) - temp.tempfile_delete(otf) - temp.tempfile_delete(out) - return None - def gui_header_clear(self): self.master_frame.contents['header'] = ( None, None ) self.nncli_loop.draw_screen() @@ -179,12 +137,6 @@ def gui_header_set(self, w): self.master_frame.contents['header'] = ( w, None ) self.nncli_loop.draw_screen() - def gui_header_get(self): - return self.master_frame.contents['header'][0] - - def gui_header_focus(self): - self.master_frame.focus_position = 'header' - def gui_footer_log_clear(self): ui = self.gui_footer_input_get() self.master_frame.contents['footer'] = \ @@ -219,10 +171,6 @@ def gui_footer_focus_input(self): self.master_frame.focus_position = 'footer' self.master_frame.contents['footer'][0].focus_position = 1 - def gui_body_clear(self): - self.master_frame.contents['body'] = ( None, None ) - self.nncli_loop.draw_screen() - def gui_body_set(self, w): self.master_frame.contents['body'] = ( w, None ) self.gui_update_status_bar() diff --git a/nncli/notes_db.py b/nncli/notes_db.py @@ -2,8 +2,6 @@ import os, time, re, glob, json, copy, threading from . import utils -from . import nextcloud_note -nextcloud_note.NOTE_FETCH_LENGTH=100 from .nextcloud_note import NextcloudNote import logging @@ -64,11 +62,6 @@ def __init__(self, config, log, update_view): self.config.get_config('nn_password'), self.config.get_config('nn_host')) - # we'll use this to store which notes are currently being synced by - # the background thread, so we don't add them anew if they're still - # in progress. This variable is only used by the background thread. - self.threaded_syncing_keys = {} - def filtered_notes_sort(self, filtered_notes, sort_mode='date'): if sort_mode == 'date': if self.config.get_config('favorite_ontop') == 'yes': @@ -321,15 +314,9 @@ def create_note(self, content): def get_note(self, key): return self.notes[key] - def get_note_favorite(self, key): - return self.notes[key].get('favorite') - def get_note_category(self, key): return self.notes[key].get('category') - def get_note_content(self, key): - return self.notes[key].get('content') - def flag_what_changed(self, note, what_changed): if 'what_changed' not in note: note['what_changed'] = [] @@ -520,7 +507,6 @@ def sync_notes(self, server_sync=True, full_sync=True): # a new note and key is not in local store # retrieve note, update note with response if not skip_remote_syncing: - len_nl = len(nl) for note_index, n in enumerate(nl): k = n.get('id') c = n.get('category') if n.get('category') is not None \ @@ -602,16 +588,9 @@ def get_note_status(self, key): o = utils.KeyValueObject(saved=False, synced=False, modified=False) modified = float(n['modified']) savedate = float(n['savedate']) - syncdate = float(n['syncdate']) if savedate > modified: o.saved = True - else: - o.modified = True - - if syncdate > modified: - o.synced = True - return o def verify_all_saved(self): diff --git a/nncli/utils.py b/nncli/utils.py @@ -34,25 +34,6 @@ def get_note_title(note): else: return '' -def get_note_title_file(note): - mo = note_title_re.match(note.get('content', '')) - if mo: - fn = mo.groups()[0] - fn = fn.replace(' ', '_') - fn = fn.replace('/', '_') - if not fn: - return '' - - if isinstance(fn, str): - fn = str(fn, 'utf-8') - else: - fn = str(fn) - - fn += '.mkdn' - return fn - else: - return '' - def note_favorite(n): if 'favorite' in n: return n['favorite']