-
Notifications
You must be signed in to change notification settings - Fork 8
/
makerEditDistributionData.py
executable file
·220 lines (174 loc) · 7.52 KB
/
makerEditDistributionData.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
import makerController
import makerDistEditor
import os
from makerUtilities import readFile, writeFile
import makerDefaultRemoteFolderEditor
import urlparse
class Controller(makerController.SuperController):
def drawDialog(self):
data = self.model.project.readDistributionTable()
self.dlg = makerDistEditor.DistributionTableEditor(self.view, data)
self.saveOldData(data)
self.itemsColors = {}
self.markConflicts()
self.dlg.Bind(self.view.wx.EVT_LIST_ITEM_SELECTED, self.checkAgain)
self.dlg.Bind(self.view.wx.EVT_LIST_BEGIN_LABEL_EDIT, self.validateColumn)
self.dlg.Bind(self.view.wx.EVT_LIST_END_LABEL_EDIT, self.endEdit)
self.dlg.defaultFolderButton.Bind(
self.view.wx.EVT_BUTTON, self.editDefaultRemoteFolders
)
self.dlg.ShowModal()
if self.dlg.saved:
self.model.project.writeDistributionTable(self.dlg.data)
if not self.model.project.checkIfProjectIsSetUp():
# save data
print "No cleanup necessary - project not set up"
return
self.model.project.serverLogin()
if not self.model.project.server.status == "connected":
self.dlg.Destroy()
else:
self.model.compareDataForCleanup(self.dlg.oldDistData, self.dlg.data)
# Task compare data sets for changes
self.dlg.Destroy()
else:
self.dlg.Destroy()
def editDefaultRemoteFolders(self, event):
data = self.model.project.readDefaultFoldersFile()
default = makerDefaultRemoteFolderEditor.DefRemFolderEditor(self.view, data)
default.ShowModal()
if default.saved:
self.model.project.writeDefaultFoldersFile(default.data)
default.Destroy()
else:
default.Destroy()
def endEdit(self, evt):
# we bind the evnt only after the edit has been made otherwise it will
# seriously slow down the app
# self.validateColumn(evt)
self.dlg.Bind(self.view.wx.EVT_UPDATE_UI, self.checkAgain)
# after markConflicts is finished this event is unbound
def validateColumn(self, evt):
print "validating column"
m = "You may only edit the 'Remote Dir' and the 'Remote File' column!"
if evt.GetColumn() == 0:
self.infoMessage(m)
evt.Veto()
elif evt.GetColumn() == 2:
self.infoMessage(m)
evt.Veto()
def checkAgain(self, evt):
self.resetItemBackgrounds()
self.markConflicts()
def saveOldData(self, oldData):
self.dlg.oldDistData = oldData
def readOldData(self):
return self.dlg.oldDistData
def markConflicts(self, event=None):
# unbind event until the next edit
self.dlg.Unbind(self.view.wx.EVT_UPDATE_UI)
markedItems = []
for conflict in self.getFilesWithConflicts():
item = self.dlg.listCtrl.FindItem(0, conflict)
markedItems.append(item)
self.itemsColors[item] = self.dlg.listCtrl.GetItemBackgroundColour(item)
self.dlg.listCtrl.SetItemBackgroundColour(item, self.view.wx.RED)
self.dlg.markedItems = markedItems
def getFilesWithConflicts(self):
conflicts = []
for f in self.getListOfRemoteFolders():
list = self.getConflictFilesForFolder(f)
if list != []:
for item in list:
conflicts.append(item)
return conflicts
def getListOfRemoteFolders(self):
listOfFolders = []
for dataSet in self.dlg.readData():
if listOfFolders.count(dataSet["remote_dir"]) == 0:
listOfFolders.append(dataSet["remote_dir"])
return listOfFolders
def getConflictFilesForFolder(self, folder):
conflictFiles = []
files = []
for dataSet in self.dlg.readData():
if dataSet["remote_dir"] == folder:
files.append(dataSet["target"])
if files.count(dataSet["target"]) > 1:
for otherDataSet in self.dlg.readData():
if otherDataSet["target"] == dataSet["target"]:
if not conflictFiles.count(otherDataSet["ftp_source"]) >= 1:
conflictFiles.append(otherDataSet["ftp_source"])
return conflictFiles
def resetItemBackgrounds(self):
for item in self.dlg.markedItems:
# due to some odd behavior in wxPython we have to set to white first
# before we can use another custom color
self.dlg.listCtrl.SetItemBackgroundColour(item, self.view.wx.WHITE)
self.dlg.listCtrl.SetItemBackgroundColour(item, self.itemsColors[item])
# ----
self.dlg.markedItems = []
class EditDistributionData:
def __init__(self, mainView, project):
self.projectController = project.projectController
self.project = project
self.controller = Controller(self, mainView)
self.controller.drawDialog()
def compareDataForCleanup(self, oldData, newData):
toCleanup = []
for theOldDataSet in oldData:
fileToCompare = theOldDataSet["ftp_source"]
for newDataSet in newData:
if newDataSet["ftp_source"] == fileToCompare:
if newDataSet["remote_dir"] == theOldDataSet["remote_dir"]:
pass
else:
# folder name has changed
toCleanup.append(
(
(theOldDataSet["remote_dir"], theOldDataSet["target"]),
(newDataSet["remote_dir"], newDataSet["target"]),
)
)
if newDataSet["target"] == theOldDataSet["target"]:
pass
else:
# target name has changed
toCleanup.append(
(
(theOldDataSet["remote_dir"], theOldDataSet["target"]),
(newDataSet["remote_dir"], newDataSet["target"]),
)
)
self.cleanup(toCleanup)
def cleanup(self, toCleanup):
self.controller.showProgress(
limit=1, Message="Please wait...", title="Cleaning Up"
)
runs = 1
for x in toCleanup:
target = x[1]
source = x[0]
if not source[0].endswith("/"):
finalSourceFolder = source[0] + "/"
else:
finalSourceFolder = source[0]
if not target[0].endswith("/"):
finalTargetFolder = target[0] + "/"
else:
finalTargetFolder = target[0]
self.controller.updateProgressPulse("Please wait...")
if self.project.checkIfRemoteDirIsDir(finalTargetFolder):
self.project.renameRemoteFile(
urlparse.urljoin(finalSourceFolder, source[1]),
urlparse.urljoin(finalTargetFolder, target[1]),
)
else:
self.project.makeRemoteDir(finalTargetFolder)
self.project.renameRemoteFile(
urlparse.urljoin(finalSourceFolder, source[1]),
urlparse.urljoin(finalTargetFolder, target[1]),
)
runs += 1
self.controller.killProgressBar()
self.project.serverLogout()