18
|
1 import wx
|
|
2 import sys
|
|
3 import os #just .sep maybe
|
14
|
4 import manifest
|
|
5 import shutil
|
18
|
6
|
|
7 from orpg.orpgCore import component
|
|
8 from orpg.dirpath import dir_struct
|
|
9 from orpg.tools.orpg_log import logger, crash
|
|
10 from orpg.tools.decorators import debugging
|
|
11 from upmana.validate import validate
|
|
12 from orpg.dirpath import dir_struct
|
17
|
13 from mercurial import ui, hg, commands, repo, revlog, cmdutil, util
|
14
|
14
|
|
15
|
|
16 class Updater(wx.Panel):
|
18
|
17 @debugging
|
|
18 def __init__(self, parent, component, manifest):
|
14
|
19 wx.Panel.__init__(self, parent)
|
|
20
|
|
21 ### Update Manager
|
|
22 self.ui = ui.ui()
|
|
23 self.repo = hg.repository(self.ui, ".")
|
|
24 self.c = self.repo.changectx('tip')
|
|
25 self.manifest = manifest
|
18
|
26 self.parent = parent
|
14
|
27 self.SetBackgroundColour(wx.WHITE)
|
|
28 self.sizer = wx.GridBagSizer(hgap=1, vgap=1)
|
17
|
29 self.changelog = wx.TextCtrl(self, wx.ID_ANY, size=(325, -1), style=wx.TE_MULTILINE | wx.TE_READONLY)
|
|
30 self.filelist = wx.TextCtrl(self, wx.ID_ANY, size=(275, 300), style=wx.TE_MULTILINE | wx.TE_READONLY)
|
14
|
31 self.buttons = {}
|
|
32 self.buttons['progress_bar'] = wx.Gauge(self, wx.ID_ANY, 100)
|
|
33 self.buttons['auto_text'] = wx.StaticText(self, wx.ID_ANY, "Auto Update")
|
|
34 self.buttons['auto_check'] = wx.CheckBox(self, wx.ID_ANY)
|
|
35 self.buttons['no_text'] = wx.StaticText(self, wx.ID_ANY, "No Update")
|
|
36 self.buttons['no_check'] = wx.CheckBox(self, wx.ID_ANY)
|
|
37 self.buttons['advanced'] = wx.Button(self, wx.ID_ANY, "Package Select")
|
|
38 self.buttons['update'] = wx.Button(self, wx.ID_ANY, "Update Now")
|
|
39 self.buttons['finish'] = wx.Button(self, wx.ID_ANY, "Finish")
|
|
40
|
|
41 self.sizer.Add(self.changelog, (0,0), span=(4,1), flag=wx.EXPAND)
|
|
42 self.sizer.Add(self.filelist, (0,1), span=(1,3), flag=wx.EXPAND)
|
|
43
|
|
44 self.sizer.Add(self.buttons['progress_bar'], (1,1), span=(1,3), flag=wx.EXPAND)
|
|
45 self.sizer.Add(self.buttons['auto_text'], (2,1))
|
|
46 self.sizer.Add(self.buttons['auto_check'], (2,2), flag=wx.EXPAND)
|
|
47 self.sizer.Add(self.buttons['no_text'], (3,1))
|
|
48 self.sizer.Add(self.buttons['no_check'], (3,2), flag=wx.EXPAND)
|
|
49 self.sizer.Add(self.buttons['advanced'], (2,3), flag=wx.EXPAND)
|
|
50 self.sizer.Add(self.buttons['update'], (3,3), flag=wx.EXPAND)
|
|
51 self.sizer.Add(self.buttons['finish'], (4,3), flag=wx.EXPAND)
|
|
52 self.buttons['finish'].Disable()
|
|
53 self.sizer.AddGrowableCol(0)
|
|
54 self.sizer.AddGrowableRow(0)
|
|
55 self.SetSizer(self.sizer)
|
|
56 self.SetAutoLayout(True)
|
|
57 self.get_package
|
|
58
|
|
59 self.current = self.repo.dirstate.branch()
|
|
60 self.BranchInfo(self.current)
|
|
61
|
|
62 if self.manifest.GetString("updatemana", "no_update", "") == 'on': self.buttons['no_check'].SetValue(True)
|
|
63 else: self.buttons['no_check'].SetValue(False)
|
|
64 if self.manifest.GetString("updatemana", "auto_update", "") == 'on': self.buttons['auto_check'].SetValue(True)
|
|
65 else: self.buttons['auto_check'].SetValue(False)
|
|
66
|
|
67 ## Event Handlers
|
|
68 self.Bind(wx.EVT_BUTTON, self.Update, self.buttons['update'])
|
|
69 self.Bind(wx.EVT_BUTTON, self.Finish, self.buttons['finish'])
|
|
70 self.Bind(wx.EVT_BUTTON, self.ChooseBranch, self.buttons['advanced'])
|
|
71 self.Bind(wx.EVT_CHECKBOX, self.ToggleAutoUpdate, self.buttons['auto_check'])
|
|
72 self.Bind(wx.EVT_CHECKBOX, self.ToggleNoUpdate, self.buttons['no_check'])
|
|
73
|
|
74 def ToggleAutoUpdate(self, event):
|
|
75 if self.buttons['auto_check'].GetValue() == True:
|
|
76 if self.buttons['no_check'].GetValue() == True:
|
|
77 self.buttons['no_check'].SetValue(False)
|
|
78 self.manifest.SetString("updatemana", "no_update", "off")
|
|
79 self.manifest.SetString("updatemana", "auto_update", "on")
|
|
80 else: self.manifest.SetString("updatemana", "auto_update", "off")
|
|
81
|
|
82 def ToggleNoUpdate(self, event):
|
|
83 if self.buttons['no_check'].GetValue() == True:
|
|
84 if self.buttons['auto_check'].GetValue() == True:
|
|
85 self.buttons['auto_check'].SetValue(False)
|
|
86 self.manifest.SetString("updatemana", "auto_update", "off")
|
|
87 self.manifest.SetString("updatemana", "no_update", "on")
|
|
88 else: self.manifest.SetString("updatemana", "no_update", "off")
|
|
89
|
|
90 def Update(self, evt=None):
|
|
91 self.ui = ui.ui()
|
|
92 self.repo = hg.repository(self.ui, ".")
|
|
93 self.c = self.repo.changectx('tip')
|
|
94 filename = 'ignorelist.txt'
|
18
|
95 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename
|
|
96 component.get('validate').config_file(filename, "default_ignorelist.txt")
|
14
|
97 self.mana = self.LoadDoc()
|
18
|
98 temp = dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep
|
14
|
99 for ignore in self.ignorelist:
|
18
|
100 shutil.copy(ignore, temp + ignore.split('/')[len(ignore.split('/')) - 1])
|
14
|
101 hg.clean(self.repo, self.current)
|
|
102 for ignore in self.ignorelist:
|
18
|
103 shutil.copyfile(temp + ignore.split('/')[len(ignore.split('/')) - 1], ignore)
|
|
104 os.remove(temp + ignore.split('/')[len(ignore.split('/')) - 1])
|
14
|
105
|
|
106 def LoadDoc(self):
|
|
107 ignore = open(self.filename)
|
|
108 self.ignorelist = []
|
|
109 for i in ignore: self.ignorelist.append(str(i [:len(i)-1]))
|
|
110 manifest = ignore.readlines()
|
|
111 ignore.close()
|
|
112
|
|
113 def Finish(self, evt=None):
|
|
114 try: self.parent.Destroy()
|
|
115 except:
|
|
116 print 'Fail'; exit()
|
|
117
|
|
118 def ChooseBranch(self, evt=None):
|
|
119 dlg = wx.Dialog(self, wx.ID_ANY, "Package Selector", style=wx.DEFAULT_DIALOG_STYLE)
|
18
|
120 if wx.Platform == '__WXMSW__': icon = wx.Icon(dir_struct["icon"]+'d20.ico', wx.BITMAP_TYPE_ICO)
|
|
121 else: icon = wx.Icon(dir_struct["icon"]+"d20.xpm", wx.BITMAP_TYPE_XPM )
|
14
|
122 dlg.SetIcon(icon)
|
|
123
|
|
124 self.ui = ui.ui()
|
|
125 self.repo = hg.repository(self.ui, ".")
|
|
126 self.c = self.repo.changectx('tip')
|
|
127
|
|
128 dlgsizer = wx.GridBagSizer(hgap=1, vgap=1)
|
|
129 Yes = wx.Button( dlg, wx.ID_OK, "Ok" )
|
|
130 Yes.SetDefault()
|
|
131 rgroup = wx.RadioButton(dlg, wx.ID_ANY, "group_start", style=wx.RB_GROUP)
|
|
132 rgroup.Hide()
|
|
133
|
|
134 self.get_packages()
|
|
135 if self.package_list == None: return
|
|
136 types = self.package_list
|
|
137 row=0; col=0
|
|
138 self.current = self.repo.dirstate.branch()
|
|
139 self.package_type = self.current
|
|
140 self.btnlist = {}; self.btn = {}
|
|
141 self.id = 1
|
|
142
|
|
143 for t in types:
|
|
144 self.btnName = str(t)
|
|
145 self.btn[self.id] = wx.RadioButton(dlg, wx.ID_ANY, str(t), name=self.btnName)
|
|
146 if self.btnName == self.current: self.btn[self.id].SetValue(True)
|
|
147 self.btnlist[self.id] = self.btnName
|
|
148 dlgsizer.Add(self.btn[self.id], (row, col))
|
|
149 col += 1; self.id += 1
|
|
150 if col == 3: row += 1; col = 0
|
|
151
|
|
152 dlgsizer.Add(Yes, (row+1,col/2))
|
|
153 dlgsizer.AddGrowableCol(0)
|
|
154 dlgsizer.AddGrowableRow(0)
|
|
155 dlg.SetAutoLayout( True )
|
|
156 dlg.SetSizer( dlgsizer )
|
|
157 dlgsizer.Fit( dlg )
|
|
158 dlg.Centre()
|
|
159 dlg.Bind(wx.EVT_RADIOBUTTON, self.PackageSet)
|
|
160 if dlg.ShowModal(): dlg.Destroy()
|
|
161
|
|
162 def PackageSet(self, event):
|
|
163 for btn in self.btn:
|
|
164 if self.btn[btn].GetValue() == True: self.current = self.btnlist[btn]
|
|
165
|
|
166 branches = self.repo.branchtags()
|
|
167 heads = dict.fromkeys(self.repo.heads(), 1)
|
|
168 l = [((n in heads), self.repo.changelog.rev(n), n, t) for t, n in branches.items()]
|
|
169
|
|
170 if self.current != type:
|
|
171 heads = dict.fromkeys(self.repo.heads(), self.repo.branchtags())
|
|
172 branches = dict.copy(self.repo.branchtags())
|
|
173 self.BranchInfo(self.current)
|
|
174
|
|
175 def BranchInfo(self, branch):
|
17
|
176 cs = self.repo.changectx( self.current ).changeset()
|
14
|
177 self.changelog.SetValue('')
|
17
|
178 changelog = cs[4]
|
14
|
179 self.changelog.AppendText(changelog + '\n')
|
17
|
180 self.filelist.SetValue('')
|
18
|
181 self.filelist.AppendText("Currently selected branch: " + branch + "\n\nAuthor: "+cs[1]+"\n\n")
|
|
182 self.filelist.AppendText("Files Modified (in update): \n")
|
17
|
183 for f in cs[3]: self.filelist.AppendText(f+"\n")
|
14
|
184
|
|
185 def get_packages(self, type=None):
|
|
186 #Fixed and ready for Test. Can be cleaner
|
|
187 self.package_list = []
|
|
188 b = self.repo.branchtags()
|
17
|
189 heads = dict.fromkeys(self.repo.heads(), 1) #The code below looks superfluous but there is good info inside
|
14
|
190 l = [((n in heads), self.repo.changelog.rev(n), n, t) for t, n in b.items()]
|
|
191 l.sort()
|
|
192 l.reverse()
|
|
193 for ishead, r, n, t in l: self.package_list.append(t)
|
|
194
|
|
195 def get_package(self):
|
|
196 self.get_packages()
|
|
197 if self.package_list == None: return None
|
|
198 return None
|
|
199
|
|
200 class Repos(wx.Panel):
|
|
201 def __init__(self, parent, openrpg, manifest):
|
|
202 wx.Panel.__init__(self, parent)
|
|
203
|
|
204 ### Update Manager
|
|
205 self.ui = ui.ui()
|
|
206 self.r = hg.repository(self.ui, ".")
|
|
207 self.c = self.r.changectx('tip')
|
|
208
|
|
209 #mainpanel = self
|
|
210 self.openrpg = openrpg
|
|
211 self.manifest = manifest
|
|
212 self.buttons = {}
|
|
213 self.texts = {}
|
|
214
|
|
215 ## Section Sizers (with frame edges and text captions)
|
|
216 self.box_sizers = {}
|
|
217 self.box_sizers["newbutton"] = wx.StaticBox(self, -1)
|
|
218
|
|
219 ## Layout Sizers
|
|
220 self.sizers = {}
|
|
221 self.sizers["main"] = wx.GridBagSizer(hgap=2, vgap=2)
|
|
222 self.sizers["button"] = wx.GridBagSizer(hgap=2, vgap=2)
|
|
223
|
|
224 #Button Layout
|
|
225 self.sizers["newbutton"] = wx.StaticBoxSizer(self.box_sizers["newbutton"], wx.VERTICAL)
|
|
226 self.sizers["newrepo_layout"] = wx.FlexGridSizer(rows=1, cols=2, hgap=2, vgap=5)
|
|
227 empty = wx.StaticText(self, -1, "")
|
|
228 reponame = wx.StaticText(self, -1, "Name:")
|
|
229 self.texts["reponame"] = wx.TextCtrl(self, -1, '')
|
|
230 self.buttons['addrepo'] = wx.Button(self, wx.ID_NEW)
|
|
231
|
|
232 ##Build Button
|
|
233 self.sizers["newrepo_layout"].Add(self.buttons['addrepo'], -1, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
|
|
234 self.sizers["newrepo_layout"].Add(empty, -1)
|
|
235 self.sizers["newrepo_layout"].Add(reponame, -1, wx.ALIGN_CENTER|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
|
|
236 self.sizers["newrepo_layout"].Add(self.texts["reponame"], -1, wx.EXPAND)
|
|
237 self.sizers["newrepo_layout"].AddGrowableCol(1)
|
|
238 self.sizers["newbutton"].Add(self.sizers["newrepo_layout"], -1, wx.EXPAND)
|
17
|
239
|
14
|
240 #Repo List Panel
|
|
241 self.repopanel = wx.ScrolledWindow(self)
|
|
242 self.repopanel.SetScrollbars(20,20,55,40)
|
|
243 self.repopanel.Scroll(50,10)
|
|
244 self.box_sizers["repolist"] = wx.StaticBox(self.repopanel, -1, "Current Repo List")
|
|
245 self.sizers["repolist"] = wx.StaticBoxSizer(self.box_sizers["repolist"], wx.VERTICAL)
|
|
246 self.sizers["repo"] = wx.GridBagSizer(hgap=2, vgap=2)
|
|
247 self.sizers["repolist_layout"] = wx.FlexGridSizer(rows=1, cols=1, hgap=2, vgap=5)
|
|
248 self.manifest = manifest
|
|
249
|
|
250 self.NewRepoList(None)
|
|
251 self.BuildRepoList(None)
|
|
252
|
|
253 self.sizers["repolist_layout"].AddGrowableCol(0)
|
|
254 self.sizers["repolist"].Add(self.sizers["repolist_layout"], -1, wx.EXPAND)
|
|
255 self.sizers["repo"].Add(self.sizers["repolist"], (0,0), flag=wx.EXPAND)
|
|
256 self.sizers["repo"].AddGrowableCol(0)
|
|
257 self.sizers['repo'].AddGrowableRow(0)
|
|
258 self.sizers['repo'].AddGrowableRow(1)
|
|
259 self.repopanel.SetSizer(self.sizers['repo'])
|
|
260 self.repopanel.SetAutoLayout(True)
|
|
261
|
|
262 #Build Main Sizer
|
|
263 self.sizers["main"].Add(self.sizers["newbutton"], (0,0), flag=wx.EXPAND)
|
|
264 self.sizers["main"].Add(self.repopanel, (1,0), flag=wx.EXPAND)
|
|
265 self.sizers["main"].AddGrowableCol(0)
|
|
266 self.sizers["main"].AddGrowableCol(1)
|
|
267 self.sizers["main"].AddGrowableRow(1)
|
|
268 self.SetSizer(self.sizers["main"])
|
|
269 self.SetAutoLayout(True)
|
|
270 self.Fit()
|
|
271 self.Bind(wx.EVT_BUTTON, self.AddRepo, self.buttons['addrepo'])
|
|
272
|
|
273 def NewRepoList(self, event):
|
|
274 self.id = -1; self.box = {}; self.box_name= {}; self.main = {}; self.container = {}; self.layout = {}
|
|
275 self.name = {}; self.url = {}; self.url_list = {}; self.pull = {}; self.uri = {}; self.delete = {}
|
|
276 self.defaultcheck = {}; self.default = {}; self.repotrac = {}
|
|
277 self.pull_list = {}; self.delete_list = {}; self.defchecklist = {}
|
|
278
|
|
279 def BuildRepoList(self, event):
|
|
280 self.repolist = self.manifest.GetList('UpdateManifest', 'repolist', '')
|
|
281 try: self.repolist = self.repo
|
|
282 except: pass
|
|
283
|
|
284 #wx.Yeild() For future refrence.
|
|
285
|
|
286 for repo in self.repolist:
|
|
287 self.id += 1
|
|
288 #Build Constructs
|
|
289 self.box[self.id] = wx.StaticBox(self.repopanel, -1, str(repo))
|
|
290 self.main[self.id] = wx.GridBagSizer(hgap=2, vgap=2)
|
|
291 self.container[self.id] = wx.StaticBoxSizer(self.box[self.id], wx.VERTICAL)
|
|
292 self.layout[self.id] = wx.FlexGridSizer(rows=1, cols=4, hgap=2, vgap=5)
|
|
293 self.name[self.id] = wx.StaticText(self.repopanel, -1, 'URL')
|
|
294 self.uri[self.id] = self.manifest.GetString('updaterepo', repo, '')
|
|
295 self.url[self.id] = wx.TextCtrl(self.repopanel, -1, self.uri[self.id])
|
|
296 self.pull[self.id] = wx.Button(self.repopanel, wx.ID_REFRESH)
|
|
297 self.delete[self.id] = wx.Button(self.repopanel, wx.ID_DELETE)
|
|
298 self.delete_list[self.delete[self.id]] = self.id
|
|
299 self.defaultcheck[self.id] = wx.CheckBox(self.repopanel, -1)
|
|
300 self.default[self.id] = wx.StaticText(self.repopanel, -1, 'Default')
|
|
301 #Build Retraceables
|
|
302 self.box_name[self.id] = str(repo)
|
|
303 self.pull_list[self.pull[self.id]] = self.id
|
|
304 self.defchecklist[self.defaultcheck[self.id]] = self.id
|
|
305 #Build Layout
|
|
306 self.layout[self.id].Add(self.name[self.id], -1, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
|
|
307 self.layout[self.id].Add(self.url[self.id], -1, wx.EXPAND)
|
|
308 self.layout[self.id].Add(self.pull[self.id], -1, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
|
|
309 self.layout[self.id].Add(self.delete[self.id], -1, wx.EXPAND)
|
|
310 self.layout[self.id].Add(self.defaultcheck[self.id], -1, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
|
|
311 self.layout[self.id].Add(self.default[self.id], -1, wx.EXPAND)
|
|
312 self.layout[self.id].AddGrowableCol(1)
|
|
313 self.container[self.id].Add(self.layout[self.id], -1, wx.EXPAND)
|
|
314 #Button Events
|
|
315 self.Bind(wx.EVT_BUTTON, self.RefreshRepo, self.pull[self.id])
|
|
316 self.Bind(wx.EVT_BUTTON, self.DelRepo, self.delete[self.id])
|
|
317 self.Bind(wx.EVT_CHECKBOX, self.SetDefault, self.defaultcheck[self.id])
|
|
318 self.sizers["repolist_layout"].Insert(0, self.container[self.id], -1, wx.EXPAND)
|
|
319 self.sizers['repolist_layout'].Layout()
|
|
320
|
|
321 #Set Default Repo Button
|
|
322 capture = self.manifest.GetString('updaterepo', 'default', '')
|
|
323 if capture != '':
|
|
324 for caught in self.uri:
|
|
325 if capture == self.uri[caught]: self.id = caught; pass
|
|
326 else: continue
|
|
327 self.defaultcheck[self.id].SetValue(True)
|
|
328
|
|
329 def AddRepo(self, event):
|
|
330 repo = self.texts['reponame'].GetValue(); repo = repo.replace(' ', '_'); repo = 'repo-' + repo
|
|
331 self.manifest.SetString('updaterepo', repo, ''); self.repo = repo.split(',')
|
|
332 repolist = self.manifest.GetList('UpdateManifest', 'repolist', '')
|
|
333 if repolist == '': pass
|
|
334 else: repolist = repolist + self.repo
|
|
335 self.manifest.SetList('UpdateManifest', 'repolist', repolist)
|
|
336 self.BuildRepoList(None)
|
|
337
|
|
338 def DelRepo(self, event):
|
|
339 self.id = self.delete_list[event.GetEventObject()]
|
|
340 self.sizers["repolist_layout"].Hide(self.container[self.id])
|
|
341 try: del self.box_name[self.id]
|
|
342 except: pass
|
|
343 self.manifest.SetList('UpdateManifest', 'repolist', list(self.box_name.values()))
|
|
344 self.sizers['repolist_layout'].Layout()
|
|
345
|
|
346 def RefreshRepo(self, event):
|
|
347 self.id = self.pull_list[event.GetEventObject()]
|
|
348 self.manifest.SetString('updaterepo', str(self.box_name[self.id]), self.url[self.id].GetValue())
|
|
349 try: commands.pull(self.ui, self.r, self.url[self.id].GetValue(), rev='', update=False, force=True)
|
|
350 except: pass
|
|
351
|
|
352 def SetDefault(self, event):
|
|
353 self.id = self.defchecklist[event.GetEventObject()]
|
|
354 self.manifest.SetString('updaterepo', 'default', self.uri[self.id])
|
|
355 for all in self.defaultcheck:
|
|
356 self.defaultcheck[all].SetValue(False)
|
|
357 self.defaultcheck[self.id].SetValue(True)
|
|
358
|
|
359 class Manifest(wx.Panel):
|
|
360 def __init__(self, parent):
|
|
361 wx.Panel.__init__(self, parent)
|
|
362 self.ui = ui.ui()
|
|
363 self.repo = hg.repository(self.ui, ".")
|
|
364 self.c = self.repo.changectx('tip')
|
|
365 self.manifestlist = []
|
|
366 self.manifestlist = self.c.manifest().keys()
|
|
367 for mana in self.manifestlist: mana = os.sep + 'orpg' + os.sep + mana
|
|
368 self.manifestlist.sort()
|
|
369 self.SetBackgroundColour(wx.WHITE)
|
|
370 self.sizer = wx.GridBagSizer(hgap=1, vgap=1)
|
18
|
371 self.manifestlog = wx.CheckListBox( self, -1, wx.DefaultPosition, wx.DefaultSize,
|
|
372 self.manifestlist, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES)
|
14
|
373 filename = 'ignorelist.txt'
|
18
|
374 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename
|
|
375 component.get('validate').config_file(filename, "default_ignorelist.txt")
|
14
|
376 self.mana = self.LoadDoc()
|
|
377 self.manifestlog.Bind(wx.EVT_CHECKLISTBOX, self.GetChecked)
|
|
378 self.sizer.Add(self.manifestlog, (0,0), flag=wx.EXPAND)
|
|
379 self.sizer.AddGrowableCol(0)
|
|
380 self.sizer.AddGrowableRow(0)
|
|
381 self.SetSizer(self.sizer)
|
|
382 self.SetAutoLayout(True)
|
|
383
|
|
384 def GetChecked(self, event):
|
|
385 self.mana = []
|
|
386 for manifest in self.manifestlog.GetChecked(): self.mana.append(self.manifestlist[manifest])
|
|
387 self.SaveDoc()
|
|
388
|
|
389 def SaveDoc(self):
|
|
390 f = open(self.filename, "w")
|
|
391 for mana in self.mana: f.write(mana+'\n')
|
|
392 f.close()
|
|
393
|
|
394 def LoadDoc(self):
|
|
395 ignore = open(self.filename)
|
|
396 ignorelist = []
|
|
397 for i in ignore: ignorelist.append(str(i [:len(i)-1]))
|
|
398 for i in ignorelist: #Adds previously ignored files to manifestlistlog if they are not in changesets.
|
|
399 if self.c.manifest().has_key(i): continue
|
|
400 else: self.manifestlist.append(i); self.manifestlist.sort()
|
17
|
401 self.manifestlog = wx.CheckListBox( self, -1, wx.DefaultPosition, wx.DefaultSize, self.manifestlist,
|
|
402 wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES)
|
14
|
403 self.manifestlog.SetCheckedStrings(ignorelist)
|
|
404 manifest = ignore.readlines()
|
|
405 ignore.close()
|
|
406
|
|
407 class Control(wx.Panel):
|
|
408 def __init__(self, parent):
|
|
409 wx.Panel.__init__(self, parent)
|
18
|
410
|
|
411 ### Control Panel
|
|
412 self.ui = ui.ui()
|
|
413 self.repo = hg.repository(self.ui, ".")
|
|
414 self.c = self.repo.changectx('tip')
|
|
415 self.manifest = manifest
|
|
416 self.parent = parent
|
|
417 #logger.debug("Enter updaterFrame") #Need to set logging level
|
|
418
|
|
419 self.get_packages()
|
|
420 self.SetBackgroundColour(wx.WHITE)
|
|
421 self.sizer = wx.GridBagSizer(hgap=1, vgap=1)
|
|
422 self.buttons = {}
|
14
|
423
|
18
|
424 ## Changelog / File List
|
|
425 changelogcp = wx.Panel(self)
|
|
426 self.changelogcp = wx.GridBagSizer(hgap=1, vgap=1)
|
|
427 self.changelog = wx.TextCtrl(changelogcp, wx.ID_ANY, size=wx.DefaultSize, style=wx.TE_MULTILINE | wx.TE_READONLY)
|
|
428 self.filelist = wx.TextCtrl(changelogcp, wx.ID_ANY, size=wx.DefaultSize, style=wx.TE_MULTILINE | wx.TE_READONLY)
|
|
429 self.changelogcp.Add(self.changelog, (0,0), flag=wx.EXPAND)
|
|
430 self.changelogcp.Add(self.filelist, (1,0), flag=wx.EXPAND)
|
|
431 changelogcp.SetSizer(self.changelogcp)
|
|
432 self.changelogcp.AddGrowableCol(0)
|
|
433 self.changelogcp.AddGrowableRow(0)
|
|
434 self.changelogcp.AddGrowableRow(1)
|
|
435 changelogcp.SetAutoLayout(True)
|
|
436
|
|
437 ## Branches / Revisions
|
|
438 branchcp = wx.Panel(self)
|
|
439 self.branchcp = wx.GridBagSizer(hgap=1, vgap=1)
|
|
440 self.branches = wx.Choice(branchcp, wx.ID_ANY, choices=self.package_list)
|
|
441 self.branch_txt = wx.StaticText(branchcp, wx.ID_ANY, "Branches")
|
|
442 self.branchcp.Add(self.branches, (0,0))
|
|
443 self.branchcp.Add(self.branch_txt, (0,1), flag=wx.ALIGN_CENTER_VERTICAL)
|
|
444 branchcp.SetSizer(self.branchcp)
|
|
445 branchcp.SetAutoLayout(True)
|
|
446
|
|
447 revlistcp = wx.Panel(self)
|
|
448 self.revlistcp = wx.GridBagSizer(hgap=2, vgap=2)
|
|
449 self.revlist = wx.ListCtrl(revlistcp, -1, wx.DefaultPosition, size=wx.DefaultSize,
|
|
450 style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_HRULES)
|
|
451 self.revlist.InsertColumn(0, 'Revs')
|
|
452 self.revlist.InsertColumn(1, 'Changeset')
|
|
453 self.revlist.SetColumnWidth(0, -1)
|
|
454 self.revlist.SetColumnWidth(1, -1)
|
|
455 self.revlist.Refresh()
|
|
456 self.revlistcp.Add(self.revlist, (0,0), flag=wx.EXPAND)
|
|
457 revlistcp.SetSizer(self.revlistcp)
|
|
458 self.revlistcp.AddGrowableCol(0)
|
|
459 self.revlistcp.AddGrowableRow(0)
|
|
460 self.revlistcp.AddGrowableRow(1)
|
|
461 revlistcp.SetAutoLayout(True)
|
|
462
|
|
463 ## Control Panel
|
|
464 cp = wx.Panel(self)
|
|
465 self.cp = wx.GridBagSizer(hgap=1, vgap=1)
|
|
466 self.buttons['update'] = wx.Button(cp, wx.ID_ANY, "Revision Update")
|
|
467 self.buttons['delete'] = wx.Button(cp, wx.ID_ANY, "Delete Branch")
|
|
468 self.cp.Add(self.buttons['update'], (0,0))
|
|
469 self.cp.Add(self.buttons['delete'], (0,1))
|
|
470 cp.SetSizer(self.cp)
|
|
471 cp.SetAutoLayout(True)
|
|
472
|
|
473 self.sizer.Add(changelogcp, (0,0), span=(3,1), flag=wx.EXPAND)
|
|
474 self.sizer.Add(branchcp, (0,1), span=(1,1))
|
|
475 self.sizer.Add(revlistcp, (2,1), span=(1,1), flag=wx.EXPAND)
|
|
476 self.sizer.Add(cp, (1,1), span=(1,1))
|
|
477
|
|
478 self.buttons['delete'].Disable()
|
|
479 self.sizer.AddGrowableCol(0)
|
|
480 self.sizer.AddGrowableCol(1)
|
|
481 self.sizer.AddGrowableRow(2)
|
|
482 self.SetSizer(self.sizer)
|
|
483 self.SetAutoLayout(True)
|
|
484
|
|
485 self.current = self.repo.dirstate.branch()
|
|
486 self.currev = self.repo.changelog.rev(self.repo.branchtags()[self.current])
|
|
487 self.RevInfo(self.currev)
|
|
488 self.revlist.Select(self.revlist.FindItem(0, str(self.currev), 1))
|
|
489 self.BranchInfo(self.current)
|
|
490 self.Bind(wx.EVT_CHOICE, self.PackageSet)
|
|
491 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.RevSet)
|
|
492 self.Bind(wx.EVT_BUTTON, self.RevUpdate, self.buttons['update'])
|
|
493
|
|
494
|
|
495 def PackageSet(self, event):
|
|
496 self.current = self.branches.GetStringSelection()
|
|
497 branches = self.repo.branchtags()
|
|
498 heads = dict.fromkeys(self.repo.heads(), 1)
|
|
499 l = [((n in heads), self.repo.changelog.rev(n), n, t) for t, n in branches.items()]
|
|
500 if self.current != type:
|
|
501 heads = dict.fromkeys(self.repo.heads(), self.repo.branchtags())
|
|
502 branches = dict.copy(self.repo.branchtags())
|
|
503 self.BranchInfo(self.current)
|
|
504 self.RevInfo(self.current)
|
|
505
|
|
506 def RevSet(self, event):
|
|
507 self.currev = self.revlist.GetItemText( self.revlist.GetFirstSelected() )
|
|
508 i = event.GetIndex()
|
|
509 self.revlist.Select(i, True)
|
|
510 self.revlist.Focus(i)
|
|
511 if self.currev != self.revlist.GetItemText( self.revlist.GetFirstSelected() ):
|
|
512 self.RevInfo(self.currev)
|
|
513
|
|
514 def RevInfo(self, rev):
|
|
515 self.revlist.DeleteAllItems()
|
|
516 self.revlist_a = []; self.revlist_b = {}
|
|
517 for heads in self.repo.changelog.reachable(self.repo.branchtags()[self.current]):
|
|
518 self.revlist_a.append(str(self.repo.changelog.rev(heads)))
|
|
519 self.revlist_b[str(self.repo.changelog.rev(heads))] = str(self.repo.changectx(heads))
|
|
520 self.revlist_a.sort()
|
|
521 for i in self.revlist_a:
|
|
522 self.revlist.InsertStringItem(0, str(i), 0 )
|
|
523 self.revlist.SetStringItem(0, 1, self.revlist_b[i])
|
|
524 self.revlist.SetColumnWidth(0, -1)
|
|
525 self.revlist.SetColumnWidth(1, -1)
|
|
526 self.revlist.Refresh()
|
|
527 self.BranchInfo(self.current)
|
|
528
|
|
529 def BranchInfo(self, branch):
|
|
530 rs = self.repo.changectx( self.currev ).changeset()
|
|
531 self.changelog.SetValue('')
|
|
532 changelog = rs[4]
|
|
533 self.changelog.AppendText(changelog + '\n')
|
|
534 self.filelist.SetValue('')
|
|
535 self.filelist.AppendText("Currently selected branch: " + branch + "\n\nAuthor: "+rs[1]+"\n\n")
|
|
536 self.filelist.AppendText("Files Modified (in update): \n")
|
|
537 for f in rs[3]: self.filelist.AppendText(f+"\n")
|
|
538
|
|
539 def DelBranch(self, event):
|
|
540 pass
|
|
541
|
|
542 def RevUpdate(self, event):
|
|
543 filename = 'ignorelist.txt'
|
|
544 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename
|
|
545 component.get('validate').config_file(filename, "default_ignorelist.txt")
|
|
546 self.mana = self.LoadDoc()
|
|
547 temp = dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep
|
|
548 for ignore in self.ignorelist:
|
|
549 shutil.copy(ignore, temp + ignore.split('/')[len(ignore.split('/')) - 1])
|
|
550 hg.clean(self.repo, self.currev)
|
|
551 for ignore in self.ignorelist:
|
|
552 shutil.copyfile(temp + ignore.split('/')[len(ignore.split('/')) - 1], ignore)
|
|
553 os.remove(temp + ignore.split('/')[len(ignore.split('/')) - 1])
|
|
554 pass
|
|
555
|
|
556 def LoadDoc(self):
|
|
557 ignore = open(self.filename)
|
|
558 self.ignorelist = []
|
|
559 for i in ignore: self.ignorelist.append(str(i [:len(i)-1]))
|
|
560 manifest = ignore.readlines()
|
|
561 ignore.close()
|
|
562
|
|
563 def get_packages(self, type=None):
|
|
564 #Fixed and ready for Test. Can be cleaner
|
|
565 self.package_list = []
|
|
566 b = self.repo.branchtags()
|
|
567 heads = dict.fromkeys(self.repo.heads(), 1) #The code below looks superfluous but there is good info inside
|
|
568 l = [((n in heads), self.repo.changelog.rev(n), n, t) for t, n in b.items()]
|
|
569 l.sort()
|
|
570 l.reverse()
|
|
571 for ishead, r, n, t in l: self.package_list.append(t)
|
|
572
|
|
573 def get_package(self):
|
|
574 self.get_packages()
|
|
575 if self.package_list == None: return None
|
|
576 return None
|
14
|
577
|
|
578 class updaterFrame(wx.Frame):
|
|
579 def __init__(self, parent, title, openrpg, manifest, main):
|
17
|
580
|
|
581 wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(600,480), style=wx.DEFAULT_FRAME_STYLE)
|
18
|
582 if wx.Platform == '__WXMSW__': icon = wx.Icon(dir_struct["icon"]+'d20.ico', wx.BITMAP_TYPE_ICO)
|
|
583 else: icon = wx.Icon(dir_struct["icon"]+"d20.xpm", wx.BITMAP_TYPE_XPM )
|
|
584
|
17
|
585 self.SetIcon(icon)
|
14
|
586 self.CenterOnScreen()
|
|
587 self.main = main
|
|
588 ####### Panel Stuff ######
|
|
589 p = wx.Panel(self)
|
|
590 nb = wx.Notebook(p)
|
|
591
|
|
592 # create the page windows as children of the notebook
|
|
593 page1 = Updater(nb, openrpg, manifest)
|
|
594 page2 = Repos(nb, openrpg, manifest)
|
|
595 page3 = Manifest(nb)
|
|
596 page4 = Control(nb)
|
|
597
|
|
598 # add the pages to the notebook with the label to show on the tab
|
|
599 nb.AddPage(page1, "Updater")
|
|
600 nb.AddPage(page2, "Repos")
|
|
601 nb.AddPage(page3, "Manifest")
|
|
602 nb.AddPage(page4, "Control")
|
|
603
|
|
604 # finally, put the notebook in a sizer for the panel to manage
|
|
605 # the layout
|
|
606 sizer = wx.BoxSizer()
|
|
607 sizer.Add(nb, 1, wx.EXPAND)
|
|
608 p.SetSizer(sizer)
|
|
609 self.Bind(wx.EVT_CLOSE, self.OnClose)
|
|
610
|
|
611 def OnClose(self, event):
|
|
612 if self.main == False: self.Destroy()
|
17
|
613 if self.main == True: self.Hide()
|
14
|
614
|
|
615 class updateApp(wx.App):
|
|
616 def OnInit(self):
|
|
617 self.main = False
|
18
|
618 logger._set_log_to_console(False)
|
|
619 logger.note("Updater Start")
|
14
|
620 self.manifest = manifest.ManifestChanges()
|
18
|
621 component.add('validate', validate)
|
|
622 self.updater = updaterFrame(self, "OpenRPG Update Manager 0.8 (open beta)",
|
|
623 component, self.manifest, self.main)
|
14
|
624 if self.manifest.GetString("updatemana", "auto_update", "") == 'on' and self.main == False:
|
|
625 self.AutoUpdate(); self.OnExit()
|
|
626 else: pass
|
|
627 if self.manifest.GetString('updatemana', 'no_update', '') == 'on' and self.main == False:
|
|
628 self.OnExit()
|
|
629 else: pass
|
|
630 try:
|
|
631 self.updater.Show()
|
|
632 self.updater.Fit()
|
|
633 except: pass
|
|
634 return True
|
|
635
|
|
636 def AutoUpdate(self):
|
|
637 self.ui = ui.ui()
|
|
638 self.repo = hg.repository(self.ui, ".")
|
|
639 self.c = self.repo.changectx('tip')
|
|
640 self.current = self.repo.dirstate.branch()
|
|
641
|
|
642 capture = self.manifest.GetString('updaterepo', 'default', '')
|
|
643 if capture != '':
|
|
644 commands.pull(self.ui, self.repo, capture, rev='', update=False, force=True)
|
|
645 filename = 'ignorelist.txt'
|
18
|
646 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename
|
|
647 component.get('validate').config_file(filename, "default_ignorelist.txt")
|
14
|
648 self.mana = self.LoadDoc()
|
18
|
649 temp = dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep
|
16
|
650 for ignore in self.ignorelist:
|
18
|
651 shutil.copy(ignore, temp + ignore.split('/')[len(ignore.split('/')) - 1])
|
14
|
652 hg.clean(self.repo, self.current)
|
|
653 for ignore in self.ignorelist:
|
18
|
654 shutil.copyfile(temp + ignore.split('/')[len(ignore.split('/')) - 1], ignore)
|
|
655 os.remove(temp + ignore.split('/')[len(ignore.split('/')) - 1])
|
|
656 else: wx.MessageBox('No default Rpository set. Skipping Auto Update!', 'Info')
|
14
|
657
|
|
658 def LoadDoc(self):
|
|
659 ignore = open(self.filename)
|
|
660 self.ignorelist = []
|
|
661 for i in ignore: self.ignorelist.append(str(i [:len(i)-1]))
|
|
662 manifest = ignore.readlines()
|
|
663 ignore.close()
|
|
664
|
|
665 def OnExit(self):
|
18
|
666 imported = ['manifest', 'orpg.dirpath', 'orpg.orpgCore', 'orpg.orpg_version',
|
|
667 'orpg.tools.orpg_log', 'orpg.tools.orpg_log', 'orpg.orpg_xml', 'orpg.dirpath',
|
|
668 'orpg.dirpath', 'upmana.validate', 'mercurial.ui', 'mercurial.hg',
|
|
669 'mercurial.commands', 'mercurial.repo', 'mercurial.revlog', 'mercurial.cmdutil', 'shutil']
|
14
|
670 for name in imported:
|
|
671 if name in sys.modules: del sys.modules[name]
|
|
672
|
|
673 try: self.updater.Destroy()
|
|
674 except: pass
|