def get_items(self): fpath = config.get_config_file("Bookmarks", package="chromium/Default") # If there is no chromium bookmarks file, look for a google-chrome one if not fpath: fpath = config.get_config_file("Bookmarks", package="google-chrome/Default") if fpath: try: return self._get_chromium_items(fpath) except Exception, exc: self.output_error(exc)
def get_items(self): try: dbfile = config.get_config_file("medialib.db", package="xmms2") songs = list(get_xmms2_songs(dbfile)) except StandardError, e: self.output_error(e) songs = []
def get_items(self): fpath = config.get_config_file("Bookmarks", package="chromium/Default") if fpath: try: return self._get_chromium_items(fpath) except Exception, exc: self.output_error(exc)
def load(): """ Load learning database """ global _register filepath = config.get_config_file(mnemonics_filename) if filepath: _register = Learning._unpickle_register(filepath) if not _register: _register = {}
def load(): """ Load learning database """ global _register filepath = config.get_config_file(mnemonics_filename) if filepath: _register = Learning._unpickle_register(filepath) if not _register: _register = {} if CORRELATION_KEY not in _register: _register[CORRELATION_KEY] = _default_actions
def _read_config(self, read_config=True): """ Read cascading config files default -> then config (in all XDG_CONFIG_DIRS) """ parser = ConfigParser.SafeConfigParser() def fill_parser(parser, defaults): for secname, section in defaults.iteritems(): if not parser.has_section(secname): parser.add_section(secname) for key, default in section.iteritems(): if isinstance(default, (tuple, list)): default = self.sep.join(default) elif isinstance(default, int): default = str(default) parser.set(secname, key, default) # Set up defaults confmap = copy.deepcopy(self.defaults) fill_parser(parser, confmap) # Read all config files config_files = [] try: defaults_path = config.get_data_file(self.defaults_filename) except config.ResourceLookupError: print "Error: no default config file %s found!" % self.defaults_filename else: self._defaults_path = defaults_path config_files += (defaults_path, ) if read_config: config_path = config.get_config_file(self.config_filename) if config_path: config_files += (config_path, ) for config_file in config_files: try: with open(config_file, "r") as fil: parser.readfp(fil) except IOError, e: print "Error reading configuration file %s: %s", (config_file, e)
def _get_default_notebook(): ''' Find default notebook ''' zim_notebooks_file = config.get_config_file("notebooks.list", package="zim") if not zim_notebooks_file: pretty.print_error(__name__, "Zim notebooks.list not found") return None lines = None with open(zim_notebooks_file, 'r') as notebooks_file: lines = notebooks_file.readlines() if not lines: return '' if lines[0].strip() == '[NotebookList]': # new version # first section looks like: # [NotebookList] # Default=~/doc/zim # ~/doc/zim # ~/tmp/test for line in lines[1:]: if line.startswith('Default='): _dummy, name = line.split('=', 1) name = name.strip() if name: pretty.print_debug(__name__, '_get_default_notebook:', name) return name return line return '' # old version # format '<notebook name | _default_>\t<path>' name = '' for line in lines: if '\t' in line: notebook_name, notebook_path = line.strip().split('\t', 1) if notebook_name == '_default_': # _default_ is pointing at name of the default notebook name = notebook_path.decode("UTF-8", "replace") else: # assume first notebook as default name = notebook_name.decode("UTF-8", "replace") break pretty.print_debug(__name__, '_get_default_notebook (old):', name) return name
def _get_default_notebook(): ''' Find default notebook ''' zim_notebooks_file = config.get_config_file("notebooks.list", package="zim") if not zim_notebooks_file: pretty.print_error(__name__, "Zim notebooks.list not found") return None with open(zim_notebooks_file, 'r') as notebooks_file: for line in notebooks_file.readlines(): if line.strip() == "[NotebookList]": # new file format == pyzim return '' if line.strip() != '_default_': # when no default notebook notebook_name, notebook_path = line.strip().split('\t', 2) if notebook_name == '_default_': # _default_ is pointing at name of the default notebook return notebook_path.decode("UTF-8", "replace") else: # assume first notebook as default return notebook_name.decode("UTF-8", "replace")
def _get_zim_notebooks(): ''' Yield (notebook name, notebook path) from zim config @notebook_name: Unicode name @notebook_path: Filesystem byte string ''' # We assume the notebook description is UTF-8 encoded zim_notebooks_file = config.get_config_file("notebooks.list", package="zim") if not zim_notebooks_file: pretty.print_error(__name__, "Zim notebooks.list not found") return [] try: with open(zim_notebooks_file, 'r') as notebooks_file: for line in notebooks_file.readlines(): if line.strip() == "[NotebookList]": return _read_zim_notebooks_new(zim_notebooks_file) else: return _read_zim_notebooks_old(zim_notebooks_file) except IOError, err: pretty.print_error(__name__, err)
def _get_zim_notebooks(): ''' Yield (notebook name, notebook path) from zim config @notebook_name: Unicode name @notebook_path: Filesystem byte string ''' # We assume the notebook description is UTF-8 encoded zim_notebooks_file = config.get_config_file("notebooks.list", package="zim") if not zim_notebooks_file: pretty.print_error(__name__, "Zim notebooks.list not found") return [] try: config_first_line = None with open(zim_notebooks_file, 'r') as notebooks_file: config_first_line = notebooks_file.readline().strip() if config_first_line == "[NotebookList]": return _read_zim_notebooks_new(zim_notebooks_file) else: return _read_zim_notebooks_old(zim_notebooks_file) except IOError, err: pretty.print_error(__name__, err)
def _get_zim_notebooks(): ''' Yield (notebook name, notebook path) from zim config @notebook_name: Unicode name @notebook_path: Filesystem byte string ''' # We assume the notebook description is UTF-8 encoded zim_notebooks_file = config.get_config_file("notebooks.list", package="zim") if not zim_notebooks_file: pretty.print_error(__name__, "Zim notebooks.list not found") return try: with open(zim_notebooks_file, 'r') as noteboks_file: for line in noteboks_file.readlines(): if not line.startswith('_default_'): notebook_name, notebook_path = line.strip().split('\t', 2) notebook_name = notebook_name.decode("UTF-8", "replace") notebook_path = os.path.expanduser(notebook_path) yield (notebook_name, notebook_path) except IOError, err: pretty.print_error(__name__, err)
def get_items(self): _config_file = config.get_config_file('user_sources.cfg') if not _config_file or not os.path.isfile(_config_file): self.output_debug('no config file') return self.output_debug('loading sources', _config_file) cfgpars = ConfigParser.SafeConfigParser(_ACTION_DEFAULTS) cfgpars.read(_config_file) for section in cfgpars.sections(): command = cfgpars.get(section, 'command') filename = cfgpars.get(section, 'file') if not command and not filename: self.output_info('missing command and filename for source:', section) continue src = UserSource(section, command, filename) src.result_type = cfgpars.get(section, 'type') or 'text' src.description = cfgpars.get(section, 'description') src.dynamic = bool(cfgpars.get(section, 'dynamic')) yield objects.SourceLeaf(src)
def get_items(self): self.output_debug("Items") if self.loaded: self.output_debug('load from cache') return self.items filesToLoad=[] if __kupfer_settings__["change_file_location"]: filesConfig = __kupfer_settings__["path_to_file"] filesToLoad = filesConfig.split(';') else: filesToLoad.append(config.get_config_file(CONFIG_FILENAME)) self.items = [] for filePath in filesToLoad: if not os.path.isfile(filePath): self.output_debug('File does not exist', filePath) continue self.output_debug('loading sources', filePath) ins = open( filePath, "r" ) for line in ins: matchObj = re.match( r'([^=]+)=(.*)$', line.strip(), re.M|re.I) if matchObj: self.items.append(UrlLeaf(matchObj.group(2).strip(), matchObj.group(1).strip())) ins.close() self.output_debug(self.items); self.output_debug('mark_for_update'); self.loaded = True return self.items
# Set up defaults confmap = copy.deepcopy(self.defaults) fill_parser(parser, confmap) # Read all config files config_files = [] try: defaults_path = config.get_data_file(self.defaults_filename) except config.ResourceLookupError, exc: print "Error: no default config file %s found!" % self.defaults_filename else: self._defaults_path = defaults_path config_files += (defaults_path, ) if read_config: config_path = config.get_config_file(self.config_filename) if config_path: config_files += (config_path, ) for config_file in config_files: try: with open(config_file, "r") as fil: parser.readfp(fil) except IOError, e: print "Error reading configuration file %s: %s", (config_file, e) # Read parsed file into the dictionary again for secname in parser.sections(): if secname not in confmap: confmap[secname] = {} for key in parser.options(secname): value = parser.get(secname, key)
def _read_config(self, read_config=True): """ Read cascading config files default -> then config (in all XDG_CONFIG_DIRS) """ parser = configparser.RawConfigParser() def fill_parser(parser, defaults): for secname, section in defaults.items(): if not parser.has_section(secname): parser.add_section(secname) for key, default in section.items(): if isinstance(default, (tuple, list)): default = self.sep.join(default) elif isinstance(default, int): default = str(default) parser.set(secname, key, default) # Set up defaults confmap = copy.deepcopy(self.defaults) fill_parser(parser, confmap) # Read all config files config_files = [] try: defaults_path = config.get_data_file(self.defaults_filename) except config.ResourceLookupError: self.output_error(("Error: no default config file %s found!" % self.defaults_filename)) else: self._defaults_path = defaults_path config_files += (defaults_path, ) if read_config: config_path = config.get_config_file(self.config_filename) if config_path: config_files += (config_path, ) for config_file in config_files: try: parser.read(config_file, encoding=self.encoding) except IOError as e: self.output_error(("Error reading configuration file %s: %s" % (config_file, e))) except UnicodeDecodeError as e: self.output_error(("Error reading configuration file %s: %s" % (config_file, e))) # Read parsed file into the dictionary again for secname in parser.sections(): if secname not in confmap: confmap[secname] = {} for key in parser.options(secname): value = parser.get(secname, key) retval = value if secname in self.defaults and key in self.defaults[secname]: defval = self.defaults[secname][key] if isinstance(defval, (tuple, list)): if not value: retval = () else: retval = [ p.strip() for p in value.split(self.sep) if p ] elif isinstance(defval, bool): retval = strbool(value) elif isinstance(defval, int): retval = type(defval)(value) else: retval = str(value) confmap[secname][key] = retval return confmap