Added database backup.
This commit is contained in:
1
Windows/itembackup/Item.txt
Normal file
1
Windows/itembackup/Item.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Item information will go here.
|
1
Windows/patronbackup/Patron.txt
Normal file
1
Windows/patronbackup/Patron.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Patron information will go here.
|
@ -17,6 +17,7 @@ from xlsxwriter.workbook import Workbook
|
|||||||
from barcode import Code39
|
from barcode import Code39
|
||||||
from barcode.writer import ImageWriter
|
from barcode.writer import ImageWriter
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import Tkinter as tk
|
import Tkinter as tk
|
||||||
@ -172,7 +173,6 @@ class Toplevel1:
|
|||||||
self.patron_entry.configure(state='normal')
|
self.patron_entry.configure(state='normal')
|
||||||
self.patron_entry.delete(0, tk.END)
|
self.patron_entry.delete(0, tk.END)
|
||||||
self.patron_entry.focus_set()
|
self.patron_entry.focus_set()
|
||||||
|
|
||||||
|
|
||||||
# --- DELETE THE CURRENT DATABASE AND SUPPLANT WITH AN EMPTY ONE ---
|
# --- DELETE THE CURRENT DATABASE AND SUPPLANT WITH AN EMPTY ONE ---
|
||||||
def ClearDatabase():
|
def ClearDatabase():
|
||||||
@ -183,12 +183,34 @@ class Toplevel1:
|
|||||||
#conn.close # Close out the current database
|
#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?')
|
self.ConfirmClear = tk.messagebox.askquestion ('PECOS - Confim','Final answer: Are you sure you wish to clear the database?')
|
||||||
if self.ConfirmClear == 'yes':
|
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
|
os.remove("checkouts.db") # Delete the current database
|
||||||
shutil.copy("emptybase.db", "checkouts.db") # Copy over an empty database
|
shutil.copy("emptybase.db", "checkouts.db") # Copy over an empty database
|
||||||
shutil.rmtree('item')
|
shutil.rmtree('item')
|
||||||
shutil.rmtree('patron')
|
shutil.rmtree('patron')
|
||||||
os.makedirs('item')
|
os.makedirs('item')
|
||||||
os.makedirs('patron')
|
os.makedirs('patron')
|
||||||
|
'''
|
||||||
# Next two lines commented out in Windows version - the connection commands work on macOS
|
# Next two lines commented out in Windows version - the connection commands work on macOS
|
||||||
#conn = sqlite3.connect('checkouts.db') # Restablish connection to the database
|
#conn = sqlite3.connect('checkouts.db') # Restablish connection to the database
|
||||||
#c = conn.cursor()
|
#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)
|
#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)
|
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():
|
def BackupData():
|
||||||
# Set path variables for backup folders
|
# Set path variables for backup folders
|
||||||
ItemFolder = 'item/'
|
ItemFolder = 'item/'
|
||||||
@ -256,6 +278,9 @@ class Toplevel1:
|
|||||||
shutil.copytree(PatronFolder, PatronBackup)
|
shutil.copytree(PatronFolder, PatronBackup)
|
||||||
shutil.copy(DatabaseFile, dbBackup)
|
shutil.copy(DatabaseFile, dbBackup)
|
||||||
|
|
||||||
|
self.DatabaseDone = tk.messagebox.showinfo ('PECOS - Backup Database','Database backup complete.')
|
||||||
|
|
||||||
|
|
||||||
# --- END OF FUNCTIONS - BEGIN GUI ---
|
# --- END OF FUNCTIONS - BEGIN GUI ---
|
||||||
|
|
||||||
self.Canvas1 = tk.Canvas(top)
|
self.Canvas1 = tk.Canvas(top)
|
||||||
@ -293,9 +318,9 @@ class Toplevel1:
|
|||||||
self.item_entry.configure(font="TkFixedFont")
|
self.item_entry.configure(font="TkFixedFont")
|
||||||
self.item_entry.bind('<Return>', CheckOutItem)
|
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.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 = tk.Frame(self.Canvas1)
|
||||||
self.LowerFrame.place(relx=0.05, rely=0.78, relheight=0.13, relwidth=0.908)
|
self.LowerFrame.place(relx=0.05, rely=0.78, relheight=0.13, relwidth=0.908)
|
||||||
|
Reference in New Issue
Block a user