nncli

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

commit 40acfecb2c6aaea41de64ee7e3436bb29aea0806
parent 8fd172052fd5a050f93091bb4023471f01d9aff6
Author: Eric Davis <edavis@insanum.com>
Date:   Fri, 11 Jul 2014 18:10:20 -0700

added more note info to the cli dump header

Diffstat:
Msncli.py | 64+++++++++++++++++++++++++++++++++++++---------------------------
Mutils.py | 7+++++++
Mview_note.py | 16+++++++---------
Mview_titles.py | 13+++----------
4 files changed, 54 insertions(+), 46 deletions(-)

diff --git a/sncli.py b/sncli.py @@ -777,28 +777,38 @@ def cli_list_notes(self, search_string): u' [' + flags + u'] ' + \ utils.get_note_title(n.note) - def cli_dump_notes(self, search_string, key=None): + def cli_dump_notes(self, search_string): - sep = u'+' + u'-'*39 + u'+' - def dump_note(note): - print sep - print u'| Key: ' + note['key'] + u' |' - print sep - print note['content'] + note_list, match_regex, all_notes_cnt = \ + self.ndb.filter_notes(search_string) + for n in note_list: + self.cli_note_dump(n.key) - if not key: - note_list, match_regex, all_notes_cnt = \ - self.ndb.filter_notes(search_string) - for n in note_list: - dump_note(n.note) - else: - note = self.ndb.get_note(key) - if note: - dump_note(note) - else: - self.log(u'ERROR: Key does not exist') + def cli_note_dump(self, key): - def cli_create_note(self, from_stdin): + note = self.ndb.get_note(key) + if not note: + self.log(u'ERROR: Key does not exist') + return + + w = 50 + sep = u'+' + u'-'*(w+2) + u'+' + t = time.localtime(float(note['modifydate'])) + mod_time = time.strftime('%a, %d %b %Y %H:%M:%S', t) + title = utils.get_note_title(note) + flags = utils.get_note_flags(note) + tags = utils.get_note_tags(note) + + print sep + print (u'| {:<' + str(w) + u'} |').format((u'Title: ' + title)[:w]) + print (u'| {:<' + str(w) + u'} |').format((u' Key: ' + note['key'])[:w]) + print (u'| {:<' + str(w) + u'} |').format((u' Date: ' + mod_time)[:w]) + print (u'| {:<' + str(w) + u'} |').format((u' Tags: ' + tags)[:w]) + print (u'| {:<' + str(w) + u'} |').format((u'Flags: [' + flags + u']')[:w]) + print sep + print note['content'] + + def cli_note_create(self, from_stdin): def save_new_note(content): if content and content != u'\n': @@ -829,16 +839,16 @@ def save_new_note(content): temp.tempfile_delete(tf) - def cli_edit_note(self, key): - - editor = self.get_editor() - if not editor: return None + def cli_note_edit(self, key): note = self.ndb.get_note(key) if not note: self.log(u'ERROR: Key does not exist') return + editor = self.get_editor() + if not editor: return None + md5_old = md5.new(note['content']).digest() tf = temp.tempfile_create(note) @@ -968,7 +978,7 @@ def sncli_start(sync, verbose): sn = sncli_start(sync, verbose) if key: - sn.cli_dump_notes(None, key=key) + sn.cli_note_dump(key) else: sn.cli_dump_notes(' '.join(args[1:])) @@ -976,10 +986,10 @@ def sncli_start(sync, verbose): if len(args) == 1: sn = sncli_start(sync, verbose) - sn.cli_create_note(False) + sn.cli_note_create(False) elif len(args) == 2 and args[1] == '-': sn = sncli_start(sync, verbose) - sn.cli_create_note(True) + sn.cli_note_create(True) else: usage() @@ -989,7 +999,7 @@ def sncli_start(sync, verbose): usage() sn = sncli_start(sync, verbose) - sn.cli_edit_note(key) + sn.cli_note_edit(key) elif args[0] == 'trash' or args[0] == 'untrash': diff --git a/utils.py b/utils.py @@ -14,6 +14,13 @@ def generate_random_key(): """ return '%030x' % (random.randrange(256**15),) +def get_note_tags(note): + tags = '%s' % ','.join(note['tags']) + if note['deleted']: + if tags: tags += u',trash' + else: tags = u'trash' + return tags + def get_note_flags(note): flags = '' flags += u'T' if note['deleted'] else u' ' diff --git a/view_note.py b/view_note.py @@ -45,14 +45,14 @@ def get_status_bar(self): total = len(self.body.positions()) t = time.localtime(float(self.note['modifydate'])) - mod_time = time.strftime('%a, %d %b %Y %H:%M:%S', t) - tags = '%s' % ','.join(self.note['tags']) - if self.note['deleted']: - if tags: tags += u',trash' - else: tags = u'trash' + mod_time = time.strftime(u'Date: %a, %d %b %Y %H:%M:%S', t) + title = utils.get_note_title(self.note) + flags = utils.get_note_flags(self.note) + tags = utils.get_note_tags(self.note) + status_title = \ urwid.AttrMap(urwid.Text(u'Title: ' + - utils.get_note_title(self.note), + title, wrap='clip'), 'status_bar') status_key_index = \ @@ -62,11 +62,9 @@ def get_status_bar(self): str(total)), 'status_bar')) status_date = \ - urwid.AttrMap(urwid.Text(u'Date: ' + - mod_time, + urwid.AttrMap(urwid.Text(mod_time, wrap='clip'), 'status_bar') - flags = utils.get_note_flags(self.note) status_tags_flags = \ ('pack', urwid.AttrMap(urwid.Text(u'[' + tags + u'] [' + flags + u']'), 'status_bar')) diff --git a/view_titles.py b/view_titles.py @@ -43,18 +43,11 @@ def format_title(self, note): %N -- note title """ - title = utils.get_note_title(note) - flags = utils.get_note_flags(note) - - # get the note tags - tags = '%s' % ','.join(note['tags']) - if note['deleted']: - if tags: tags += u',trash' - else: tags = u'trash' - - # format the note modification date t = time.localtime(float(note['modifydate'])) mod_time = time.strftime(self.config.get_config('format_strftime'), t) + title = utils.get_note_title(note) + flags = utils.get_note_flags(note) + tags = utils.get_note_tags(note) # get the age of the note dt = datetime.datetime.fromtimestamp(time.mktime(t))