comparison upmana/updatemana.py @ 33:3687514e0218 traipse_dev

I actally forgot the Update Manager's new package. Sorry. Here it is!
author sirebral
date Sun, 02 Aug 2009 17:13:45 -0500
parents
children 8b630fc8a343
comparison
equal deleted inserted replaced
32:c223c1051f4a 33:3687514e0218
1 import wx
2 #import wx.html
3 #import webbrowser
4 #import urllib
5 #import zipfile
6 #import traceback
7 import manifest
8 #import hashlib
9 import orpg.dirpath
10 from orpg.orpgCore import *
11 import orpg.orpg_version
12 import orpg.tools.orpg_log
13 import orpg.orpg_xml
14 import orpg.dirpath
15 #import orpg.tools.orpg_settings
16 import orpg.tools.validate
17 from mercurial import ui, hg, commands, repo, revlog, cmdutil
18
19 class Updater(wx.Panel):
20 def __init__(self, parent, openrpg):
21 wx.Panel.__init__(self, parent)
22
23 ### Update Manager
24 self.ui = ui.ui()
25 self.repo = hg.repository(self.ui, ".")
26 self.c = self.repo.changectx('tip')
27 self.manifest = []
28 self.manifest = self.c.manifest().keys()
29 self.openrpg = openrpg
30 #self.settings = openrpg.get_component('settings')
31 self.xml = openrpg.get_component('xml')
32 self.dir_struct = self.openrpg.get_component("dir_struct")
33 self.parent = parent
34 self.log = self.openrpg.get_component("log")
35 self.log.log("Enter updaterFrame", ORPG_DEBUG)
36 self.SetBackgroundColour(wx.WHITE)
37 self.sizer = wx.GridBagSizer(hgap=1, vgap=1)
38 self.changelog = wx.TextCtrl(self, wx.ID_ANY, size=(400, -1), style=wx.TE_MULTILINE | wx.TE_READONLY)
39 self.filelist = wx.TextCtrl(self, wx.ID_ANY, size=(250, 300), style=wx.TE_MULTILINE | wx.TE_READONLY)
40 self.buttons = {}
41 self.buttons['progress_bar'] = wx.Gauge(self, wx.ID_ANY, 100)
42 self.buttons['auto_text'] = wx.StaticText(self, wx.ID_ANY, "Auto Update")
43 self.buttons['auto_check'] = wx.CheckBox(self, wx.ID_ANY)
44 self.buttons['no_text'] = wx.StaticText(self, wx.ID_ANY, "No Update")
45 self.buttons['no_check'] = wx.CheckBox(self, wx.ID_ANY)
46 self.buttons['advanced'] = wx.Button(self, wx.ID_ANY, "Package Select")
47 self.buttons['update'] = wx.Button(self, wx.ID_ANY, "Update Now")
48 self.buttons['finish'] = wx.Button(self, wx.ID_ANY, "Finish")
49
50 self.sizer.Add(self.changelog, (0,0), span=(4,1), flag=wx.EXPAND)
51 self.sizer.Add(self.filelist, (0,1), span=(1,3), flag=wx.EXPAND)
52
53 self.sizer.Add(self.buttons['progress_bar'], (1,1), span=(1,3), flag=wx.EXPAND)
54 self.sizer.Add(self.buttons['auto_text'], (2,1))
55 self.sizer.Add(self.buttons['auto_check'], (2,2), flag=wx.EXPAND)
56 self.sizer.Add(self.buttons['no_text'], (3,1))
57 self.sizer.Add(self.buttons['no_check'], (3,2), flag=wx.EXPAND)
58 self.sizer.Add(self.buttons['advanced'], (2,3), flag=wx.EXPAND)
59 self.sizer.Add(self.buttons['update'], (3,3), flag=wx.EXPAND)
60 self.sizer.Add(self.buttons['finish'], (4,3), flag=wx.EXPAND)
61 self.sizer.AddGrowableCol(0)
62 self.sizer.AddGrowableRow(0)
63 self.SetSizer(self.sizer)
64 self.SetAutoLayout(True)
65 self.initPrefs()
66
67 self.current = self.c.branch()
68 self.BranchInfo(self.current)
69 #if self.autoupdate == "On": self.buttons['auto_check'].SetValue(True)
70
71 ## Event Handlers
72 self.Bind(wx.EVT_BUTTON, self.Update, self.buttons['update'])
73 self.Bind(wx.EVT_BUTTON, self.Finish, self.buttons['finish'])
74 self.Bind(wx.EVT_BUTTON, self.Advanced, self.buttons['advanced'])
75 #self.Bind(wx.EVT_CHECKBOX, self.ToggleAutoUpdate, self.buttons['auto_check'])
76
77 def showFinish(self):
78 if self.Updated: self.filelist.SetValue(self.filelist.GetValue() + "Finished ... \n")
79 self.buttons['finish'].Show()
80 self.buttons['advanced'].Show()
81
82 def initPrefs(self):
83 #self.list_url = self.settings.get_setting("PackagesURL")
84 #self.package_type = self.settings.get_setting("PackagesType")
85 #self.package_name = self.settings.get_setting("PackagesName")
86 self.SelectPackage = False
87 #self.autoupdate = self.settings.get_setting("AutoUpdate")
88 self.packages = None
89 self.package = self.get_package()
90 self.Updated = False
91 self.Finished = False
92
93 def isFinished(self):
94 return self.Finished
95
96 def ToggleAutoUpdate(self, event):
97 if self.buttons['auto_check'].GetValue():
98 self.autoupdate = "On"
99 #self.settings.set_setting("AutoUpdate", "On")
100 #self.Update(None)
101 else:
102 self.autoupdate = "Off"
103 #self.settings.set_setting("AutoUpdate", "Off")
104
105 def Update(self, evt=None):
106 hg.clean(self.repo, self.current)
107
108 def Finish(self, evt=None):
109 #self.settings.updateIni()
110 self.Finished = True
111 self.Destroy() #destroys tab, pretty useless.
112
113 def Advanced(self, evt=None):
114
115 ## This part sucks. Do they need to see the Branch List everytime? No!! Press the button.
116 dlg = wx.Dialog(self, wx.ID_ANY, "Package Selector", style=wx.DEFAULT_DIALOG_STYLE)
117 if wx.Platform == '__WXMSW__': icon = wx.Icon(self.dir_struct["icon"]+'d20.ico', wx.BITMAP_TYPE_ICO)
118 else: icon = wx.Icon(self.dir_struct["icon"]+"d20.xpm", wx.BITMAP_TYPE_XPM )
119 dlg.SetIcon(icon)
120
121 dlgsizer = wx.GridBagSizer(hgap=1, vgap=1)
122 Yes = wx.Button( dlg, wx.ID_OK, "Ok" )
123 Yes.SetDefault()
124 rgroup = wx.RadioButton(dlg, wx.ID_ANY, "group_start", style=wx.RB_GROUP)
125 rgroup.Hide()
126
127 if self.packages == None: self.get_packages()
128 if self.package_list == None: return
129 types = self.package_list
130 row=0; col=0
131 self.current = self.c.branch()
132 self.package_type = self.current
133 self.btnlist = {}; self.btn = {}
134 self.id = 1
135
136 for t in types:
137 self.btnName = str(t)
138 self.btn[self.id] = wx.RadioButton(dlg, wx.ID_ANY, str(t), name=self.btnName)
139 if self.btnName == self.current:
140 self.btn[self.id].SetValue(True)
141 self.btnlist[self.id] = self.btnName
142 dlgsizer.Add(self.btn[self.id], (row, col))
143 row += 1; self.id += 1
144
145 dlgsizer.Add(Yes, (row+1,0))
146 dlg.SetAutoLayout( True )
147 dlg.SetSizer( dlgsizer )
148 dlgsizer.Fit( dlg )
149 dlg.Centre()
150 dlg.Bind(wx.EVT_RADIOBUTTON, self.PackageSet)
151
152 if dlg.ShowModal():
153 dlg.Destroy()
154 if self.Updated:
155 self.Updated = False
156 self.filelist.SetValue('')
157 wx.CallAfter(self.check)
158
159 def PackageSet(self, event):
160 for btn in self.btn:
161 if self.btn[btn].GetValue() == True: self.current = self.btnlist[btn]
162
163 branches = self.repo.branchtags()
164 heads = dict.fromkeys(self.repo.heads(), 1)
165 l = [((n in heads), self.repo.changelog.rev(n), n, t) for t, n in branches.items()]
166
167 #l.sort()
168 #l.reverse()
169 #for ishead, r, n, t in l: self.package_list.append(t)
170
171 if self.current != type:
172 #r = hg.islocal()
173 files = self.c.files()
174 #print commands.log(u, r, c)
175 #print r.changelog
176
177 ### Cleaning up for dev build 0.1
178 ### The below material is for the Rev Log. You can run hg log to see what data it will pull.
179 #cs = r.changectx(c.rev()).changeset()
180 #get = util.cachefunc(lambda r: repo.changectx(r).changeset())
181 #changeiter, matchfn = cmdutil.walkchangerevs(u, r, 1, cs, 1)
182 #for st, rev, fns in changeiter:
183 # revbranch = get(rev)[5]['branch']; print revbranch
184
185 heads = dict.fromkeys(self.repo.heads(), self.repo.branchtags())
186 branches = dict.copy(self.repo.branchtags())
187
188 self.BranchInfo(self.current)
189
190
191 def BranchInfo(self, branch):
192 self.filelist.SetValue('')
193 self.filelist.AppendText("Files that will change\n\n")
194 self.changelog.SetValue('')
195 changelog = "This is Dev Build 0.1 of the Update Manager. It has limited functionality.\n\nThe full release will search your Revision log and show the contents here."
196 self.changelog.AppendText(changelog + '\n')
197 self.filelist.AppendText("Update to " + branch + "\n\n The full release will show the files to be changed here.")
198
199 #### Files works but not fully without the change log information, pulled for Dev 0.1
200 #for f in files:
201 # fc = c[f]
202 # self.filelist.AppendText(str(f + '\n'))
203
204
205 def verify_file(self, abs_path):
206 """Returns True if file or directory exists"""
207 try:
208 os.stat(abs_path)
209 return True
210 except OSError:
211 self.log.log("Invalid File or Directory: " + abs_path, ORPG_GENERAL)
212 return False
213
214 def get_packages(self, type=None):
215 #Fixed and ready for Test. Can be cleaner
216 self.package_list = []
217 b = self.repo.branchtags()
218 heads = dict.fromkeys(self.repo.heads(), 1)
219 l = [((n in heads), self.repo.changelog.rev(n), n, t) for t, n in b.items()]
220 l.sort()
221 l.reverse()
222 for ishead, r, n, t in l: self.package_list.append(t)
223
224 def get_package(self):
225 #Fixed and ready for test.
226 if self.packages == None: self.get_packages()
227 if self.package_list == None: return None
228 return None
229
230 class Repos(wx.Panel):
231 def __init__(self, parent, openrpg):
232 wx.Panel.__init__(self, parent)
233 self.openrpg = openrpg
234 self.settings = openrpg.get_component('settings')
235 self.xml = openrpg.get_component('xml')
236
237 self.buttons = {}
238 self.texts = {}
239
240 ## Section Sizers (with frame edges and text captions)
241 self.box_sizers = {}
242 self.box_sizers["newrepo"] = wx.StaticBox(self, -1, "Add New Repo")
243 self.box_sizers["repolist"] = wx.StaticBox(self, -1, "Current Repo List")
244
245 ## Layout Sizers
246 self.sizers = {}
247 self.sizers["main"] = wx.GridBagSizer(hgap=2, vgap=2)
248 self.sizers["newrepo"] = wx.StaticBoxSizer(self.box_sizers["newrepo"], wx.VERTICAL)
249 self.sizers["repolist"] = wx.StaticBoxSizer(self.box_sizers["repolist"], wx.VERTICAL)
250
251 #Build Server Sizer Layout
252 self.sizers["newrepo_layout"] = wx.FlexGridSizer(rows=1, cols=2, hgap=2, vgap=1)
253 reponame = wx.StaticText(self, -1, "Name:")
254 self.texts["reponame"] = wx.TextCtrl(self, -1)
255 repodesc = wx.StaticText(self, -1, "Description:")
256 self.texts["repodesc"] = wx.TextCtrl(self, -1)
257 repoadd = wx.StaticText(self, -1, "Address:")
258 self.texts["repoadd"] = wx.TextCtrl(self, -1)
259 addrepo = wx.Button(self, wx.ID_ADD)
260
261 ##Put GUI Together.
262 self.sizers["newrepo_layout"].Add(reponame, -1, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
263 self.sizers["newrepo_layout"].Add(self.texts["reponame"], -1, wx.EXPAND)
264 self.sizers["newrepo_layout"].Add(repodesc, -1, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
265 self.sizers["newrepo_layout"].Add(self.texts["repodesc"], -1, wx.EXPAND)
266 self.sizers["newrepo_layout"].Add(repoadd, -1, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
267 self.sizers["newrepo_layout"].Add(self.texts["repoadd"], -1, wx.EXPAND)
268 self.sizers["newrepo_layout"].Add(addrepo, -1)
269 self.sizers["newrepo_layout"].AddGrowableCol(1)
270 self.sizers["newrepo"].Add(self.sizers["newrepo_layout"], -1, wx.EXPAND)
271
272 #Repo List Layout
273 self.sizers["repolist_layout"] = wx.FlexGridSizer(rows=1, cols=2, hgap=2, vgap=1)
274 #addrepo = wx.Button(self, wx.ID_ADD) ## Looks bad inside the Sizer, move out!
275 #self.sizers["repolist_layout"].Add(addrepo, -1)
276 self.sizers["repolist_layout"].AddGrowableCol(1)
277 self.sizers["repolist"].Add(self.sizers["repolist_layout"], -1, wx.EXPAND)
278
279 """
280 grid = wx.GridSizer(3, 2)
281
282 grid.AddMany([(wx.Button(self, wx.ID_CANCEL), 0, wx.TOP | wx.LEFT, 9),
283 (wx.Button(self, wx.ID_DELETE), 0, wx.TOP, 9),
284 (wx.Button(self, wx.ID_SAVE), 0, wx.LEFT, 9),
285 (wx.Button(self, wx.ID_EXIT)),
286 (wx.Button(self, wx.ID_STOP), 0, wx.LEFT, 9),
287 (wx.Button(self, wx.ID_NEW))])
288
289 self.Bind(wx.EVT_BUTTON, self.OnQuit, id=wx.ID_EXIT)
290 self.SetSizer(grid)
291 self.Centre()
292 self.Show(True)
293
294
295 def OnQuit(self, event):
296 self.Close()
297 """
298
299 #Build Main Sizer
300 self.sizers["main"].Add(self.sizers["newrepo"], (0,0), flag=wx.EXPAND)
301 self.sizers["main"].Add(self.sizers["repolist"], (1,0), flag=wx.EXPAND)
302 self.sizers["main"].AddGrowableCol(0)
303 self.sizers["main"].AddGrowableCol(1)
304 #self.sizers["main"].AddGrowableRow(1)
305 self.SetSizer(self.sizers["main"])
306 self.SetAutoLayout(True)
307 self.Fit()
308
309 class Manifest(wx.Panel):
310 def __init__(self, parent):
311 wx.Panel.__init__(self, parent)
312 self.ui = ui.ui()
313 self.repo = hg.repository(self.ui, ".")
314 self.c = self.repo.changectx('tip')
315 self.manifest = []
316 self.manifest = self.c.manifest().keys()
317 self.manifest.sort()
318 self.SetBackgroundColour(wx.WHITE)
319 self.sizer = wx.GridBagSizer(hgap=1, vgap=1)
320
321 self.manifestlog = wx.TextCtrl(self, wx.ID_ANY, size=(400, -1), style=wx.TE_MULTILINE | wx.TE_READONLY)
322
323 self.sizer.Add(self.manifestlog, (0,0), flag=wx.EXPAND)
324
325 self.sizer.AddGrowableCol(0)
326 self.sizer.AddGrowableRow(0)
327 self.SetSizer(self.sizer)
328 self.SetAutoLayout(True)
329 self.BuildManifest()
330
331
332 def BuildManifest(self):
333 self.manifestlog.SetValue('')
334 self.manifestlog.AppendText('Currently the Manifest Log shows your files only, later you will be able to select files to ingore on update\n')
335 for i in self.manifest:
336 self.manifestlog.AppendText(i + '\n')
337
338 class Control(wx.Panel):
339 def __init__(self, parent):
340 wx.Panel.__init__(self, parent)
341 t = wx.StaticText(self, -1, "Here you will be able to control your branches, delete branches, \nupdate to a sepcific revision, and that type of control.", (10,60))
342
343
344 class updaterFrame(wx.Frame):
345 def __init__(self, parent, title, openrpg):
346 wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(640,480),
347 style=wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP | wx.DEFAULT_FRAME_STYLE)
348
349 self.CenterOnScreen()
350
351 ####### Panel Stuff ######
352 p = wx.Panel(self)
353 nb = wx.Notebook(p)
354
355 # create the page windows as children of the notebook
356 page1 = Updater(nb, openrpg)
357 page2 = Repos(nb, openrpg)
358 page3 = Manifest(nb)
359 page4 = Control(nb)
360
361 # add the pages to the notebook with the label to show on the tab
362 nb.AddPage(page1, "Updater")
363 nb.AddPage(page2, "Repos")
364 nb.AddPage(page3, "Manifest")
365 nb.AddPage(page4, "Control")
366
367 # finally, put the notebook in a sizer for the panel to manage
368 # the layout
369 sizer = wx.BoxSizer()
370 sizer.Add(nb, 1, wx.EXPAND)
371 p.SetSizer(sizer)
372
373
374
375 class updateApp(wx.App):
376 def OnInit(self):
377 self.open_rpg = open_rpg
378 self.log = orpg.tools.orpg_log.orpgLog(orpg.dirpath.dir_struct["user"] + "runlogs/")
379 self.log.setLogToConsol(False)
380 self.log.log("Updater Start", ORPG_NOTE)
381
382 #Add the initial global components of the openrpg class
383 #Every class should be passed openrpg
384 self.open_rpg.add_component("log", self.log)
385 self.open_rpg.add_component("xml", orpg.orpg_xml)
386 self.open_rpg.add_component("dir_struct", orpg.dirpath.dir_struct)
387 self.validate = orpg.tools.validate.Validate()
388 self.open_rpg.add_component("validate", self.validate)
389 #self.settings = orpg.tools.orpg_settings.orpgSettings(self.open_rpg)
390 #self.open_rpg.add_component("settings", self.settings)
391 #self.settings.updateIni()
392 self.updater = updaterFrame(self, "OpenRPG Update Manager Beta 0.3", self.open_rpg)
393 self.updated = False
394 try:
395 self.updater.Show()
396 self.SetTopWindow(self.updater)
397 self.updater.Fit()
398 except: pass
399
400 return True
401
402 def OnExit(self):
403 #self.settings.save()
404 """
405 imported = ['orpg.orpgCore', 'orpg.orpg_wx', 'orpg.orpg_version', 'orpg.tools.orpg_log', 'orpg.orpg_xml', 'orpg.dirpath', 'orpg.tools.orpg_settings', 'orpg.tools.validate', 'orpg.pulldom', 'orpg.tools.NotebookCtrl', 'orpg.tools.config_update', 'orpg.systempath', 'orpg.minidom', 'orpg.dirpath.dirpath_tools', 'orpg.tools.rgbhex', 'orpg.orpg_windows']
406
407 for name in imported:
408 if name in sys.modules:
409 self.log.log("Unimported " + name, ORPG_DEBUG)
410 del sys.modules[name]
411 """
412 self.log.log("Updater Exit\n\n", ORPG_NOTE)