Fix: flatpak-related actions can be executed

This commit is contained in:
2022-04-27 17:35:40 +02:00
parent c192cd0ae8
commit d0df5886d3

18
main.py
View File

@@ -55,13 +55,13 @@ def run_daily():
f.close() f.close()
def list_apt_packages(): def save_apt_packages():
f = open("packages.txt", "w") f = open("packages.txt", "w")
subprocess.run(args=["dpkg", "--get-selections"], stdout=f) subprocess.run(args=["dpkg", "--get-selections"], stdout=f)
f.close() f.close()
def list_flatpak_apps(): def save_flatpak_apps():
f = open("flatpaks.txt", "w") f = open("flatpaks.txt", "w")
subprocess.run(args=["flatpak", "list", "--app", "--columns=origin,ref"], stdout=f) # This will store a junk line subprocess.run(args=["flatpak", "list", "--app", "--columns=origin,ref"], stdout=f) # This will store a junk line
f.close() f.close()
@@ -113,6 +113,8 @@ def restore():
restore_apt_packages() restore_apt_packages()
if actions.__contains__("dconf"): if actions.__contains__("dconf"):
restore_dconf_settings() restore_dconf_settings()
if actions.__contains__("flatpak"):
restore_flatpak_apps()
print("Exiting...") print("Exiting...")
exit() exit()
@@ -130,6 +132,7 @@ if __name__ == '__main__':
backupdir = os.path.expanduser("~/.backup") backupdir = os.path.expanduser("~/.backup")
package_manager = "apt-get" package_manager = "apt-get"
settings_editor = "dconf" settings_editor = "dconf"
flatpak = "flatpak"
restore_mode = False restore_mode = False
try: try:
options, values = getopt.getopt(sys.argv[1:], "hd:ra:", ["help", "backup-dir=", "restore", "action="]) options, values = getopt.getopt(sys.argv[1:], "hd:ra:", ["help", "backup-dir=", "restore", "action="])
@@ -139,24 +142,27 @@ if __name__ == '__main__':
else: else:
for option, value in options: for option, value in options:
if option in ("-h", "--help"): if option in ("-h", "--help"):
print("usage: barusu [opts]\n" print("usage: " + sys.argv[0] + " [opts]\n"
"Options:\n" "Options:\n"
"\t-h --help: show this\n" "\t-h --help: show this\n"
"\t-d --backup-dir [directory]: set the directory for the backup/restoration " "\t-d --backup-dir [directory]: set the directory for the backup/restoration "
"(default is ~/.backups)\n" "(default is ~/.backups)\n"
"\t-r --restore: run the restoration (from backupdir)\n" "\t-r --restore: run the restoration (from backupdir)\n"
"\t-a --action [a/d]: select actions to perform (default is all). Valid actions: " "\t-a --action [a/d]: select actions to perform (default is all). Valid actions: "
"a - back up apt packages, d - back up dconf settings") "a - back up apt packages, d - back up dconf settings, f - back up flatpak apps")
exit() exit()
elif option in ("-d", "--backup-dir"): elif option in ("-d", "--backup-dir"):
backupdir = os.path.expanduser(value) backupdir = os.path.expanduser(value)
elif option in ("-a", "--action"): elif option in ("-a", "--action"):
package_manager = False package_manager = False
settings_editor = False settings_editor = False
flatpak = False
if value.__contains__('a'): if value.__contains__('a'):
package_manager = "apt-get" package_manager = "apt-get"
if value.__contains__('d'): if value.__contains__('d'):
settings_editor = "dconf" settings_editor = "dconf"
if value.__contains__('f'):
flatpak = "flatpak"
elif option in ("-r", "--restore"): elif option in ("-r", "--restore"):
restore_mode = True restore_mode = True
@@ -175,6 +181,8 @@ if __name__ == '__main__':
exit(0) exit(0)
run_daily() run_daily()
if actions.__contains__("apt-get"): if actions.__contains__("apt-get"):
list_apt_packages() save_apt_packages()
if actions.__contains__("dconf"): if actions.__contains__("dconf"):
save_dconf_settings() save_dconf_settings()
if actions.__contains__("flatpak"):
save_flatpak_apps()