79 lines
2 KiB
Python
Executable file
79 lines
2 KiB
Python
Executable file
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()
|
|
|
|
# Main part
|
|
|
|
def main():
|
|
config_file = cwd / "config.yml"
|
|
if not config_file.exists():
|
|
return
|
|
config = yaml.safe_load(config_file.read_text())
|
|
if not config:
|
|
return
|
|
if "dotfiles" in config:
|
|
print("Installing dotfiles...")
|
|
for folder in config["dotfiles"]:
|
|
print(f" - {folder}")
|
|
set_dotfiles(folder, config["dotfiles"][folder])
|
|
if "gnome" in config:
|
|
if "extensions" in config["gnome"]:
|
|
print("Installing GNOME extensions...")
|
|
for ext in config["gnome"]["extensions"]:
|
|
print(f" - {ext}")
|
|
install_gnome_extension(ext)
|
|
if "import" in config["gnome"]:
|
|
print("Importing GNOME settings...")
|
|
for file in config["gnome"]["import"]:
|
|
print(f" - {file}")
|
|
import_gnome_config(file, config["gnome"]["import"][file])
|
|
|
|
main() |