Fri Jun 23 16:28:43 CEST 2023
This commit is contained in:
+42
-30
@@ -7,7 +7,8 @@ from solenlib import schedule_tdy_tmr as st
|
||||
import sys
|
||||
import getpass
|
||||
import argparse
|
||||
import datetime
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(prog="ŠOLEn", description="ŠOLEn, an enhanced version of the ŠkolaOnLine online school system")
|
||||
@@ -20,9 +21,7 @@ if __name__ == "__main__":
|
||||
parser.add_argument("-l", "--local", action="store_true", help="Only fetch local files, don't connect to the internet")
|
||||
parser.add_argument("-d", "--delete-local-files", action="store_true", help="Delete all local user data, including schedules, grades and user credentials")
|
||||
|
||||
parser.add_argument("-b", "--backup", action="store_true", help="Securely back up all user data and store them in a .tar.gz archive in the destination directory")
|
||||
parser.add_argument("-D", "--backup-directory", action="store", help="Backup destination directory")
|
||||
parser.add_argument("-P", "--backup-password", action="store", help="Backup password to encrypt the archive with")
|
||||
parser.add_argument("-b", "--backup", action="store_true", help="Back up all user data and store them in a .tar.gz archive in the destination directory")
|
||||
parser.add_argument("-R", "--backup-restore", action="store", nargs=1, metavar="PATH", help="Specify the path to a .tar.gz archive that was earlier created with ŠOLEn to restore backed up user data")
|
||||
|
||||
args = parser.parse_args()
|
||||
@@ -30,37 +29,51 @@ if __name__ == "__main__":
|
||||
if args.delete_local_files:
|
||||
try:
|
||||
print("Removing all schedules and grades ...", end=" ")
|
||||
os.system(f"rm -rf {os.environ['HOME']}/.local/lib/solendata/*.csv")
|
||||
os.system(f"rm -rf {os.environ['HOME']}/.local/lib/solendata/*")
|
||||
print("done")
|
||||
print("Removing all user credentials ...", end=" ")
|
||||
os.system(f"rm -rf {os.environ['HOME']}/.local/lib/solendata/shadow")
|
||||
print("done")
|
||||
print("All user data removed successfully")
|
||||
sys.exit(0)
|
||||
except:
|
||||
print("Could not remove user data")
|
||||
sys.exit(1)
|
||||
|
||||
elif args.backup:
|
||||
try:
|
||||
if not args.backup_directory or not args.backup_password:
|
||||
print("-D, --backup-directory BACKUP-DIRECTORY and -P, --backup-password BACKUP-PASSWORD are required")
|
||||
sys.exit(1)
|
||||
else:
|
||||
nowtime = str(datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
|
||||
try:
|
||||
print("Creating the backup archive ...", end=" ")
|
||||
os.system(f"tar cf solen-backup-{nowtime} {os.path.abspath(args.backup-directory)}")
|
||||
print("done")
|
||||
print("Backup archive created successfully")
|
||||
sys.exit(0)
|
||||
except:
|
||||
print("The 'tar' utility is not installed")
|
||||
sys.exit(1)
|
||||
nowtime = str(datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
|
||||
try:
|
||||
print("Creating the backup archive ...", end=" ")
|
||||
os.system(f"tar cf solen-backup-{nowtime}.tar {os.getcwd()}")
|
||||
print("done")
|
||||
print("Compressing the archive ...", end=" ")
|
||||
os.system(f"gzip {os.getcwd()}/solen-backup-{nowtime}.tar")
|
||||
print("done")
|
||||
print("Backup archive created successfully")
|
||||
except:
|
||||
print("The 'tar' utility or the 'gzip' utility is not installed")
|
||||
except:
|
||||
print("Could not backup user data")
|
||||
sys.exit(1)
|
||||
|
||||
elif args.backup_restore:
|
||||
try:
|
||||
backup_path = args.backup_restore
|
||||
print("Preparing ...", end=" ")
|
||||
os.system(f"mkdir {os.getcwd()}/.solentmp")
|
||||
print("done")
|
||||
print("Uncompressing the archive ...", end=" ")
|
||||
os.system(f"gunzip {backup_path}")
|
||||
print("done")
|
||||
print("Unpacking the archive ...", end=" ")
|
||||
os.system(f"tar xzjf {backup_path} {os.getcwd()}/.solentmp")
|
||||
print("done")
|
||||
print("Moving the files ...", end=" ")
|
||||
os.system(f"mv {os.getcwd()}/.solentmp/* {os.environ['HOME']}/.local/lib/solendata")
|
||||
print("done")
|
||||
print("Cleaning up ...", end=" ")
|
||||
os.system(f"rm -rf {os.getcwd()}/.solentmp")
|
||||
print("done")
|
||||
print("Backup restored successfully")
|
||||
except:
|
||||
print("Could not restore the backup")
|
||||
else:
|
||||
if args.username:
|
||||
user = str(args.username)
|
||||
@@ -76,7 +89,7 @@ if __name__ == "__main__":
|
||||
pwd = str(input("Zadejte heslo: "))
|
||||
|
||||
if not nw.login(user, pwd):
|
||||
print("Login unsuccessfull")
|
||||
print("Login unsuccessful")
|
||||
sys.exit(1)
|
||||
else:
|
||||
try:
|
||||
@@ -92,20 +105,19 @@ if __name__ == "__main__":
|
||||
st.show_schedule()
|
||||
if args.grades:
|
||||
if args.local:
|
||||
gr.show_grades(local=True)
|
||||
gr.show_grades(pwd, user, local=True)
|
||||
else:
|
||||
gr.show_grades()
|
||||
gr.show_grades(pwd, user)
|
||||
|
||||
if not args.grades and not args.today_tomorrow and not args.week:
|
||||
if args.local:
|
||||
sw.show_schedule(local=True)
|
||||
st.show_schedule(local=True)
|
||||
gr.show_grades(local=True)
|
||||
gr.show_grades(pwd, user, local=True)
|
||||
else:
|
||||
sw.show_schedule()
|
||||
st.show_schedule()
|
||||
gr.show_grades()
|
||||
sys.exit(0)
|
||||
gr.show_grades(pwd, user)
|
||||
except Exception as e:
|
||||
raise e
|
||||
print("Could not execute")
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user