def __init__(self, do_server_sync, verbose=False, config_file=None): self.config = Config(config_file) self.do_server_sync = do_server_sync self.verbose = verbose self.do_gui = False force_full_sync = False if not os.path.exists(self.config.get_config('db_path')): os.mkdir(self.config.get_config('db_path')) force_full_sync = True # configure the logging module self.logfile = os.path.join(self.config.get_config('db_path'), 'sncli.log') self.loghandler = RotatingFileHandler(self.logfile, maxBytes=100000, backupCount=1) self.loghandler.setLevel(logging.DEBUG) self.loghandler.setFormatter( logging.Formatter(fmt='%(asctime)s [%(levelname)s] %(message)s')) self.logger = logging.getLogger() self.logger.setLevel(logging.DEBUG) self.logger.addHandler(self.loghandler) self.config.logfile = self.logfile logging.debug('sncli logging initialized') self.logs = [] try: self.ndb = NotesDB(self.config, self.log, self.gui_update_view) except Exception, e: self.log(str(e)) sys.exit(1)
def __init__(self, config): # should probably also look in $HOME self.config = config self.config.app_version = VERSION # configure logging module ############################# # first create db directory if it doesn't exist yet. if not os.path.exists(self.config.db_path): os.mkdir(self.config.db_path) log_filename = os.path.join(self.config.db_path, 'nvpy.log') # file will get nuked when it reaches 100kB lhandler = RotatingFileHandler(log_filename, maxBytes=100000, backupCount=1) lhandler.setLevel(logging.DEBUG) lhandler.setFormatter( logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(message)s')) # we get the root logger and configure it logger = logging.getLogger() if self.config.debug == 1: logger.setLevel(logging.DEBUG) logger.addHandler(lhandler) # this will go to the root logger logging.debug('nvpy logging initialized') logging.debug('config read from %s' % (str(self.config.files_read), )) if self.config.sn_username == '': self.config.simplenote_sync = 0 css = self.config.rest_css_path if css: if css.startswith("~/"): # On Mac, paths that start with '~/' aren't found by path.exists css = css.replace("~", os.path.abspath(os.path.expanduser('~')), 1) self.config.rest_css_path = css if not os.path.exists(css): # Couldn't find the user-defined css file. Use docutils css instead. self.config.rest_css_path = None self.notes_list_model = NotesListModel() # create the interface self.view = view.View(self.config, self.notes_list_model) # read our database of notes into memory # and sync with simplenote. try: self.notes_db = NotesDB(self.config) except ReadError, e: emsg = "Please check nvpy.log.\n" + str(e) self.view.show_error('Sync error', emsg) exit(1)
def __init__(self): # setup appdir if hasattr(sys, 'frozen') and sys.frozen: self.appdir, _ = os.path.split(sys.executable) else: dirname = os.path.dirname(__file__) if dirname and dirname != os.curdir: self.appdir = dirname else: self.appdir = os.getcwd() # make sure it's the full path self.appdir = os.path.abspath(self.appdir) # should probably also look in $HOME self.config = Config(self.appdir) self.config.app_version = self.get_version() # configure logging module ############################# # first create db directory if it doesn't exist yet. if not os.path.exists(self.config.db_path): os.mkdir(self.config.db_path) log_filename = os.path.join(self.config.db_path, 'nvpy.log') # file will get nuked when it reaches 100kB lhandler = RotatingFileHandler(log_filename, maxBytes=100000) lhandler.setLevel(logging.DEBUG) lhandler.setFormatter( logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(message)s')) # we get the root logger and configure it logger = logging.getLogger() logger.setLevel(logging.DEBUG) logger.addHandler(lhandler) # this will go to the root logger logging.debug('nvpy logging initialized') # read our database of notes into memory # and sync with simplenote. c = self.config notes_db_config = KeyValueObject(db_path=c.db_path, sn_username=c.sn_username, sn_password=c.sn_password, sort_mode=c.sort_mode) self.notes_db = NotesDB(notes_db_config) self.notes_db.add_observer('synced:note', self.observer_notes_db_synced_note) self.notes_db.add_observer('change:note-status', self.observer_notes_db_change_note_status) self.notes_db.add_observer('progress:sync_full', self.observer_notes_db_sync_full) self.notes_list_model = NotesListModel() # create the interface self.view = view.View(self.config, self.notes_list_model) # we want to be notified when the user does stuff self.view.add_observer('click:notelink', self.observer_view_click_notelink) self.view.add_observer('delete:note', self.observer_view_delete_note) self.view.add_observer('select:note', self.observer_view_select_note) self.view.add_observer('change:entry', self.observer_view_change_entry) self.view.add_observer('change:text', self.observer_view_change_text) self.view.add_observer('create:note', self.observer_view_create_note) self.view.add_observer('keep:house', self.observer_view_keep_house) self.view.add_observer('command:markdown', self.observer_view_markdown) self.view.add_observer('command:rest', self.observer_view_rest) self.view.add_observer('command:sync_full', lambda v, et, e: self.sync_full()) self.view.add_observer('command:sync_current_note', self.observer_view_sync_current_note) self.view.add_observer('close', self.observer_view_close) # nn is a list of (key, note) objects nn = self.notes_db.filter_notes() # this will trigger the list_change event self.notes_list_model.set_list(nn) # we'll use this to keep track of the currently selected note # we only use idx, because key could change from right under us. self.selected_note_idx = -1 self.view.select_note(0) # perform full sync with server, and refresh notes list if successful self.sync_full()
def __init__(self, config): SubjectMixin.MAIN_THREAD = threading.current_thread() # should probably also look in $HOME self.config = config self.config.app_version = VERSION # configure logging module ############################# # first create db directory if it doesn't exist yet. if not os.path.exists(self.config.db_path): os.mkdir(self.config.db_path) log_filename = os.path.join(self.config.db_path, 'nvpy.log') # file will get nuked when it reaches 100kB lhandler = RotatingFileHandler(log_filename, maxBytes=100000, backupCount=1) lhandler.setLevel(logging.DEBUG) lhandler.setFormatter(logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(message)s')) # we get the root logger and configure it logger = logging.getLogger() if self.config.debug == 1: logger.setLevel(logging.DEBUG) logger.addHandler(lhandler) # this will go to the root logger logging.debug('nvpy logging initialized') logging.debug('config read from %s' % (str(self.config.files_read),)) if self.config.sn_username == '': self.config.simplenote_sync = 0 rst_css = self.config.rest_css_path if rst_css: if rst_css.startswith("~/"): # On Mac, paths that start with '~/' aren't found by path.exists rst_css = rst_css.replace( "~", os.path.abspath(os.path.expanduser('~')), 1) self.config.rest_css_path = rst_css if not os.path.exists(rst_css): # Couldn't find the user-defined css file. Use docutils css instead. self.config.rest_css_path = None md_css = self.config.md_css_path if md_css: if md_css.startswith("~/"): # On Mac, paths that start with '~/' aren't found by path.exists md_css = md_css.replace( "~", os.path.abspath(os.path.expanduser('~')), 1) self.config.md_css_path = md_css if not os.path.exists(md_css): # Couldn't find the user-defined css file. # Do not use css styling for markdown. self.config.md_css_path = None self.notes_list_model = NotesListModel() # create the interface self.view = view.View(self.config, self.notes_list_model) # read our database of notes into memory # and sync with simplenote. try: self.notes_db = NotesDB(self.config) except ReadError as e: emsg = "Please check nvpy.log.\n" + str(e) self.view.show_error('Sync error', emsg) exit(1) self.notes_db.add_observer('synced:note', self.observer_notes_db_synced_note) self.notes_db.add_observer('change:note-status', self.observer_notes_db_change_note_status) if self.config.simplenote_sync: self.notes_db.add_observer('progress:sync_full', self.observer_notes_db_sync_full) self.notes_db.add_observer('error:sync_full', self.observer_notes_db_error_sync_full) self.notes_db.add_observer('complete:sync_full', self.observer_notes_db_complete_sync_full) # we want to be notified when the user does stuff self.view.add_observer('click:notelink', self.observer_view_click_notelink) self.view.add_observer('delete:note', self.observer_view_delete_note) self.view.add_observer('select:note', self.observer_view_select_note) self.view.add_observer('change:entry', self.observer_view_change_entry) self.view.add_observer('change:text', self.observer_view_change_text) self.view.add_observer('change:pinned', self.observer_view_change_pinned) self.view.add_observer('create:note', self.observer_view_create_note) self.view.add_observer('keep:house', self.observer_view_keep_house) self.view.add_observer('command:markdown', self.observer_view_markdown) self.view.add_observer('command:rest', self.observer_view_rest) self.view.add_observer('delete:tag', self.observer_view_delete_tag) self.view.add_observer('add:tag', self.observer_view_add_tag) if self.config.simplenote_sync: self.view.add_observer('command:sync_full', lambda v, et, e: self.sync_full()) self.view.add_observer('command:sync_current_note', self.observer_view_sync_current_note) self.view.add_observer('close', self.observer_view_close) # setup UI to reflect our search mode and case sensitivity self.view.set_cs(self.config.case_sensitive, silent=True) self.view.set_search_mode(self.config.search_mode, silent=True) self.view.add_observer('change:cs', self.observer_view_change_cs) self.view.add_observer('change:search_mode', self.observer_view_change_search_mode) # nn is a list of (key, note) objects nn, match_regexp, active_notes = self.notes_db.filter_notes() # this will trigger the list_change event self.notes_list_model.set_list(nn) self.notes_list_model.match_regexp = match_regexp self.view.set_note_tally(len(nn), active_notes, len(self.notes_db.notes)) # we'll use this to keep track of the currently selected note # we only use idx, because key could change from right under us. self.selected_note_key = None self.view.select_note(0) if self.config.simplenote_sync: self.view.after(0, self.sync_full)
def __init__(self): self.db = NotesDB()