def write_config(comment_text, overwrite): lines = comment_text.split("\n") assert lines[1] in (_config_file_str, _proggen_str) if lines[1] == _proggen_str: return "Original configuration was generated programmatically, no configuration to extract." config_text = "\n".join(lines[2:]) p = INI() p.read_string(config_text) filename = p.get("admin", "basename") \ if p.has_option("admin", "basename") else 'beastling' filename = Path(filename + '.conf') if filename.exists() and not overwrite: return "BEASTling configuration file %s already exists! Run beastling with the --overwrite option if you wish to overwrite it.\n" % filename if not filename.parent.exists(): filename.parent.mkdir() p.write(filename) return "Wrote BEASTling configuration file %s.\n" % filename
def write_config(comment_text, overwrite): lines = comment_text.split("\n") lines = [l for l in lines if l] assert lines[1] in (_config_file_str, _proggen_str) if lines[1] == _proggen_str: return "Original configuration was generated programmatically, no configuration to extract." truths = [_do_not_edit_str in line for line in lines] if any(truths): lines = lines[0:truths.index(True)] config_text = "\n".join(lines[2:]) p = INI() p.read_string(config_text) filename = p.get("admin", "basename") \ if p.has_option("admin", "basename") else 'beastling' filename = Path(filename + '.conf') if filename.exists() and not overwrite: return "BEASTling configuration file %s already exists! Run beastling with the --overwrite option if you wish to overwrite it.\n" % filename if not filename.parent.exists(): filename.parent.mkdir() p.write(filename) return "Wrote BEASTling configuration file %s.\n" % filename
def _bibfiles(cls, directory, config, endwith): """Read the INI-file, yield bibfile instances for sections.""" cfg = INI(interpolation=None) cfg.read(os.path.join(directory, '..', config)) for s in cfg.sections(): if not s.endswith(endwith): continue filepath = os.path.join(directory, s) assert os.path.exists(filepath) sortkey = cfg.get(s, 'sortkey') if sortkey.lower() == 'none': sortkey = None yield BibFile( filepath=filepath, encoding=cfg.get(s, 'encoding'), sortkey=sortkey, use_pybtex=cfg.getboolean(s, 'use_pybtex'), priority=cfg.getint(s, 'priority'), name=cfg.get(s, 'name'), title=cfg.get(s, 'title'), description=cfg.get(s, 'description'), abbr=cfg.get(s, 'abbr'))
def test_existing_config(self): cfg = INI() cfg.read_dict({'section': {'option': '12'}}) cfg.write(self.tmp_path('test.ini')) cfg = Config('test', dir_=self.tmp_path()) self.assertEqual(cfg.get('section', 'option'), '12')