def config_load(self): try: read_conf = snakypy_file_red(self.config_file) parsed = toml_parse(read_conf) return parsed except FileNotFoundError: snakypy_path_create(self.config_root) create_config(config_content, self.config_file) read_conf = snakypy_file_red(self.config_file) parsed = toml_parse(read_conf) # printer( # f"[ZSHPower Warning] A new configuration file for that version " # f'has been created in "{self.config_root}".', # foreground=FG.YELLOW, # ) return parsed
def create_config(content, file_path, force=False): if not exists(file_path) or force: parsed_toml = toml_parse(content) write_toml = toml_dumps(parsed_toml) snakypy_file_create(write_toml, file_path, force=force) return True return
def get_version(self, space_elem=" "): if isfile(self.pyproject_f): read_f = snakypy_file_read(self.pyproject_f) parsed = dict(toml_parse(read_f)) for item in parsed.values(): for data in item.values(): return f"{data['version']}{space_elem}" return ""
def main(self, arguments): checking_init(self.HOME) if arguments["--open"]: try: read_conf = snakypy_file_red(self.config_file) parsed = toml_parse(read_conf) editor_conf = parsed["general"]["config"]["editor"] except (FileNotFoundError, Exception): editor_conf = None if editor_conf: editor_run(editor_conf, self.config_file) else: editors = ("vim", "nano", "emacs", "micro") for edt in editors: editor_run(edt, self.config_file) elif arguments["--view"]: read_config = snakypy_file_read(self.config_file) pydoc_pager(read_config) return True
def toml(self): if not self.file_path or not self.file_path.endswith(".toml"): raise ValueError(_("node {} not in TOML format").format(self.name)) return toml_parse(get_file_contents(self.file_path))
def parse_string(config_string): cfg = toml_parse(config_string) return cfg
def load_file(self): with open(self.file_name) as f: self._storage = toml_parse(f.read())