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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env python
#   File: backitup.py
# Author: shadytyrant@gmail.com
#   Date: 2009-11-19
#  Notes: A gui version of my linux backup script written with wxPython
#--------------------------------------------
 
import wx, ostime
 
class MyFrame(wx.Frame):
    def __init__(self*args, **kwds):
 
        # Create widgets, layout, and propertys. Bind events to handlers
 
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self*args, **kwds)
 
        self.label_1 = wx.StaticText(self-1"File One          ")
        self.txtFilePathOne = wx.TextCtrl(self-1"")
        self.btnAddFileOne = wx.Button(self-1"Add File")
 
        self.label_2 = wx.StaticText(self-1"File Two           ")
        self.txtFilePathTwo = wx.TextCtrl(self-1"")
        self.btnAddFileTwo = wx.Button(self-1"Add File")
 
        self.label_3 = wx.StaticText(self-1"File Three       ")
        self.txtFilePathThree = wx.TextCtrl(self-1"")
        self.btnAddFileThree = wx.Button(self-1"Add File")
 
        self.label_4 = wx.StaticText(self-1"File Four         ")
        self.txtFilePathFour = wx.TextCtrl(self-1"")
        self.btnAddFileFour = wx.Button(self-1"Add File")
 
        self.label_5 = wx.StaticText(self-1"Backup Folder")
        self.txtBackupFilePath = wx.TextCtrl(self-1"")
        self.btnSelectBackupFolder = wx.Button(self-1"Select Folder")
 
        self.btnRunBackup = wx.Button(self-1"Run Backup")
 
        self.__set_properties()
        self.__do_layout()
 
        self.Bind(wx.EVT_BUTTONself.OnAddFileOneClickself.btnAddFileOne)
        self.Bind(wx.EVT_BUTTONself.OnAddFileTwoClickself.btnAddFileTwo)
        self.Bind(wx.EVT_BUTTONself.OnAddFileThreeClickself.btnAddFileThree)
        self.Bind(wx.EVT_BUTTONself.OnAddFileFourClickself.btnAddFileFour)
        self.Bind(wx.EVT_BUTTONself.OnSelectFolderClickself.btnSelectBackupFolder)
        self.Bind(wx.EVT_BUTTONself.OnRunBackupClickself.btnRunBackup)
 
    def __set_properties(self):
        # Create properties
        self.SetTitle("Back It Up")
 
 
    def __do_layout(self):
        # Create layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_7 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
 
        sizer_6.Add(self.label_10, wx.ALL3)
        sizer_6.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_6.Add(self.txtFilePathOne0, wx.ALL3)
        sizer_6.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_6.Add(self.btnAddFileOne0, wx.ALL3)
 
        sizer_1.Add(sizer_6, 1, wx.EXPAND0)
 
        sizer_2.Add(self.label_20, wx.ALL3)
        sizer_2.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_2.Add(self.txtFilePathTwo0, wx.ALL3)
        sizer_2.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_2.Add(self.btnAddFileTwo0, wx.ALL3)
 
        sizer_1.Add(sizer_2, 1, wx.EXPAND0)
 
        sizer_3.Add(self.label_30, wx.ALL3)
        sizer_3.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_3.Add(self.txtFilePathThree0, wx.ALL3)
        sizer_3.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_3.Add(self.btnAddFileThree0, wx.ALL3)
 
        sizer_1.Add(sizer_3, 1, wx.EXPAND0)
 
        sizer_4.Add(self.label_40, wx.ALL3)
        sizer_4.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_4.Add(self.txtFilePathFour0, wx.ALL3)
        sizer_4.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_4.Add(self.btnAddFileFour0, wx.ALL3)
 
        sizer_1.Add(sizer_4, 1, wx.EXPAND0)
 
        sizer_7.Add(self.label_50, wx.ALL3)
        sizer_7.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_7.Add(self.txtBackupFilePath0, wx.ALL3)
        sizer_7.Add((3030)0, wx.ADJUST_MINSIZE0)
        sizer_7.Add(self.btnSelectBackupFolder0, wx.ALL3)
 
        sizer_1.Add(sizer_7, 1, wx.EXPAND0)
        sizer_1.Add(self.btnRunBackup0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL3)
 
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
 
        self.Layout()
        self.Centre()
 
    #-------------------------------------------------------------------------
    # Event Handlers
 
    def OnAddFileOneClick(self, event):
        # Open file dialog and set path string in text box
        dlg = wx.FileDialog(self, message="Open a file...", defaultDir=os.getcwd(), defaultFile="", style=wx.OPEN)
        wildcard = "All files (*.*)|*.*"
        dlg.SetWildcard(wildcard)
 
        if dlg.ShowModal() == wx.ID_OK:
            filename = dlg.GetPath()
            self.txtFilePathOne.SetValue(filename)
            dlg.Destroy()
 
    def OnAddFileTwoClick(self, event):
        # Open file dialog and set path string in text box
        dlg = wx.FileDialog(self, message="Open a file...", defaultDir=os.getcwd(), defaultFile="", style=wx.OPEN)
        wildcard = "All files (*.*)|*.*"
        dlg.SetWildcard(wildcard)
 
        if dlg.ShowModal() == wx.ID_OK:
            filename = dlg.GetPath()
            self.txtFilePathTwo.SetValue(filename)
            dlg.Destroy()
 
    def OnAddFileThreeClick(self, event):
        # Open file dialog and set path string in text box
        dlg = wx.FileDialog(self, message="Open a file...", defaultDir=os.getcwd(), defaultFile="", style=wx.OPEN)
        wildcard = "All files (*.*)|*.*"
        dlg.SetWildcard(wildcard)
 
        if dlg.ShowModal() == wx.ID_OK:
            filename = dlg.GetPath()
            self.txtFilePathThree.SetValue(filename)
            dlg.Destroy()
 
    def OnAddFileFourClick(self, event):
        # Open file dialog and set path string in text box
        dlg = wx.FileDialog(self, message="Open a file...", defaultDir=os.getcwd(), defaultFile="", style=wx.OPEN)
        wildcard = "All files (*.*)|*.*"
        dlg.SetWildcard(wildcard)
 
        if dlg.ShowModal() == wx.ID_OK:
            filename = dlg.GetPath()
            self.txtFilePathFour.SetValue(filename)
            dlg.Destroy()
 
    def OnSelectFolderClick(self, event):
        # Open file dialog and set path string in text box
        dlg = wx.FileDialog(self, message="Open a file...", defaultDir=os.getcwd(), defaultFile="", style=wx.OPEN)
        wildcard = "All files (*.*)|*.*"
        dlg.SetWildcard(wildcard)
 
        if dlg.ShowModal() == wx.ID_OK:
            filename = dlg.GetPath()
            self.txtBackupFilePath.SetValue(filename)
            dlg.Destroy()
 
    def OnRunBackupClick(self, event):
        # Check for user errors and run backup
        source = [self.txtFilePathOne.GetValue()self.txtFilePathTwo.GetValue(),
                  self.txtFilePathThree.GetValue()self.txtFilePathFour.GetValue()]
 
        target_dir = self.txtBackupFilePath.GetValue()
 
        if len(target_dir) == 0:
            messageBox = wx.MessageBox('Please Enter Backup File Path''Error', wx.OK | wx.ICON_ERROR)
            app.MainLoop()
 
        target = target_dir + time.strftime('%Y_%m_%d') + '.tar.gz'
 
        for i in source:
            backup = 'tar -cvzf %s %s' % (target, ' '.join(source[:-1]))
 
        if os.system(backup) == 0:
            messageBox = wx.MessageBox('Backup Was Successful''Error', wx.OK | wx.ICON_EXCLAMATION)
        else:
            messageBox = wx.MessageBox('ERROR: Backup Failed''Error', wx.OK | wx.ICON_ERROR)
 
if __name__ == "__main__":
    # Create app and frame objects and send into main loop
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    MainFrame = MyFrame(None-1"")
    app.SetTopWindow(MainFrame)
    MainFrame.Show()
    app.MainLoop()