def test_io(): with tempfile.NamedTemporaryFile() as f: c1 = configuration.Config(f.name) c1["a"] = 1 c1.write_list("b", ["foo", "bär"]) c1.save_to_disk() c2 = configuration.Config(f.name) assert c1 == c2 assert c2.read_list("b", []) == ["foo", "bär"]
def test_io(): with tempfile.NamedTemporaryFile() as f: c1 = configuration.Config(f.name) c1['a'] = 1 c1.write_list('b', ['foo', 'bär']) c1.save_to_disk() c2 = configuration.Config(f.name) assert c1 == c2 assert c2.read_list('b', []) == ['foo', 'bär']
def __init__(self): self.dirs = dirs user_config = configuration.Config(self.dirs.config_file) # Apply defaults where no custom values have been set for key, value in default_config.items(): if key not in user_config: user_config[key] = value self.config = user_config self.config.save_state() logging.info("Running in portable mode: %s" % self.dirs.portable) self.month = None self.date = None self.months = {} # The dir name is the title self.title = "" # show instructions at first start self.is_first_start = self.config.read("firstStart") self.config["firstStart"] = 0 logging.info("First Start: %s" % bool(self.is_first_start)) logging.info("RedNotebook version: %s" % info.version) logging.info(filesystem.get_platform_info()) self.actual_date = self.get_start_date() # Let components check if the MainWindow has been created self.frame = None self.frame = MainWindow(self) journal_path = self.get_journal_path() if not self.dirs.is_valid_journal_path(journal_path): logging.error( "Invalid directory: %s. Using default journal." % journal_path ) self.show_message( _("You cannot use this directory for your journal:") + " %s" % journal_path + ". " + _("Opening default journal."), error=True, ) journal_path = self.dirs.default_data_dir self.open_journal(journal_path) self.archiver = backup.Archiver(self) GObject.idle_add(self.archiver.check_last_backup_date) # Check for a new version if self.config.read("checkForNewVersion") == 1: utils.check_new_version(self, info.version, startup=True) # Automatically save the content after a period of time GObject.timeout_add_seconds(600, self.save_to_disk)
def test_changed(): with tempfile.NamedTemporaryFile() as f: c = configuration.Config(f.name) assert not c.changed() c["a"] = 1 assert c.changed() c.save_to_disk() assert not c.changed() c.read("a", "foo") assert not c.changed() c.read_list("a", "foo") assert not c.changed() c.read("b", "bar") assert c.changed() c.save_to_disk() assert not c.changed() c.read_list("c", "baz") assert c.changed()
def test_changed(): with tempfile.NamedTemporaryFile() as f: c = configuration.Config(f.name) assert not c.changed() c['a'] = 1 assert c.changed() c.save_to_disk() assert not c.changed() c.read('a', 'foo') assert not c.changed() c.read_list('a', 'foo') assert not c.changed() c.read('b', 'bar') assert c.changed() c.save_to_disk() assert not c.changed() c.read_list('c', 'baz') assert c.changed()
# define a Handler which writes messages to sys.stdout console = logging.StreamHandler(sys.stdout) console.setLevel(logging.DEBUG) # set a format which is simpler for console use formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s') # tell the handler to use this format console.setFormatter(formatter) # add the handler to the root logger root_logger.addHandler(console) logging.info('Writing log to file "%s"' % log_file) default_config_file = os.path.join(filesystem.app_dir, 'files', 'default.cfg') default_config = configuration.Config(default_config_file) dirs = filesystem.Filenames(default_config) setup_logging(dirs.log_file) # ------------------ end Enable logging ------------------------------- logging.info('System encoding: %s' % filesystem.ENCODING) logging.info('Language code: %s' % filesystem.LANGUAGE) try: from gi.repository import Gtk from gi.repository import GObject except (ImportError, AssertionError) as e: logging.error(e) logging.error('GTK+ not found. Please install it (gir1.2-gtk-3.0).')
def __init__(self): self.dirs = dirs user_config = configuration.Config(self.dirs.config_file) # Apply defaults where no custom values have been set for key, value in default_config.items(): if key not in user_config: user_config[key] = value self.config = user_config self.config.save_state() logging.info('Running in portable mode: %s' % self.dirs.portable) # Allow starting minimized to tray # When we start minimized we have to set the tray icon visible self.start_minimized = filesystem.HAS_TRAY and args.minimized if not filesystem.HAS_TRAY: self.config['closeToTray'] = 0 elif self.start_minimized: self.config['closeToTray'] = 1 self.month = None self.date = None self.months = {} # The dir name is the title self.title = '' # show instructions at first start self.is_first_start = self.config.read('firstStart', 1) self.config['firstStart'] = 0 logging.info('First Start: %s' % bool(self.is_first_start)) logging.info('RedNotebook version: %s' % info.version) logging.info(filesystem.get_platform_info()) utils.set_environment_variables(self.config) self.actual_date = self.get_start_date() # Let components check if the MainWindow has been created self.frame = None self.frame = MainWindow(self) journal_path = self.get_journal_path() if not self.dirs.is_valid_journal_path(journal_path): logging.error('Invalid directory: %s. Using default journal.' % journal_path) self.show_message( _('You cannot use this directory for your journal:') + ' %s' % journal_path + '. ' + _('Opening default journal.'), error=True) journal_path = self.dirs.default_data_dir self.open_journal(journal_path) self.archiver = backup.Archiver(self) #self.archiver.check_last_backup_date() # Check for a new version if self.config.read('checkForNewVersion', 0) == 1: utils.check_new_version(self, info.version, startup=True) # Automatically save the content after a period of time gobject.timeout_add_seconds(600, self.save_to_disk)