-
Notifications
You must be signed in to change notification settings - Fork 8
/
makerFtpBrowser.py
executable file
·256 lines (228 loc) · 11 KB
/
makerFtpBrowser.py
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import wx
from makerWidgets import MakerDialog
import makerFtpTools
import os
class FTPBrowser(MakerDialog):
def __init__(self, parent):
print 'initializing ftp Browser...'
self.saved = False
self.parent = parent
self.createDialog(self.parent)
self.pathname = None
def createDialog(self, prnt):
MakerDialog.__init__(self,
{'name' : 'ftpBrowser',
'parent' : prnt,
'pos' : wx.Point(441, 187),
'size' : wx.Size(387, 501),
'style' : wx.DEFAULT_DIALOG_STYLE,
'title' : 'FTP Browser',
'clientSize' : wx.Size(387, 501),
'centerPos' : wx.BOTH})
# ----- LIST BOX -----
self.listBox = self.add('listbox', {'choices' : [],
'name' : 'listBox',
'parent' : self,
'pos' : wx.Point(0, 53),
'size' : wx.Size(385, 352),
'style' : 0,
'handler' : self.ftpBrowserAction_select_})
# ----- WINDOW 1 -----
self.win1 = self.add('window', {'name' : 'win1',
'parent' : self,
'pos' : wx.Point(0, 0),
'size' : wx.Size(387, 50),
'style' : 0
})
# ----- WINDOW 2 -----
self.win2 = self.add('window', {'name' : 'win2',
'parent' : self,
'pos' : wx.Point(0, 405),
'size' : wx.Size(387, 50),
'style' : 0
})
# ----- OK BUTTON -----
self.OKbutton = self.add('button', {'label' : 'OK',
'name' : 'OK',
'parent' : self.win2,
'pos' : wx.Point(290, 60),
'size' : wx.Size(75, 25),
'style' : 0,
'handler' : self.ftpBrowserAction_Ok_})
# ----- CANCEL BUTTON -----
self.cancelButton = self.add('button', {'label' : 'Cancel',
'name' : 'cancel',
'parent' : self.win2,
'pos' : wx.Point(200, 60),
'size' : wx.Size(80, 25),
'style' : 0,
'handler' : self.ftpBrowserAction_cancel_})
# ----- NEW FOLDER BUTTON -----
self.newFolderButton = self.add('button', {'label' : 'New Folder',
'name' : 'newfolder',
'parent' : self.win1,
'pos' : wx.Point(280, 16),
'size' : wx.Size(90, 25),
'style' : 0,
'handler' : self.ftpBrowserAction_newFolder_})
# ----- DELETE BUTTON -----
self.deleteButton = self.add('button', {'label' : 'Delete',
'name' : 'delete',
'parent' : self.win1,
'pos' : wx.Point(200, 16),
'size' : wx.Size(75, 25),
'style' : 0,
'handler' : self.ftpBrowserAction_delete_})
# ----- HELP BUTTON -----
self.helpButton = self.add('button', {'label' : 'Help',
'name' : 'help',
'parent' : self.win2,
'pos' : wx.Point(8, 60),
'size' : wx.Size(75, 25),
'style' : 0,
'handler' : self.onHelpButton})
# ----- UP BUTTON -----
self.upButton = self.add('button', {'label' : 'Up',
'name' : 'up',
'parent' : self.win1,
'pos' : wx.Point(8, 16),
'size' : wx.Size(75, 25),
'style' : 0,
'handler' : self.ftpBrowserAction_up_})
self.createSizers()
def createSizers(self):
self.boxSizer = wx.BoxSizer(orient=wx.VERTICAL)
self.boxSizer.AddWindow(self.win1, 0, border=0, flag=wx.FIXED_MINSIZE)
self.boxSizer.AddWindow(self.listBox, 0, border=0, flag=wx.GROW)
self.boxSizer.AddWindow(self.win2, 1, border=0, flag=wx.FIXED_MINSIZE)
self.SetSizer(self.boxSizer)
def fillList(self, theList):
items = self.listBox.GetCount()
for i in range(items):
self.listBox.Delete(0)
for i in range(len(theList)):
self.listBox.Append(theList[i])
self.list = theList # save the list for later use
# make sure the first item in the list is visible
self.listBox.EnsureVisible(0)
def onHelpButton(self, event):
m = 'You can browse your server here as well as create/delete folders.'
m += " It is also possible to delete files..."
self.parent.Message(m)
def ftpBrowserAction_ls_(self):
"""Fills the ftpbrowser's listbox."""
self.parent.busy()
self.list = self.ftp_tools.ls()
if self.ftp_tools.pwd()==self.start:
try:
self.list.remove('..')
except:
print 'seems like really root'
self.fillList(self.list)
self.parent.relax()
def ftpBrowserAction_Ok_(self, event):
if self.listBox.GetSelection() == -1:
# 'no selection - taking current'
string = self.ftp_tools.pwd()
else:
# 'there is a selection...'
if self.ftp_tools.isdir(self.list[self.listBox.GetSelection()]):
# let's see if this works
string = self.ftp_tools.pwd() +"/"+ self.list[self.listBox.GetSelection()]
else:
string = self.ftp_tools.pwd()
self.pathname = string
self.saved = True
self.Close()
def ftpBrowserAction_delete_(self, event):
if self.listBox.GetSelection() == -1:
self.parent.Error('Please select an item')
return
theDir = self.list[self.listBox.GetSelection()]
if self.ftp_tools.isfile(self.ftp_tools.pwd(), theDir):
answer = self.parent.Ask('Do you really want to delete %s?' % theDir)
if answer == 'Ok':
res = self.ftp_tools.deleteFile(self.ftp_tools.pwd() + "/" + theDir)
if res != True:
self.parent.Error("Unable to delete file:\n" + str(res))
else:
answer = self.parent.Ask('Do you really want to delete %s ?' % theDir)
if answer == 'Ok':
result = self.ftp_tools.rmd(theDir)
if result != True:
self.parent.Error("Unable to delete folder:\n" + result)
self.ftpBrowserAction_ls_()
def ftpBrowserAction_newFolder_(self, event):
result = self.parent.Input('Please enter a name for the new folder:')
if result=="Null":
return
try:
self.ftp_tools.mkd(result)
self.ftpBrowserAction_ls_()
except Exception, e:
self.parent.Error("unable to create new folder!")
def ftpBrowserAction_select_(self, event):
item = self.listBox.GetSelection()
target = self.list[item]
try:
self.ftp_tools.cd(target)
except:
print "this is not a dir"
return
items = self.listBox.GetCount()
print items
for i in range(items):
self.listBox.Delete(0)
self.ftpBrowserAction_ls_()
def ftpBrowserAction_up_(self, event):
try:
self.ftp_tools.cd('..')
except Exception, e:
self.parent.Error('You cannot go up! ' + str(e))
self.ftpBrowserAction_ls_()
def ftpBrowserAction_cancel_(self, event):
self.saved = False
self.ftp_tools.logout()
self.Close()
def ftpBrowserAction_connect_(self, host, user, root, password):
"""
before calling this method you have to use
actionLoadPassword
returns True or False
"""
self.parent.busy()
try:
self.ftp_tools = makerFtpTools.Browser(host, root, user, password)
except Exception, e:
if "550" in str(e):
self.parent.Error("Unable to connect! Root folder '" + root + "' does not exist!\n Using the servers default folder instead...")
try:
self.ftp_tools = makerFtpTools.Browser(host, ".", user, password)
except Exception, e:
self.parent.Error('unable to connect ! Check your settings...' + str(e))
self.Destroy()
self.parent.relax()
return False
try:
self.start = self.ftp_tools.pwd()
except:
self.parent.Message("unable to read root")
if self.ftp_tools.pwd() == self.start:
try:
self.list.remove('..')
except:
print 'seems to be really root !'
self.parent.relax()
return True
def ftpBrowserShow(self):
# this works
try:
self.ShowModal()
finally:
if self.saved:
path = self.pathname
self.Destroy()
return path
else:
self.Destroy()
return None