Skip to content

Commit

Permalink
Convert settings script
Browse files Browse the repository at this point in the history
  • Loading branch information
koeqaife committed Jul 29, 2024
1 parent a979ac2 commit 390c23d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup/after_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ install_microtex() {
makepkg -si
}


cp -f $HOME/dotfiles/setup/wl-gammarelay.service $HOME/.config/systemd/user/
ask_continue "Import the old settings into the new settings?" && python "$HOME"/dotfiles/setup/import_settings.py
ask_continue "Proceed with installing/updating packages?" && "$HOME"/dotfiles/install.sh packages
ask_continue "Proceed with installing MicroTex?" && install_microtex

Expand Down
70 changes: 70 additions & 0 deletions setup/import_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import json
import os
from os import path
import shutil

settings = path.expanduser("~/dotfiles/.settings")
settings_json = f"{settings}/settings.json"
apps_json = f"{settings}/apps.json"


files = {
"settings": {
f"{settings}/custom-color": "custom-color",
f"{settings}/swww-anim": "swww-anim",
f"{settings}/color-scheme": "color-scheme",
f"{settings}/generation-scheme": "generation-scheme",
f"{settings}/wallpaper-engine.sh": "wallpaper-engine"
},
"apps": {
f"{settings}/browser.sh": "browser",
f"{settings}/editor.sh": "editor",
f"{settings}/filemanager.sh": "filemanager",
f"{settings}/terminal.sh": "terminal"
}
}

if not path.isfile(settings_json):
print(f":: File \"{settings_json}\" does not exist!")
exit(1)
if not path.isfile(apps_json):
print(f":: File \"{apps_json}\" does not exist!")
exit(1)

print(":: Loading files")
with open(settings_json) as f:
settings_c = json.load(f)
with open(apps_json) as f:
apps_c = json.load(f)

print(":: Importing")
for file in files["apps"]:
if path.isfile(file):
with open(file) as f:
apps_c[files["apps"][file]] = f.read().strip()
else:
print(f": File {file} doesn't exists")
for file in files["settings"]:
if path.isfile(file):
with open(file) as f:
settings_c[files["settings"][file]] = f.read().strip()
else:
print(f": File {file} doesn't exists")

print(":: Saving")
with open(settings_json, 'w') as f:
json.dump(settings_c, f, indent=2)
with open(apps_json, 'w') as f:
json.dump(apps_c, f, indent=2)

print(":: Backing up old files")
old_files = [
f for f in os.listdir(settings)
if os.path.isfile(os.path.join(settings, f))
]
backup_folder = f"{settings}/old"
ignore = ["icon-theme", "settings.json", "apps.json"]
os.makedirs(backup_folder, exist_ok=True)
for x in old_files:
if x.strip() not in ignore:
shutil.move(f"{settings}/{x}", f"{backup_folder}/{x}")

0 comments on commit 390c23d

Please sign in to comment.