backup sway config file

This commit is contained in:
piotr 2022-02-12 02:36:35 +01:00
parent b87c203ea7
commit c1435e5cbf
2 changed files with 41 additions and 13 deletions

View File

@ -15,7 +15,8 @@ License: MIT
import os
import sys
import argparse
from shutil import copy2, copytree
from shutil import copy, copy2, copytree
import datetime
from nwg_shell.__about__ import __version__
@ -35,7 +36,7 @@ def copy_from_skel(name, skip_confirmation=False):
dst = os.path.join(config_home, name)
print("Copying files to '{}'".format(dst), end=" ")
try:
copytree(src, dst, dirs_exist_ok=True)
# copytree(src, dst, dirs_exist_ok=True)
print("OK")
except Exception as e:
print("Failure: {}".format(e), file=sys.stderr)
@ -54,16 +55,19 @@ def main():
help="display version information")
args = parser.parse_args()
print("This script installs/overwrites configs and style sheets for sway and nwg-shell components.")
if not args.all:
a = input("You will be prompted 'Y/n' at each step. Proceed? Y/n ")
if a.strip().upper() != "Y":
print("Installation cancelled")
sys.exit(0)
print("_______________________________________________________________________________________________")
print(" This script installs/overwrites configs and style sheets for sway and nwg-shell components. ")
print(" The only backup that will be made is the main sway config file. ")
print(" If you're running the script on your existing sway setup, you're doing it at your own risk. ")
print("_______________________________________________________________________________________________")
a = input("\nProceed? Y/n ")
if a.strip().upper() != "Y":
print("Installation cancelled")
sys.exit(0)
a = input("Install helper scripts? Y/n ") if not args.all else "Y"
if a.strip().upper() == "Y" or args.all:
print("[Scripts installation]")
print("\n[Scripts installation]")
paths = []
bin_path = ""
for path in os.getenv("PATH").split(":"):
@ -104,9 +108,33 @@ def main():
except Exception as e:
print("Failure: {}".format(e), file=sys.stderr)
print("[Configs installation]")
for item in ["gtk-3.0", "sway", "nwg-panel", "nwg-wrapper", "nwg-drawer", "nwg-dock", "nwg-bar", "swaync"]:
copy_from_skel(item, args.all)
a = input("Install configs and style sheets? Y/n ") if not args.all else "Y"
if a.strip().upper() == "Y" or args.all:
print("\n[Configs installation]")
# Backup sway config file
now = datetime.datetime.now()
new_name = now.strftime("config-backup-%Y%m%d-%H%M%S")
src = os.path.join(config_home, "sway/config")
dst = os.path.join(config_home, "sway/{}".format(new_name))
proceed = True
backup = False
try:
copy(src, dst)
backup = True
except Exception as e:
print("Error: {}".format(e))
a = input("Proceed with installation? Y/n ")
proceed = a.strip().upper() == "Y"
if proceed:
for item in ["gtk-3.0", "sway", "nwg-panel", "nwg-wrapper", "nwg-drawer", "nwg-dock", "nwg-bar", "swaync"]:
copy_from_skel(item, args.all)
if backup:
print("\n*** Original sway config file '{}' has been renamed to '{}'".format(src, new_name))
print("That's all. You may run sway now.")
else:
print("Configs installation cancelled")
if __name__ == '__main__':

View File

@ -9,7 +9,7 @@ def read(f_name):
setup(
name='nwg-shell',
version='0.1.0',
version='0.1.1',
description='GTK3-based shell for sway Wayland compositor',
packages=find_packages(),
include_package_data=True,