def load(self, session, filename=None): self._mkworkdir(session) self.index = None self.reset(rules=False, data=True) filename = filename or self.conffile lines = [] try: fd = open(filename, 'rb') try: decrypt_and_parse_lines(fd, lambda l: lines.append(l), None) except ValueError: pass fd.close() except IOError: pass # Discover plugins and update the config rule to match from mailpile.plugins import PluginManager self.plugins = PluginManager(config=self, builtin=True).discover([ os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'plugins'), os.path.join(self.workdir, 'plugins') ]) self.sys.plugins.rules['_any'][1] = self.plugins.available() # Parse once (silently), to figure out which plugins to load... self.parse_config(None, '\n'.join(lines), source=filename) if len(self.sys.plugins) == 0: self.sys.plugins.extend(self.plugins.DEFAULT) self.load_plugins(session) # Now all the plugins are loaded, reset and parse again! self.reset_rules_from_source() self.parse_config(session, '\n'.join(lines), source=filename) # Open event log self.event_log = EventLog( self.data_directory('event_log', mode='rw', mkdir=True), # FIXME: Disbled encryption for now lambda: False and self.prefs.obfuscate_index).load() # Enable translations translation = self.get_i18n_translation(session) # Configure jinja2 self.jinja_env = Environment( loader=MailpileJinjaLoader(self), autoescape=True, trim_blocks=True, extensions=[ 'jinja2.ext.i18n', 'jinja2.ext.with_', 'jinja2.ext.do', 'mailpile.jinjaextensions.MailpileCommand' ]) self.jinja_env.install_gettext_translations(translation, newstyle=True) # Load VCards self.vcards = VCardStore( self, self.data_directory('vcards', mode='rw', mkdir=True))
def load(self, session, filename=None): self._mkworkdir(session) self.index = None self.reset(rules=False, data=True) try: ocfg = os.path.join(self.workdir, 'config.rc') ocl = OldConfigLoader(filename=ocfg) if ocl.export(self) and session: session.ui.warning(('WARNING: Imported old config from %s' ) % ocfg) elif ocl.lines and session: session.ui.warning(('WARNING: Failed to import config from %s' ) % ocfg) except: import traceback traceback.print_exc() filename = filename or self.conffile lines = [] try: fd = open(filename, 'rb') try: decrypt_and_parse_lines(fd, lambda l: lines.append(l)) except ValueError: pass fd.close() except IOError: pass self.parse_config(session, '\n'.join(lines), source=filename) self.vcards = VCardStore(self, self.data_directory('vcards')) self.vcards.load_vcards(session)
def load(self, session, filename=None): self._mkworkdir(session) self.index = None self.reset(rules=False, data=True) filename = filename or self.conffile lines = [] try: fd = open(filename, 'rb') try: decrypt_and_parse_lines(fd, lambda l: lines.append(l), None) except ValueError: pass fd.close() except IOError: pass # Discover plugins and update the config rule import mailpile.plugins pds = [os.path.join(self.workdir, 'plugins')] pds = mailpile.plugins.Discover(pds) self.sys.plugins.rules['_any'][1] = pds # Parse once (silently), to figure out which plugins to load... self.parse_config(None, '\n'.join(lines), source=filename) if len(self.sys.plugins) == 0: self.sys.plugins.extend(mailpile.plugins.__all__) self.load_plugins(session) # Now all the plugins are loaded, reset and parse again! self.set_rules(self._rules_source) self.sys.plugins.rules['_any'][1] = pds self.parse_config(session, '\n'.join(lines), source=filename) # Open event log self.event_log = EventLog( self.data_directory('event_log', mode='rw', mkdir=True), # FIXME: Disbled encryption for now lambda: False and self.prefs.obfuscate_index).load() # Enable translations self.get_i18n_translation(session) # Load VCards self.vcards = VCardStore( self, self.data_directory('vcards', mode='rw', mkdir=True))