From b8ae16f6b7d8e3d583aa91d5143700bc6b148966 Mon Sep 17 00:00:00 2001 From: Derisis13 Date: Fri, 10 Dec 2021 19:12:31 +0100 Subject: [PATCH] Added checking for dconf and apt-get to avoid confusion and frustration Also restoring now provides information about the age of your backup --- main.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index ef44736..8f8fc81 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import datetime +import distutils.spawn import getopt import os import subprocess @@ -47,6 +48,13 @@ def restore(): packagelist.close() exit(2) else: + try: + f = open(".backupdone", "r") + date = f.read(10) + f.close() + except FileNotFoundError: + date = "Unknown" + print("Restoring programs and settings from ", date) subprocess.run(["dpkg", "--set-selections"], stdin=packagelist) subprocess.run(["apt-get", "dselect-upgrade"]) packagelist.close() @@ -67,6 +75,18 @@ def restore(): exit() +def check_progs(): + apt = distutils.spawn.find_executable("apt-get") + dconf = distutils.spawn.find_executable("dconf") + if apt == False: + print("Your system is not using apt as a package manager! Barusu uses apt to back up your packages. Barusu IS " + "NOT designed to work with other packaging tools.") + if dconf = False: + print("Your system is not using dconf! Barusu uses dconf to back up your settings. Barusu IS " + "NOT designed to work with other settings manager.") + return apt, dconf + + if __name__ == '__main__': backupdir = os.path.expanduser("~/.backup") try: @@ -76,7 +96,7 @@ if __name__ == '__main__': exit(1) for option, value in options: if option in ("-h", "help"): - print("usage: barusu [opts]\n\ + print("usage: backup_assistant [opts]\n\ Options:\n\ \t-h --help: show this\n\ \t-d --backup-dir [directory]: set the directory for the backup/restoration (default is ~/.backups)\n\ @@ -88,6 +108,11 @@ if __name__ == '__main__': restore() exit() + apt, dconf = check_progs() + if apt and dconf: + print("System incompatibilities, exitting...") + exit(3) + try: os.chdir(backupdir) except FileNotFoundError: