From 9aa7f6864d0e72728260271494866c17485d4195 Mon Sep 17 00:00:00 2001 From: Derisis13 Date: Thu, 9 Dec 2021 19:37:15 +0100 Subject: [PATCH] Innitial commit, core function is implemented --- main.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..6005795 --- /dev/null +++ b/main.py @@ -0,0 +1,47 @@ +import os +import subprocess +import datetime +import sys + + +def run_daily(): + try: + f = open('.backupdone', "r+") + except FileNotFoundError: + f = open('.backupdone', "w+") + olddate = f.read(10) + if (olddate == str(datetime.datetime.now().date())) and (len(olddate) > 0): + exit() + f.seek(0, 0) + f.write(str(datetime.datetime.now().date())) + f.close() + + +def list_pkgs(): + f = open("packages.txt", "w") + subprocess.run(args=["dpkg", "--get-selections"], stdout=f) + f.close() + + +def save_settings(): + f = open("dconf_out.txt", "w") + subprocess.run(args=["dconf", "dump", "/"], stdout=f) + f.close() + + +if __name__ == '__main__': + for i in sys.argv: + if i == "--help" or i == "-h": + print("usage: [opts]\n\ + Options:\n\ + \t-h --help: show this\n\ + \t-d --backup-dir [directory]: set the directory the backups go to") + backupdir = "/home/lacko/.backup" + try: + # os.chdir("/run/user/1000/gvfs/smb-share:server=ds_panni.local,share=lacko/Backup/T490") + os.chdir(backupdir) + except FileNotFoundError: + subprocess.call(["mkdir", backupdir]) + run_daily() + list_pkgs() + save_settings()