-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.py
More file actions
72 lines (47 loc) · 1.91 KB
/
backup.py
File metadata and controls
72 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Compress.py - by Ian Noble (iannoble.org.uk | iannoble@gmail.com | github.com/inoble)
# Tkinter GUI to select and compress directories and upload them to a webserver.
import os, shutil
import upload
from tkinter import *
from tkinter import filedialog
# change location of directory to compress
def select_loc():
""" Return selected directory location. """
# delete any previous location information in textbox and status text
entry.delete(0, 'end')
status_text.config(text='')
location = filedialog.askdirectory()
entry.insert(END, location)
# find directory location and compress directory
def backup():
""" Compress selected directory location and upload. """
location = entry.get()
# if textbox is empty, prompt user to select a directory to compress
if not location:
status_text.config(text='click ... to select a directory to compress')
# if textbox contains a directory, compress directory
else:
os.chdir(location)
status_text.config(text='compressing: ' + location)
shutil.make_archive('backup', 'zip', location)
status_text.config(text='uploading...')
upload.upload(location)
status_text.config(text='backup successful')
# initiate Tkinter GUI
master = Tk()
master.geometry('{}x{}'.format(400, 50))
master.title('Backup Directory')
# Tkinter text entry box
entry = Entry(master, width=50)
entry.grid(row = 0, column = 0, columnspan = 5)
# Tkinter button to search for a directory
filedialog_button = Button(master, text="...", command=select_loc)
filedialog_button.grid(row = 0, column = 6, sticky=W)
# Tkinter 'zip' button to compress and upload directory
compress_button = Button(master, text="backup", command=backup)
compress_button.grid(row = 0, column = 7, sticky=W)
# Tkinter status textbox
status_text = Label(master, justify=LEFT)
status_text.grid(row = 1, column = 0)
# end Tkinter GUI
mainloop()