nncli

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

commit e86031cce3024d79fd38e225f5754e3da99cd258
parent c1bda40e9bf6c0a797f46ed8d755d0dd896a3fa3
Author: Eric Davis <edavis@insanum.com>
Date:   Sun,  6 Jul 2014 15:46:15 -0700

new keybind command for creating a new note

Diffstat:
Mconfig.py | 14+++++++++-----
Mnotes_db.py | 22++++++++++++----------
Msncli.py | 27+++++++++++++++++++++++----
Mtemp.py | 6++++++
4 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/config.py b/config.py @@ -18,6 +18,7 @@ def __init__(self): 'cfg_format_strftime' : '%Y/%m/%d', 'cfg_format_note_title' : '[%D] %F %-N %T', 'cfg_status_bar' : 'yes', + 'cfg_editor' : 'vim', 'cfg_pager' : 'less -c', 'cfg_log_reversed' : 'yes', @@ -32,6 +33,7 @@ def __init__(self): 'kb_bottom' : 'G', 'kb_top' : 'g', 'kb_status' : 's', + 'kb_create_note' : 'C', 'kb_view_note' : 'enter', 'kb_view_note_ext' : 'meta enter', 'kb_view_next_note' : 'J', @@ -111,6 +113,7 @@ def __init__(self): 'format_strftime' : [ cp.get(cfg_sec, 'cfg_format_strftime', raw=True), 'Date strftime format' ], 'format_note_title' : [ cp.get(cfg_sec, 'cfg_format_note_title', raw=True), 'Note title format' ], 'status_bar' : [ cp.get(cfg_sec, 'cfg_status_bar'), 'Status bar location' ], + 'editor' : [ cp.get(cfg_sec, 'cfg_editor'), 'Editor' ], 'pager' : [ cp.get(cfg_sec, 'cfg_pager'), 'External pager' ], 'log_reversed' : [ cp.get(cfg_sec, 'cfg_log_reversed'), 'Log file reversed' ] } @@ -129,13 +132,14 @@ def __init__(self): 'top' : [ cp.get(cfg_sec, 'kb_top'), [ 'common' ], 'Goto top' ], 'status' : [ cp.get(cfg_sec, 'kb_status'), [ 'common' ], 'Toggle status bar' ], 'view_log' : [ cp.get(cfg_sec, 'kb_view_log'), [ 'common' ], 'View log' ], + 'create_note' : [ cp.get(cfg_sec, 'kb_create_note'), [ 'titles' ], 'Create a new note' ], 'view_note' : [ cp.get(cfg_sec, 'kb_view_note'), [ 'titles' ], 'View note' ], 'view_note_ext' : [ cp.get(cfg_sec, 'kb_view_note_ext'), [ 'titles' ], 'View note with pager' ], - 'view_next_note' : [ cp.get(cfg_sec, 'kb_view_next_note'), [ 'notes' ], 'View next note' ], - 'view_prev_note' : [ cp.get(cfg_sec, 'kb_view_prev_note'), [ 'notes' ], 'View previous note' ], - 'tabstop2' : [ cp.get(cfg_sec, 'kb_tabstop2'), [ 'notes' ], 'View with tabstop=2' ], - 'tabstop4' : [ cp.get(cfg_sec, 'kb_tabstop4'), [ 'notes' ], 'View with tabstop=4' ], - 'tabstop8' : [ cp.get(cfg_sec, 'kb_tabstop8'), [ 'notes' ], 'View with tabstop=8' ], + 'view_next_note' : [ cp.get(cfg_sec, 'kb_view_next_note'), [ 'notes' ], 'View next note' ], + 'view_prev_note' : [ cp.get(cfg_sec, 'kb_view_prev_note'), [ 'notes' ], 'View previous note' ], + 'tabstop2' : [ cp.get(cfg_sec, 'kb_tabstop2'), [ 'notes' ], 'View with tabstop=2' ], + 'tabstop4' : [ cp.get(cfg_sec, 'kb_tabstop4'), [ 'notes' ], 'View with tabstop=4' ], + 'tabstop8' : [ cp.get(cfg_sec, 'kb_tabstop8'), [ 'notes' ], 'View with tabstop=8' ], 'search' : [ cp.get(cfg_sec, 'kb_search'), [ 'titles' ], 'Search notes' ], 'clear_search' : [ cp.get(cfg_sec, 'kb_clear_search'), [ 'titles' ], 'Show all notes' ], 'note_pin' : [ cp.get(cfg_sec, 'kb_note_pin'), [ 'titles' ], 'Pin note' ], diff --git a/notes_db.py b/notes_db.py @@ -436,22 +436,24 @@ def sync_note(self, k, check_for_new): # only send required fields cn = copy.deepcopy(note) - del note['what_changed'] + if 'what_changed' in note: + del note['what_changed'] del cn['minversion'] del cn['createdate'] del cn['syncdate'] del cn['savedate'] - if 'deleted' not in cn['what_changed']: - del cn['deleted'] - if 'systemtags' not in cn['what_changed']: - del cn['systemtags'] - if 'tags' not in cn['what_changed']: - del cn['tags'] - if 'content' not in cn['what_changed']: - del cn['content'] - del cn['what_changed'] + if 'what_changed' in cn: + if 'deleted' not in cn['what_changed']: + del cn['deleted'] + if 'systemtags' not in cn['what_changed']: + del cn['systemtags'] + if 'tags' not in cn['what_changed']: + del cn['tags'] + if 'content' not in cn['what_changed']: + del cn['content'] + del cn['what_changed'] uret = self.simplenote.update_note(cn) #uret = self.simplenote.update_note(note) diff --git a/sncli.py b/sncli.py @@ -321,6 +321,27 @@ def frame_keypress(self, size, key): else: self.status_bar = self.config.get_config('status_bar') + elif key == self.config.get_keybind('create_note'): + if self.body_get().__class__ == view_titles.ViewTitles: + editor = self.config.get_config('editor') + if not editor and os.environ['EDITOR']: + editor = os.environ['EDITOR'] + if not editor: + self.status_message_set(u'No editor configured!') + return None + + tf = temp.tempfile_create(None) + try: + subprocess.check_call(editor + u' ' + temp.tempfile_name(tf), shell=True) + except Exception, e: + self.status_message_set(u'Editor error: ' + str(e)) + + content = ''.join(temp.tempfile_content(tf)) + if content: + self.status_message_set(u'New note created') + self.ndb.create_note(content) + temp.tempfile_delete(tf) + elif key == self.config.get_keybind('view_note'): # only when viewing the note list if self.body_get().__class__ == view_titles.ViewTitles: @@ -331,13 +352,11 @@ def frame_keypress(self, size, key): elif key == self.config.get_keybind('view_note_ext'): # only when viewing the note list if self.body_get().__class__ == view_titles.ViewTitles: - pager = None - if self.config.get_config('pager'): - pager = self.config.get_config('pager') + pager = self.config.get_config('pager') if not pager and os.environ['PAGER']: pager = os.environ['PAGER'] if not pager: - self.status_message(u'No pager configured!') + self.status_message_set(u'No pager configured!') return None tf = temp.tempfile_create(lb.note_list[lb.focus_position].note) diff --git a/temp.py b/temp.py @@ -20,3 +20,9 @@ def tempfile_name(tf): return tf.name return '' +def tempfile_content(tf): + lines = [] + for line in tf: + lines.append(line) + return lines +