nncli

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

commit 1ce59e4da77816e22a1318478ecdd04e0e5b263d
parent e209a0a559b095dfb482b07f9aa6feb2ff3e6edf
Author: Eric Davis <edavis@insanum.com>
Date:   Wed, 25 Jun 2014 11:30:37 -0700

code reorg

Diffstat:
Aconfig.py | 192+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msncli.py | 293++++++++++++++-----------------------------------------------------------------
2 files changed, 241 insertions(+), 244 deletions(-)

diff --git a/config.py b/config.py @@ -0,0 +1,192 @@ + +import os, ConfigParser + +class Config: + + def __init__(self): + self.home = os.path.abspath(os.path.expanduser('~')) + defaults = \ + { + 'sn_username' : '', + 'sn_password' : '', + 'db_path' : os.path.join(self.home, '.sncli'), + 'search_mode' : 'gstyle', + 'search_tags' : '1', + 'sort_mode' : '1', + 'pinned_ontop' : '1', + 'tabstop' : '4', + 'format_strftime' : '%Y/%m/%d', + 'format_note_title' : '[%D] %F %N%>%T', + + 'kb_help' : 'h', + 'kb_quit' : 'q', + 'kb_down' : 'j', + 'kb_up' : 'k', + 'kb_page_down' : ' ', + 'kb_page_up' : 'b', + 'kb_half_page_down' : 'ctrl d', + 'kb_half_page_up' : 'ctrl u', + 'kb_bottom' : 'G', + 'kb_top' : 'g', + 'kb_view_note' : 'enter', + 'kb_view_log' : 'l', + 'kb_tabstop2' : '2', + 'kb_tabstop4' : '4', + 'kb_tabstop8' : '8', + + 'clr_default_fg' : 'default', + 'clr_default_bg' : 'default', + + 'clr_note_title_day_fg' : 'dark blue', + 'clr_note_title_day_bg' : 'default', + 'clr_note_title_day_focus_fg' : 'white', + 'clr_note_title_day_focus_bg' : 'default', + + 'clr_note_title_week_fg' : 'dark blue', + 'clr_note_title_week_bg' : 'default', + 'clr_note_title_week_focus_fg' : 'white', + 'clr_note_title_week_focus_bg' : 'default', + + 'clr_note_title_month_fg' : 'dark blue', + 'clr_note_title_month_bg' : 'default', + 'clr_note_title_month_focus_fg' : 'white', + 'clr_note_title_month_focus_bg' : 'default', + + 'clr_note_title_year_fg' : 'dark blue', + 'clr_note_title_year_bg' : 'default', + 'clr_note_title_year_focus_fg' : 'white', + 'clr_note_title_year_focus_bg' : 'default', + + 'clr_note_title_ancient_fg' : 'dark blue', + 'clr_note_title_ancient_bg' : 'default', + 'clr_note_title_ancient_focus_fg' : 'white', + 'clr_note_title_ancient_focus_bg' : 'default', + + 'clr_note_date_fg' : 'dark blue', + 'clr_note_date_bg' : 'default', + 'clr_note_date_focus_fg' : 'white', + 'clr_note_date_focus_bg' : 'default', + + 'clr_note_flags_fg' : 'dark blue', + 'clr_note_flags_bg' : 'default', + 'clr_note_flags_focus_fg' : 'white', + 'clr_note_flags_focus_bg' : 'default', + + 'clr_note_tags_fg' : 'dark blue', + 'clr_note_tags_bg' : 'default', + 'clr_note_tags_focus_fg' : 'white', + 'clr_note_tags_focus_bg' : 'default', + + 'clr_note_content_fg' : 'default', + 'clr_note_content_bg' : 'default', + 'clr_note_content_focus_fg' : 'white', + 'clr_note_content_focus_bg' : 'light red', + + 'clr_help_header_fg' : 'dark blue', + 'clr_help_header_bg' : 'default', + 'clr_help_key_fg' : 'default', + 'clr_help_key_bg' : 'default', + 'clr_help_config_fg' : 'dark green', + 'clr_help_config_bg' : 'default', + 'clr_help_descr_fg' : 'default', + 'clr_help_descr_bg' : 'default' + } + + cp = ConfigParser.SafeConfigParser(defaults) + self.configs_read = cp.read([os.path.join(self.home, '.snclirc')]) + + cfg_sec = 'sncli' + + if not cp.has_section(cfg_sec): + cp.add_section(cfg_sec) + self.ok = False + else: + self.ok = True + + self.sn_username = cp.get(cfg_sec, 'sn_username', raw=True) + self.sn_password = cp.get(cfg_sec, 'sn_password', raw=True) + self.db_path = cp.get(cfg_sec, 'db_path') + self.search_mode = cp.get(cfg_sec, 'search_mode') + self.search_tags = cp.getint(cfg_sec, 'search_tags') + self.sort_mode = cp.getint(cfg_sec, 'sort_mode') + self.pinned_ontop = cp.getint(cfg_sec, 'pinned_ontop') + self.tabstop = cp.getint(cfg_sec, 'tabstop') + self.format_strftime = cp.get(cfg_sec, 'format_strftime', raw=True) + self.format_note_title = cp.get(cfg_sec, 'format_note_title', raw=True) + + self.clr_default_fg = cp.get(cfg_sec, 'clr_default_fg') + self.clr_default_bg = cp.get(cfg_sec, 'clr_default_bg') + + self.clr_note_title_day_fg = cp.get(cfg_sec, 'clr_note_title_day_fg') + self.clr_note_title_day_bg = cp.get(cfg_sec, 'clr_note_title_day_bg') + self.clr_note_title_day_focus_fg = cp.get(cfg_sec, 'clr_note_title_day_focus_fg') + self.clr_note_title_day_focus_bg = cp.get(cfg_sec, 'clr_note_title_day_focus_bg') + + self.clr_note_title_week_fg = cp.get(cfg_sec, 'clr_note_title_week_fg') + self.clr_note_title_week_bg = cp.get(cfg_sec, 'clr_note_title_week_bg') + self.clr_note_title_week_focus_fg = cp.get(cfg_sec, 'clr_note_title_week_focus_fg') + self.clr_note_title_week_focus_bg = cp.get(cfg_sec, 'clr_note_title_week_focus_bg') + + self.clr_note_title_month_fg = cp.get(cfg_sec, 'clr_note_title_month_fg') + self.clr_note_title_month_bg = cp.get(cfg_sec, 'clr_note_title_month_bg') + self.clr_note_title_month_focus_fg = cp.get(cfg_sec, 'clr_note_title_month_focus_fg') + self.clr_note_title_month_focus_bg = cp.get(cfg_sec, 'clr_note_title_month_focus_bg') + + self.clr_note_title_year_fg = cp.get(cfg_sec, 'clr_note_title_year_fg') + self.clr_note_title_year_bg = cp.get(cfg_sec, 'clr_note_title_year_bg') + self.clr_note_title_year_focus_fg = cp.get(cfg_sec, 'clr_note_title_year_focus_fg') + self.clr_note_title_year_focus_bg = cp.get(cfg_sec, 'clr_note_title_year_focus_bg') + + self.clr_note_title_ancient_fg = cp.get(cfg_sec, 'clr_note_title_ancient_fg') + self.clr_note_title_ancient_bg = cp.get(cfg_sec, 'clr_note_title_ancient_bg') + self.clr_note_title_ancient_focus_fg = cp.get(cfg_sec, 'clr_note_title_ancient_focus_fg') + self.clr_note_title_ancient_focus_bg = cp.get(cfg_sec, 'clr_note_title_ancient_focus_bg') + + self.clr_note_date_fg = cp.get(cfg_sec, 'clr_note_date_fg') + self.clr_note_date_bg = cp.get(cfg_sec, 'clr_note_date_bg') + self.clr_note_date_focus_fg = cp.get(cfg_sec, 'clr_note_date_focus_fg') + self.clr_note_date_focus_bg = cp.get(cfg_sec, 'clr_note_date_focus_bg') + + self.clr_note_flags_fg = cp.get(cfg_sec, 'clr_note_flags_fg') + self.clr_note_flags_bg = cp.get(cfg_sec, 'clr_note_flags_bg') + self.clr_note_flags_focus_fg = cp.get(cfg_sec, 'clr_note_flags_focus_fg') + self.clr_note_flags_focus_bg = cp.get(cfg_sec, 'clr_note_flags_focus_bg') + + self.clr_note_tags_fg = cp.get(cfg_sec, 'clr_note_tags_fg') + self.clr_note_tags_bg = cp.get(cfg_sec, 'clr_note_tags_bg') + self.clr_note_tags_focus_fg = cp.get(cfg_sec, 'clr_note_tags_focus_fg') + self.clr_note_tags_focus_bg = cp.get(cfg_sec, 'clr_note_tags_focus_bg') + + self.clr_note_content_fg = cp.get(cfg_sec, 'clr_note_content_fg') + self.clr_note_content_bg = cp.get(cfg_sec, 'clr_note_content_bg') + self.clr_note_content_focus_fg = cp.get(cfg_sec, 'clr_note_content_focus_fg') + self.clr_note_content_focus_bg = cp.get(cfg_sec, 'clr_note_content_focus_bg') + + self.clr_help_header_fg = cp.get(cfg_sec, 'clr_help_header_fg') + self.clr_help_header_bg = cp.get(cfg_sec, 'clr_help_header_bg') + self.clr_help_key_fg = cp.get(cfg_sec, 'clr_help_key_fg') + self.clr_help_key_bg = cp.get(cfg_sec, 'clr_help_key_bg') + self.clr_help_config_fg = cp.get(cfg_sec, 'clr_help_config_fg') + self.clr_help_config_bg = cp.get(cfg_sec, 'clr_help_config_bg') + self.clr_help_descr_fg = cp.get(cfg_sec, 'clr_help_descr_fg') + self.clr_help_descr_bg = cp.get(cfg_sec, 'clr_help_descr_bg') + + self.keybinds = \ + { + 'help' : [ cp.get(cfg_sec, 'kb_help'), 'Help' ], + 'quit' : [ cp.get(cfg_sec, 'kb_quit'), 'Quit' ], + 'down' : [ cp.get(cfg_sec, 'kb_down'), 'Scroll down one line' ], + 'up' : [ cp.get(cfg_sec, 'kb_up'), 'Scroll up one line' ], + 'page_down' : [ cp.get(cfg_sec, 'kb_page_down'), 'Page down' ], + 'page_up' : [ cp.get(cfg_sec, 'kb_page_up'), 'Page up' ], + 'half_page_down' : [ cp.get(cfg_sec, 'kb_half_page_down'), 'Half page down' ], + 'half_page_up' : [ cp.get(cfg_sec, 'kb_half_page_up'), 'Half page up' ], + 'bottom' : [ cp.get(cfg_sec, 'kb_bottom'), 'Goto bottom' ], + 'top' : [ cp.get(cfg_sec, 'kb_top'), 'Goto top' ], + 'view_note' : [ cp.get(cfg_sec, 'kb_view_note'), 'View note' ], + 'view_log' : [ cp.get(cfg_sec, 'kb_view_log'), 'View log' ], + 'tabstop2' : [ cp.get(cfg_sec, 'kb_tabstop2'), 'View with tabstop=2' ], + 'tabstop4' : [ cp.get(cfg_sec, 'kb_tabstop4'), 'View with tabstop=4' ], + 'tabstop8' : [ cp.get(cfg_sec, 'kb_tabstop8'), 'View with tabstop=8' ] + } + diff --git a/sncli.py b/sncli.py @@ -1,201 +1,13 @@ #!/usr/bin/env python2 import os, sys, re, signal, time, datetime, logging -import copy, json, urwid, datetime, ConfigParser +import copy, json, urwid, datetime import utils +from config import Config from simplenote import Simplenote from notes_db import NotesDB, SyncError, ReadError, WriteError from logging.handlers import RotatingFileHandler -class Config: - - def __init__(self): - self.home = os.path.abspath(os.path.expanduser('~')) - defaults = \ - { - 'sn_username' : '', - 'sn_password' : '', - 'db_path' : os.path.join(self.home, '.sncli'), - 'search_mode' : 'gstyle', - 'search_tags' : '1', - 'sort_mode' : '1', - 'pinned_ontop' : '1', - 'tabstop' : '4', - 'format_strftime' : '%Y/%m/%d', - 'format_note_title' : '[%D] %F %N%>%T', - - 'kb_help' : 'h', - 'kb_quit' : 'q', - 'kb_down' : 'j', - 'kb_up' : 'k', - 'kb_page_down' : ' ', - 'kb_page_up' : 'b', - 'kb_half_page_down' : 'ctrl d', - 'kb_half_page_up' : 'ctrl u', - 'kb_bottom' : 'G', - 'kb_top' : 'g', - 'kb_view_note' : 'enter', - 'kb_view_log' : 'l', - 'kb_tabstop2' : '2', - 'kb_tabstop4' : '4', - 'kb_tabstop8' : '8', - - 'clr_default_fg' : 'default', - 'clr_default_bg' : 'default', - - 'clr_note_title_day_fg' : 'dark blue', - 'clr_note_title_day_bg' : 'default', - 'clr_note_title_day_focus_fg' : 'white', - 'clr_note_title_day_focus_bg' : 'default', - - 'clr_note_title_week_fg' : 'dark blue', - 'clr_note_title_week_bg' : 'default', - 'clr_note_title_week_focus_fg' : 'white', - 'clr_note_title_week_focus_bg' : 'default', - - 'clr_note_title_month_fg' : 'dark blue', - 'clr_note_title_month_bg' : 'default', - 'clr_note_title_month_focus_fg' : 'white', - 'clr_note_title_month_focus_bg' : 'default', - - 'clr_note_title_year_fg' : 'dark blue', - 'clr_note_title_year_bg' : 'default', - 'clr_note_title_year_focus_fg' : 'white', - 'clr_note_title_year_focus_bg' : 'default', - - 'clr_note_title_ancient_fg' : 'dark blue', - 'clr_note_title_ancient_bg' : 'default', - 'clr_note_title_ancient_focus_fg' : 'white', - 'clr_note_title_ancient_focus_bg' : 'default', - - 'clr_note_date_fg' : 'dark blue', - 'clr_note_date_bg' : 'default', - 'clr_note_date_focus_fg' : 'white', - 'clr_note_date_focus_bg' : 'default', - - 'clr_note_flags_fg' : 'dark blue', - 'clr_note_flags_bg' : 'default', - 'clr_note_flags_focus_fg' : 'white', - 'clr_note_flags_focus_bg' : 'default', - - 'clr_note_tags_fg' : 'dark blue', - 'clr_note_tags_bg' : 'default', - 'clr_note_tags_focus_fg' : 'white', - 'clr_note_tags_focus_bg' : 'default', - - 'clr_note_content_fg' : 'default', - 'clr_note_content_bg' : 'default', - 'clr_note_content_focus_fg' : 'white', - 'clr_note_content_focus_bg' : 'light red', - - 'clr_help_header_fg' : 'dark blue', - 'clr_help_header_bg' : 'default', - 'clr_help_key_fg' : 'default', - 'clr_help_key_bg' : 'default', - 'clr_help_config_fg' : 'dark green', - 'clr_help_config_bg' : 'default', - 'clr_help_descr_fg' : 'default', - 'clr_help_descr_bg' : 'default' - } - - cp = ConfigParser.SafeConfigParser(defaults) - self.configs_read = cp.read([os.path.join(self.home, '.snclirc')]) - - cfg_sec = 'sncli' - - if not cp.has_section(cfg_sec): - cp.add_section(cfg_sec) - self.ok = False - else: - self.ok = True - - self.sn_username = cp.get(cfg_sec, 'sn_username', raw=True) - self.sn_password = cp.get(cfg_sec, 'sn_password', raw=True) - self.db_path = cp.get(cfg_sec, 'db_path') - self.search_mode = cp.get(cfg_sec, 'search_mode') - self.search_tags = cp.getint(cfg_sec, 'search_tags') - self.sort_mode = cp.getint(cfg_sec, 'sort_mode') - self.pinned_ontop = cp.getint(cfg_sec, 'pinned_ontop') - self.tabstop = cp.getint(cfg_sec, 'tabstop') - self.format_strftime = cp.get(cfg_sec, 'format_strftime', raw=True) - self.format_note_title = cp.get(cfg_sec, 'format_note_title', raw=True) - - self.clr_default_fg = cp.get(cfg_sec, 'clr_default_fg') - self.clr_default_bg = cp.get(cfg_sec, 'clr_default_bg') - - self.clr_note_title_day_fg = cp.get(cfg_sec, 'clr_note_title_day_fg') - self.clr_note_title_day_bg = cp.get(cfg_sec, 'clr_note_title_day_bg') - self.clr_note_title_day_focus_fg = cp.get(cfg_sec, 'clr_note_title_day_focus_fg') - self.clr_note_title_day_focus_bg = cp.get(cfg_sec, 'clr_note_title_day_focus_bg') - - self.clr_note_title_week_fg = cp.get(cfg_sec, 'clr_note_title_week_fg') - self.clr_note_title_week_bg = cp.get(cfg_sec, 'clr_note_title_week_bg') - self.clr_note_title_week_focus_fg = cp.get(cfg_sec, 'clr_note_title_week_focus_fg') - self.clr_note_title_week_focus_bg = cp.get(cfg_sec, 'clr_note_title_week_focus_bg') - - self.clr_note_title_month_fg = cp.get(cfg_sec, 'clr_note_title_month_fg') - self.clr_note_title_month_bg = cp.get(cfg_sec, 'clr_note_title_month_bg') - self.clr_note_title_month_focus_fg = cp.get(cfg_sec, 'clr_note_title_month_focus_fg') - self.clr_note_title_month_focus_bg = cp.get(cfg_sec, 'clr_note_title_month_focus_bg') - - self.clr_note_title_year_fg = cp.get(cfg_sec, 'clr_note_title_year_fg') - self.clr_note_title_year_bg = cp.get(cfg_sec, 'clr_note_title_year_bg') - self.clr_note_title_year_focus_fg = cp.get(cfg_sec, 'clr_note_title_year_focus_fg') - self.clr_note_title_year_focus_bg = cp.get(cfg_sec, 'clr_note_title_year_focus_bg') - - self.clr_note_title_ancient_fg = cp.get(cfg_sec, 'clr_note_title_ancient_fg') - self.clr_note_title_ancient_bg = cp.get(cfg_sec, 'clr_note_title_ancient_bg') - self.clr_note_title_ancient_focus_fg = cp.get(cfg_sec, 'clr_note_title_ancient_focus_fg') - self.clr_note_title_ancient_focus_bg = cp.get(cfg_sec, 'clr_note_title_ancient_focus_bg') - - self.clr_note_date_fg = cp.get(cfg_sec, 'clr_note_date_fg') - self.clr_note_date_bg = cp.get(cfg_sec, 'clr_note_date_bg') - self.clr_note_date_focus_fg = cp.get(cfg_sec, 'clr_note_date_focus_fg') - self.clr_note_date_focus_bg = cp.get(cfg_sec, 'clr_note_date_focus_bg') - - self.clr_note_flags_fg = cp.get(cfg_sec, 'clr_note_flags_fg') - self.clr_note_flags_bg = cp.get(cfg_sec, 'clr_note_flags_bg') - self.clr_note_flags_focus_fg = cp.get(cfg_sec, 'clr_note_flags_focus_fg') - self.clr_note_flags_focus_bg = cp.get(cfg_sec, 'clr_note_flags_focus_bg') - - self.clr_note_tags_fg = cp.get(cfg_sec, 'clr_note_tags_fg') - self.clr_note_tags_bg = cp.get(cfg_sec, 'clr_note_tags_bg') - self.clr_note_tags_focus_fg = cp.get(cfg_sec, 'clr_note_tags_focus_fg') - self.clr_note_tags_focus_bg = cp.get(cfg_sec, 'clr_note_tags_focus_bg') - - self.clr_note_content_fg = cp.get(cfg_sec, 'clr_note_content_fg') - self.clr_note_content_bg = cp.get(cfg_sec, 'clr_note_content_bg') - self.clr_note_content_focus_fg = cp.get(cfg_sec, 'clr_note_content_focus_fg') - self.clr_note_content_focus_bg = cp.get(cfg_sec, 'clr_note_content_focus_bg') - - self.clr_help_header_fg = cp.get(cfg_sec, 'clr_help_header_fg') - self.clr_help_header_bg = cp.get(cfg_sec, 'clr_help_header_bg') - self.clr_help_key_fg = cp.get(cfg_sec, 'clr_help_key_fg') - self.clr_help_key_bg = cp.get(cfg_sec, 'clr_help_key_bg') - self.clr_help_config_fg = cp.get(cfg_sec, 'clr_help_config_fg') - self.clr_help_config_bg = cp.get(cfg_sec, 'clr_help_config_bg') - self.clr_help_descr_fg = cp.get(cfg_sec, 'clr_help_descr_fg') - self.clr_help_descr_bg = cp.get(cfg_sec, 'clr_help_descr_bg') - - self.keybinds = \ - { - 'help' : [ cp.get(cfg_sec, 'kb_help'), 'Help' ], - 'quit' : [ cp.get(cfg_sec, 'kb_quit'), 'Quit' ], - 'down' : [ cp.get(cfg_sec, 'kb_down'), 'Scroll down one line' ], - 'up' : [ cp.get(cfg_sec, 'kb_up'), 'Scroll up one line' ], - 'page_down' : [ cp.get(cfg_sec, 'kb_page_down'), 'Page down' ], - 'page_up' : [ cp.get(cfg_sec, 'kb_page_up'), 'Page up' ], - 'half_page_down' : [ cp.get(cfg_sec, 'kb_half_page_down'), 'Half page down' ], - 'half_page_up' : [ cp.get(cfg_sec, 'kb_half_page_up'), 'Half page up' ], - 'bottom' : [ cp.get(cfg_sec, 'kb_bottom'), 'Goto bottom' ], - 'top' : [ cp.get(cfg_sec, 'kb_top'), 'Goto top' ], - 'view_note' : [ cp.get(cfg_sec, 'kb_view_note'), 'View note' ], - 'view_log' : [ cp.get(cfg_sec, 'kb_view_log'), 'View log' ], - 'tabstop2' : [ cp.get(cfg_sec, 'kb_tabstop2'), 'View with tabstop=2' ], - 'tabstop4' : [ cp.get(cfg_sec, 'kb_tabstop4'), 'View with tabstop=4' ], - 'tabstop8' : [ cp.get(cfg_sec, 'kb_tabstop8'), 'View with tabstop=8' ] - } - class sncli: def __init__(self): @@ -223,8 +35,8 @@ def __init__(self): self.last_view = [] # XXX - #self.all_notes, match_regex, self.all_notes_cnt = self.ndb.filter_notes() - #return + self.all_notes, match_regex, self.all_notes_cnt = self.ndb.filter_notes() + return self.ndb.add_observer('synced:note', self.observer_notes_db_synced_note) self.ndb.add_observer('change:note-status', self.observer_notes_db_change_note_status) @@ -233,7 +45,49 @@ def __init__(self): self.all_notes, match_regex, self.all_notes_cnt = self.ndb.filter_notes() - def do_it(self): + def sync_full(self): + try: + sync_from_server_errors = self.ndb.sync_full() + except Exception, e: + print e + exit(1) + else: + if sync_from_server_errors > 0: + print('Error syncing %d notes from server. Please check sncli.log for details.' % (sync_from_server_errors)) + + def observer_notes_db_change_note_status(self, ndb, evt_type, evt): + logging.debug(evt.msg) + # XXX set status text someplace visible + skey = self.get_selected_note_key() + if skey == evt.key: + print self.ndb.get_note_status(skey) + + def observer_notes_db_sync_full(self, ndb, evt_type, evt): + logging.debug(evt.msg) + # XXX set status text someplace visible + print evt.msg + + def observer_notes_db_synced_note(self, ndb, evt_type, evt): + """This observer gets called only when a note returns from + a sync that's more recent than our most recent mod to that note. + """ + + selected_note_o = self.notes_list_model.list[self.selected_note_idx] + print "observer_notes_db_synced_note: " + evt.msg + + # if the note synced back matches our currently selected note, + # we overwrite. + + # XXX + #if selected_note_o.key == evt.lkey: + # if selected_note_o.note['content'] != evt.old_note['content']: + # self.view.mute_note_data_changes() + # # in this case, we want to keep the user's undo buffer so that they + # # can undo synced back changes if they would want to. + # self.view.set_note_data(selected_note_o.note, reset_undo=False) + # self.view.unmute_note_data_changes() + + def ba_bam_what(self): def list_get_note_titles(): lines = [] @@ -564,64 +418,15 @@ def keypress(self, size, key): handle_mouse=False) sncli_loop.run() - def sync_full(self): - try: - sync_from_server_errors = self.ndb.sync_full() - except Exception, e: - print e - exit(1) - else: - if sync_from_server_errors > 0: - print('Error syncing %d notes from server. Please check sncli.log for details.' % (sync_from_server_errors)) - - def set_note_status(self, msg): - print(msg) - - def observer_notes_db_change_note_status(self, ndb, evt_type, evt): - skey = self.get_selected_note_key() - if skey == evt.key: - # XXX - #self.view.set_note_status(self.ndb.get_note_status(skey)) - self.set_note_status(self.ndb.get_note_status(skey)) - - def set_status_text(self, msg): - print(msg) - - def observer_notes_db_sync_full(self, ndb, evt_type, evt): - logging.debug(evt.msg) - # XXX - #self.view.set_status_text(evt.msg) - self.set_status_text(evt.msg) - - def observer_notes_db_synced_note(self, ndb, evt_type, evt): - """This observer gets called only when a note returns from - a sync that's more recent than our most recent mod to that note. - """ - - selected_note_o = self.notes_list_model.list[self.selected_note_idx] - print "observer_notes_db_synced_note: " + evt.msg - - # if the note synced back matches our currently selected note, - # we overwrite. - - # XXX - #if selected_note_o.key == evt.lkey: - # if selected_note_o.note['content'] != evt.old_note['content']: - # self.view.mute_note_data_changes() - # # in this case, we want to keep the user's undo buffer so that they - # # can undo synced back changes if they would want to. - # self.view.set_note_data(selected_note_o.note, reset_undo=False) - # self.view.unmute_note_data_changes() - def SIGINT_handler(signum, frame): - print('Signal caught, bye!') + print('\nSignal caught, bye!') sys.exit(1) signal.signal(signal.SIGINT, SIGINT_handler) def main(): - sncli().do_it() + sncli().ba_bam_what() if __name__ == '__main__': main()