Added database backup.

This commit is contained in:
2020-12-08 12:32:17 -06:00
parent b60937b4b5
commit d1016ec070
3 changed files with 31 additions and 4 deletions

View File

@ -0,0 +1 @@
Item information will go here.

View File

@ -0,0 +1 @@
Patron information will go here.

View File

@ -17,6 +17,7 @@ from xlsxwriter.workbook import Workbook
from barcode import Code39
from barcode.writer import ImageWriter
import subprocess
import time
try:
import Tkinter as tk
@ -172,7 +173,6 @@ class Toplevel1:
self.patron_entry.configure(state='normal')
self.patron_entry.delete(0, tk.END)
self.patron_entry.focus_set()
# --- DELETE THE CURRENT DATABASE AND SUPPLANT WITH AN EMPTY ONE ---
def ClearDatabase():
@ -183,12 +183,34 @@ class Toplevel1:
#conn.close # Close out the current database
self.ConfirmClear = tk.messagebox.askquestion ('PECOS - Confim','Final answer: Are you sure you wish to clear the database?')
if self.ConfirmClear == 'yes':
ItemFolder = 'item/'
ItemBackup = 'itembackup/'
PatronFolder = 'patron/'
PatronBackup = 'patronbackup/'
DatabaseFile = 'checkouts.db'
dbBackup = 'checkouts-backup.db'
os.remove(DatabaseFile) # Delete the current database
os.remove(dbBackup)
shutil.copy("emptybase.db", "checkouts.db") # Copy over an empty database
shutil.rmtree(ItemFolder)
shutil.rmtree(PatronFolder)
shutil.rmtree(ItemBackup)
shutil.rmtree(PatronBackup)
os.makedirs(ItemFolder)
os.makedirs(PatronFolder)
os.makedirs(PatronBackup)
os.makedirs(ItemBackup)
'''
os.remove("checkouts.db") # Delete the current database
shutil.copy("emptybase.db", "checkouts.db") # Copy over an empty database
shutil.rmtree('item')
shutil.rmtree('patron')
os.makedirs('item')
os.makedirs('patron')
'''
# Next two lines commented out in Windows version - the connection commands work on macOS
#conn = sqlite3.connect('checkouts.db') # Restablish connection to the database
#c = conn.cursor()
@ -231,7 +253,7 @@ class Toplevel1:
#subprocess.run(['open', 'export.html'], check=True) # Open export.html in the default web browser (macOS)
os.startfile('export.html') # Open export.html in the default web browser (Windows)
# --- BACKUP THE DATABASE AND BARCODES EVERY FIVE MINTUES ---
# --- BACKUP THE DATABASE ---
def BackupData():
# Set path variables for backup folders
ItemFolder = 'item/'
@ -256,6 +278,9 @@ class Toplevel1:
shutil.copytree(PatronFolder, PatronBackup)
shutil.copy(DatabaseFile, dbBackup)
self.DatabaseDone = tk.messagebox.showinfo ('PECOS - Backup Database','Database backup complete.')
# --- END OF FUNCTIONS - BEGIN GUI ---
self.Canvas1 = tk.Canvas(top)
@ -293,9 +318,9 @@ class Toplevel1:
self.item_entry.configure(font="TkFixedFont")
self.item_entry.bind('<Return>', CheckOutItem)
self.finish_button = tk.Button(self.Canvas1, command=CheckOutComplete)
self.finish_button = tk.Button(self.Canvas1, command=BackupData)
self.finish_button.place(relx=0.7, rely=0.12, height=29, width=123)
self.finish_button.configure(text='''Finish checkout''')
self.finish_button.configure(text='''Backup Database''')
self.LowerFrame = tk.Frame(self.Canvas1)
self.LowerFrame.place(relx=0.05, rely=0.78, relheight=0.13, relwidth=0.908)