42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
|
|
from os import path
|
|
from models.database import Database
|
|
from models.user import User
|
|
from services.search import Search
|
|
from services.utils import Utils
|
|
from ui.input_menu import InputMenu, Validator
|
|
from ui.selection_menu import SelectionMenu
|
|
|
|
class BackupMenu:
|
|
@staticmethod
|
|
def create_backup():
|
|
input_menu = InputMenu("Export Backup File").add_option("FILE", "Filename", "STR", "backup.sql", 1, 50, None).do_input()
|
|
backup_name = input_menu.get_value("FILE")
|
|
print(f"Exporting database to file: {backup_name}")
|
|
Utils.export_db(backup_name)
|
|
input(f"Exported database. Press any key to return.")
|
|
|
|
@staticmethod
|
|
def import_backup():
|
|
menu = SelectionMenu("Import Backup? This will delete current database!")
|
|
menu.add_option("Yes", True)
|
|
menu.add_option("No", False)
|
|
option = menu.display().input_option()
|
|
|
|
if option == False:
|
|
return
|
|
|
|
input_menu = InputMenu("Import Backup File").add_option("FILE", "Filename", "STR", "backup.sql", 1, 50, None).do_input()
|
|
backup_name = input_menu.get_value("FILE")
|
|
|
|
if not path.exists(f"./{backup_name}"):
|
|
input(f"Backup file not found. Press any key to return.")
|
|
return
|
|
|
|
print("Cleared current database.")
|
|
Database.delete_tables()
|
|
|
|
print(f"Importing database from file: {backup_name}")
|
|
Utils.import_db(backup_name)
|
|
input(f"Imported database. Press any key to return.")
|
|
|