from pathlib import Path import yaml import subprocess cwd = Path(__file__).parent.parent variables = { "$home": str(Path.home()) } def replace_variables(string: str): for variable in variables: string = string.replace(variable, variables[variable]) return string def get_files(folder: Path, files: list[str]) -> set[Path]: result = set() for file in files: if not (folder / file).exists(): for d in (folder).glob(file): result.add(d) else: result.add(folder / file) return result # Setup dotfiles def set_dotfiles(folder: str, config: dict): all_files = set() for where in config: files = get_files(cwd / folder, config[where]).difference(all_files) for file in files: where_file = Path(replace_variables(where)) / file.relative_to(cwd / folder) if where_file.exists(): where_file.unlink() where_file.symlink_to(file) all_files.update(files) # Install GNOME extensions def install_gnome_extension(ext): p = subprocess.Popen(f"{cwd / '_scripts' / 'gnome-install-extension.sh'} {ext}", shell=True) p.wait() # Import GNOME settings def import_gnome_config(file: str, path: str): dconf = cwd / "gnome" / (file+".dconf"); p = subprocess.Popen(f"dconf load {path} < {dconf}", shell=True) p.wait() dotfiles = cwd / "dotfiles.yml" if dotfiles.exists(): config = yaml.safe_load(dotfiles.read_text()) if config: print("Installing dotfiles...") for folder in config: print(f" - {folder}") set_dotfiles(folder, config[folder]) gnome = cwd / "gnome.yml" if gnome.exists(): config = yaml.safe_load(gnome.read_text()) if "extensions" in config: print("Installing GNOME extensions...") for ext in config["extensions"]: print(f" - {ext}") install_gnome_extension(ext) if "import" in config: print("Importing GNOME settings...") for file in config["import"]: print(f" - {file}") import_gnome_config(file, config["import"][file])