comparison upmana/updatemana.py @ 47:52f6a38f8885 traipse_dev

Update Manager 0.6.7 (Initial Release). Getting ready to implement it now. Default Check on repos does *NOT* work. Manifest works, Repos work. Main does not show panel or menu item, so if Auto or No are check, user will *NOT* see the Update Manager unless they edit their manifest.xml
author sirebral
date Thu, 06 Aug 2009 03:31:21 -0500
parents 599f727e3833
children 0aeee1992423
comparison
equal deleted inserted replaced
46:599f727e3833 47:52f6a38f8885
5 import orpg.orpg_version 5 import orpg.orpg_version
6 import orpg.tools.orpg_log 6 import orpg.tools.orpg_log
7 import orpg.orpg_xml 7 import orpg.orpg_xml
8 import orpg.dirpath 8 import orpg.dirpath
9 import orpg.tools.validate 9 import orpg.tools.validate
10 import tempfile
11 import shutil
10 from mercurial import ui, hg, commands, repo, revlog, cmdutil 12 from mercurial import ui, hg, commands, repo, revlog, cmdutil
11 13
12 14
13 class Updater(wx.Panel): 15 class Updater(wx.Panel):
14 def __init__(self, parent, open_rpg, manifest): 16 def __init__(self, parent, open_rpg, manifest):
17 ### Update Manager 19 ### Update Manager
18 self.ui = ui.ui() 20 self.ui = ui.ui()
19 self.repo = hg.repository(self.ui, ".") 21 self.repo = hg.repository(self.ui, ".")
20 self.c = self.repo.changectx('tip') 22 self.c = self.repo.changectx('tip')
21 self.manifest = manifest 23 self.manifest = manifest
22
23 self.xml = open_rpg.get_component('xml') 24 self.xml = open_rpg.get_component('xml')
24 self.dir_struct = open_rpg.get_component("dir_struct") 25 self.dir_struct = open_rpg.get_component("dir_struct")
25 self.parent = parent 26 self.parent = parent
26 self.log = open_rpg.get_component("log") 27 self.log = open_rpg.get_component("log")
27 self.log.log("Enter updaterFrame", ORPG_DEBUG) 28 self.log.log("Enter updaterFrame", ORPG_DEBUG)
56 self.SetAutoLayout(True) 57 self.SetAutoLayout(True)
57 self.get_package 58 self.get_package
58 59
59 self.current = self.c.branch() 60 self.current = self.c.branch()
60 self.BranchInfo(self.current) 61 self.BranchInfo(self.current)
61 #if self.autoupdate == "On": self.buttons['auto_check'].SetValue(True)
62 62
63 ## Event Handlers 63 ## Event Handlers
64 self.Bind(wx.EVT_BUTTON, self.Update, self.buttons['update']) 64 self.Bind(wx.EVT_BUTTON, self.Update, self.buttons['update'])
65 self.Bind(wx.EVT_BUTTON, self.Finish, self.buttons['finish']) 65 self.Bind(wx.EVT_BUTTON, self.Finish, self.buttons['finish'])
66 self.Bind(wx.EVT_BUTTON, self.ChooseBranch, self.buttons['advanced']) 66 self.Bind(wx.EVT_BUTTON, self.ChooseBranch, self.buttons['advanced'])
70 def ToggleAutoUpdate(self, event): 70 def ToggleAutoUpdate(self, event):
71 if self.buttons['auto_check'].GetValue(): 71 if self.buttons['auto_check'].GetValue():
72 if self.buttons['no_check'].GetValue(): 72 if self.buttons['no_check'].GetValue():
73 self.buttons['no_check'].SetValue(False) 73 self.buttons['no_check'].SetValue(False)
74 self.manifest.SetString("updatemana", "no_update", "off") 74 self.manifest.SetString("updatemana", "no_update", "off")
75 self.autoupdate = "On"
76 self.manifest.SetString("updatemana", "auto_update", "on") 75 self.manifest.SetString("updatemana", "auto_update", "on")
77 else: 76 else: self.manifest.SetString("updatemana", "auto_update", "off")
78 self.autoupdate = "Off"
79 self.manifest.SetString("updatemana", "auto_update", "off")
80 77
81 def ToggleNoUpdate(self, event): 78 def ToggleNoUpdate(self, event):
82 if self.buttons['no_check'].GetValue(): 79 if self.buttons['no_check'].GetValue():
83 if self.buttons['auto_check'].GetValue(): 80 if self.buttons['auto_check'].GetValue():
84 self.buttons['auto_check'].SetValue(False) 81 self.buttons['auto_check'].SetValue(False)
85 self.manifest.SetString("updatemana", "auto_update", "off") 82 self.manifest.SetString("updatemana", "auto_update", "off")
86 self.autoupdate = "On"
87 self.manifest.SetString("updatemana", "no_update", "on") 83 self.manifest.SetString("updatemana", "no_update", "on")
88 else: 84 else: self.manifest.SetString("updatemana", "no_update", "off")
89 self.autoupdate = "Off"
90 self.manifest.SetString("updatemana", "no_update", "off")
91 85
92 def Update(self, evt=None): 86 def Update(self, evt=None):
93 hg.clean(self.repo, self.current) 87 self.ui = ui.ui()
88 self.repo = hg.repository(self.ui, ".")
89 self.c = self.repo.changectx('tip')
90
91 filename = '.ignorelist.txt'
92 self.filename = orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep + filename
93 orpg.tools.validate.Validate(orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep).config_file(filename, "default_ignorelist.txt")
94 self.mana = self.LoadDoc()
95 for ignore in self.ignorelist:
96 shutil.copy(ignore, orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep)
97 #hg.clean(self.repo, self.current)
98 for ignore in self.ignorelist:
99 shutil.copyfile(orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep + ignore.split('/')[len(ignore.split('/')) - 1], ignore)
100 os.remove(orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep + ignore.split('/')[len(ignore.split('/')) - 1])
101
102 def LoadDoc(self):
103 ignore = open(self.filename)
104 self.ignorelist = []
105 for i in ignore: self.ignorelist.append(str(i [:len(i)-1]))
106 manifest = ignore.readlines()
107 ignore.close()
94 108
95 def Finish(self, evt=None): 109 def Finish(self, evt=None):
96 self.Finished = True 110 exit()
97 self.Destroy() #destroys tab, pretty useless.
98 111
99 def ChooseBranch(self, evt=None): 112 def ChooseBranch(self, evt=None):
100
101 dlg = wx.Dialog(self, wx.ID_ANY, "Package Selector", style=wx.DEFAULT_DIALOG_STYLE) 113 dlg = wx.Dialog(self, wx.ID_ANY, "Package Selector", style=wx.DEFAULT_DIALOG_STYLE)
102 if wx.Platform == '__WXMSW__': icon = wx.Icon(self.dir_struct["icon"]+'d20.ico', wx.BITMAP_TYPE_ICO) 114 if wx.Platform == '__WXMSW__': icon = wx.Icon(self.dir_struct["icon"]+'d20.ico', wx.BITMAP_TYPE_ICO)
103 else: icon = wx.Icon(self.dir_struct["icon"]+"d20.xpm", wx.BITMAP_TYPE_XPM ) 115 else: icon = wx.Icon(self.dir_struct["icon"]+"d20.xpm", wx.BITMAP_TYPE_XPM )
104 dlg.SetIcon(icon) 116 dlg.SetIcon(icon)
105 117
119 self.id = 1 131 self.id = 1
120 132
121 for t in types: 133 for t in types:
122 self.btnName = str(t) 134 self.btnName = str(t)
123 self.btn[self.id] = wx.RadioButton(dlg, wx.ID_ANY, str(t), name=self.btnName) 135 self.btn[self.id] = wx.RadioButton(dlg, wx.ID_ANY, str(t), name=self.btnName)
124 if self.btnName == self.current: 136 if self.btnName == self.current: self.btn[self.id].SetValue(True)
125 self.btn[self.id].SetValue(True)
126 self.btnlist[self.id] = self.btnName 137 self.btnlist[self.id] = self.btnName
127 dlgsizer.Add(self.btn[self.id], (row, col)) 138 dlgsizer.Add(self.btn[self.id], (row, col))
128 row += 1; self.id += 1 139 col += 1; self.id += 1
129 140 if col == 3: row += 1; col = 0
130 dlgsizer.Add(Yes, (row+1,0)) 141
142 dlgsizer.Add(Yes, (row+1,col/2))
143 dlgsizer.AddGrowableCol(0)
144 dlgsizer.AddGrowableRow(0)
131 dlg.SetAutoLayout( True ) 145 dlg.SetAutoLayout( True )
132 dlg.SetSizer( dlgsizer ) 146 dlg.SetSizer( dlgsizer )
133 dlgsizer.Fit( dlg ) 147 dlgsizer.Fit( dlg )
134 dlg.Centre() 148 dlg.Centre()
135 dlg.Bind(wx.EVT_RADIOBUTTON, self.PackageSet) 149 dlg.Bind(wx.EVT_RADIOBUTTON, self.PackageSet)
136 150 if dlg.ShowModal(): dlg.Destroy()
137 if dlg.ShowModal():
138 dlg.Destroy()
139 151
140 def PackageSet(self, event): 152 def PackageSet(self, event):
141 for btn in self.btn: 153 for btn in self.btn:
142 if self.btn[btn].GetValue() == True: self.current = self.btnlist[btn] 154 if self.btn[btn].GetValue() == True: self.current = self.btnlist[btn]
143 155
169 181
170 def BranchInfo(self, branch): 182 def BranchInfo(self, branch):
171 self.filelist.SetValue('') 183 self.filelist.SetValue('')
172 self.filelist.AppendText("Files that will change\n\n") 184 self.filelist.AppendText("Files that will change\n\n")
173 self.changelog.SetValue('') 185 self.changelog.SetValue('')
174 changelog = "Traipse 'OpenRPG' Update Manager.\n\nThis is Dev Build 0.6.5 of the Update Manager. It has limited functionality.\n\nThe full release will search your Revision log and show the contents here.\n\nMajor changes in this version are ... Manifest is now in a CheckListBox, very nice, Repos now allow for scrolling, New button works. Checks Box on the Updater tab work. Settings file is created and data is saved to it." 186 changelog = "Traipse 'OpenRPG' Update Manager.\n\nThis is Dev Build 0.6.7 of the Update Manager. This version is nearly 100% functional. Users can now add repositories of OpenRPG, choose from different branches available from those repositories, and add files to an ignore list.\n\nThe Update Manager is divided into tabs, Updater, Repos, Manifest, and Control. The Updater says it all, choose a branch and update to that branch. Repos is a new feature that I hope users take advantage of. Clone the repo, build your own, and then share it with your friends! The Manifest is the ignore list. Want to make sure a test run doesn't delete important files ... then add them to the Manifest'. Control is not functional yet, but when it is users will be able to update to specific revision dates and delete branches.\n\nThis is a good start. Enjoy the freedom!!"
175 self.changelog.AppendText(changelog + '\n') 187 self.changelog.AppendText(changelog + '\n')
176 self.filelist.AppendText("Update to " + branch + "\n\n The full release will show the files to be changed here.") 188 self.filelist.AppendText("Update to " + branch + "\n\nWhen Update Manager is fully functional this area will show the files that will be affected by the yoru branch selection.")
177 189
178 #### Files works but not fully without the change log information, pulled for Dev 0.1 190 #### Files works but not fully without the change log information, pulled for Dev 0.1
179 #for f in files: 191 #for f in files:
180 # fc = c[f] 192 # fc = c[f]
181 # self.filelist.AppendText(str(f + '\n')) 193 # self.filelist.AppendText(str(f + '\n'))
182
183
184 194
185 def get_packages(self, type=None): 195 def get_packages(self, type=None):
186 #Fixed and ready for Test. Can be cleaner 196 #Fixed and ready for Test. Can be cleaner
187 self.package_list = [] 197 self.package_list = []
188 b = self.repo.branchtags() 198 b = self.repo.branchtags()
319 329
320 def AddRepo(self, event): 330 def AddRepo(self, event):
321 repo = self.texts['reponame'].GetValue(); repo = repo.replace(' ', '_'); repo = 'repo-' + repo 331 repo = self.texts['reponame'].GetValue(); repo = repo.replace(' ', '_'); repo = 'repo-' + repo
322 self.manifest.SetString('updaterepo', repo, ''); self.repo = repo.split(',') 332 self.manifest.SetString('updaterepo', repo, ''); self.repo = repo.split(',')
323 repolist = self.manifest.GetList('UpdateManifest', 'repolist', '') 333 repolist = self.manifest.GetList('UpdateManifest', 'repolist', '')
324 if repolist == '': 334 if repolist == '': pass
325 pass 335 else: repolist = repolist + self.repo
326 else:
327 repolist = repolist + self.repo
328 self.manifest.SetList('UpdateManifest', 'repolist', repolist) 336 self.manifest.SetList('UpdateManifest', 'repolist', repolist)
329 self.BuildRepoList(None) 337 self.BuildRepoList(None)
330 338
331 def DelRepo(self, event): 339 def DelRepo(self, event):
332 self.id = self.delete_list[event.GetEventObject()] 340 self.id = self.delete_list[event.GetEventObject()]
337 self.sizers['repolist_layout'].Layout() 345 self.sizers['repolist_layout'].Layout()
338 346
339 def RefreshRepo(self, event): 347 def RefreshRepo(self, event):
340 self.id = self.pull_list[event.GetEventObject()] 348 self.id = self.pull_list[event.GetEventObject()]
341 self.manifest.SetString('updaterepo', str(self.box_name[self.id]), self.url[self.id].GetValue()) 349 self.manifest.SetString('updaterepo', str(self.box_name[self.id]), self.url[self.id].GetValue())
342 try: 350 try: commands.pull(self.ui, self.r, self.url[self.id].GetValue(), rev='', update=False, force=True)
343 commands.pull(self.ui, self.r, self.url[self.id].GetValue(), rev='', update=False, force=True) 351 except: pass
344 except:
345 pass
346 352
347 class Manifest(wx.Panel): 353 class Manifest(wx.Panel):
348 def __init__(self, parent): 354 def __init__(self, parent):
349 wx.Panel.__init__(self, parent) 355 wx.Panel.__init__(self, parent)
350 self.ui = ui.ui() 356 self.ui = ui.ui()
351 self.repo = hg.repository(self.ui, ".") 357 self.repo = hg.repository(self.ui, ".")
352 self.c = self.repo.changectx('tip') 358 self.c = self.repo.changectx('tip')
353 359
354 self.manifestlist = [] 360 self.manifestlist = []
355 self.manifestlist = self.c.manifest().keys() 361 self.manifestlist = self.c.manifest().keys()
362 for mana in self.manifestlist: mana = os.sep + 'orpg' + os.sep + mana
356 self.manifestlist.sort() 363 self.manifestlist.sort()
357 364
358 self.SetBackgroundColour(wx.WHITE) 365 self.SetBackgroundColour(wx.WHITE)
359 self.sizer = wx.GridBagSizer(hgap=1, vgap=1) 366 self.sizer = wx.GridBagSizer(hgap=1, vgap=1)
360 367
361 self.manifestlog = wx.CheckListBox( self, -1, wx.DefaultPosition, wx.DefaultSize, self.manifestlist, 368 self.manifestlog = wx.CheckListBox( self, -1, wx.DefaultPosition, wx.DefaultSize, self.manifestlist,
362 wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES) 369 wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES)
363 370
364 filename = '.hgignore' 371 filename = 'ignorelist.txt'
365 self.filename = orpg.dirpath.dir_struct["home"] + filename 372 self.filename = orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep + filename
366 orpg.tools.validate.Validate(orpg.dirpath.dir_struct["home"]).config_file(filename, "default.hgignore") 373 orpg.tools.validate.Validate(orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep).config_file(filename, "default_ignorelist.txt")
367 self.mana = self.LoadDoc() 374 self.mana = self.LoadDoc()
368 375
369 self.manifestlog.Bind(wx.EVT_CHECKLISTBOX, self.GetChecked) 376 self.manifestlog.Bind(wx.EVT_CHECKLISTBOX, self.GetChecked)
370 self.sizer.Add(self.manifestlog, (0,0), flag=wx.EXPAND) 377 self.sizer.Add(self.manifestlog, (0,0), flag=wx.EXPAND)
371 self.sizer.AddGrowableCol(0) 378 self.sizer.AddGrowableCol(0)
373 self.SetSizer(self.sizer) 380 self.SetSizer(self.sizer)
374 self.SetAutoLayout(True) 381 self.SetAutoLayout(True)
375 382
376 def GetChecked(self, event): 383 def GetChecked(self, event):
377 self.mana = [] 384 self.mana = []
378 for manifest in self.manifestlog.GetChecked(): 385 for manifest in self.manifestlog.GetChecked(): self.mana.append(self.manifestlist[manifest])
379 self.mana.append(self.manifestlist[manifest])
380 self.SaveDoc() 386 self.SaveDoc()
381 387
382 def SaveDoc(self): 388 def SaveDoc(self):
383 f = open(self.filename, "w") 389 f = open(self.filename, "w")
384 for mana in self.mana: 390 for mana in self.mana: f.write(mana+'\n')
385 f.write(mana+'\n')
386 #f.write('\n')
387 f.close() 391 f.close()
388 392
389 def LoadDoc(self): 393 def LoadDoc(self):
390 ignore = open(self.filename) 394 ignore = open(self.filename)
391 ignorelist = [] 395 ignorelist = []
392 for i in ignore: 396 for i in ignore: ignorelist.append(str(i [:len(i)-1]))
393 ignorelist.append(str(i [:len(i)-1]))
394 self.manifestlog.SetCheckedStrings(ignorelist) 397 self.manifestlog.SetCheckedStrings(ignorelist)
395 manifest = ignore.read() 398 manifest = ignore.readlines()
396 ignore.close() 399 ignore.close()
397 400
398 class Control(wx.Panel): 401 class Control(wx.Panel):
399 def __init__(self, parent): 402 def __init__(self, parent):
400 wx.Panel.__init__(self, parent) 403 wx.Panel.__init__(self, parent)
401 404
402 405
403 class updaterFrame(wx.Frame): 406 class updaterFrame(wx.Frame):
404 def __init__(self, parent, title, openrpg, manifest): 407 def __init__(self, parent, title, openrpg, manifest):
405 wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(640,480), 408 wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(700,480),
406 style=wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP | wx.DEFAULT_FRAME_STYLE) 409 style=wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP | wx.DEFAULT_FRAME_STYLE)
407
408 self.CenterOnScreen() 410 self.CenterOnScreen()
409 411
410 ####### Panel Stuff ###### 412 ####### Panel Stuff ######
411 p = wx.Panel(self) 413 p = wx.Panel(self)
412 nb = wx.Notebook(p) 414 nb = wx.Notebook(p)
439 self.open_rpg.add_component("log", self.log) 441 self.open_rpg.add_component("log", self.log)
440 self.open_rpg.add_component("xml", orpg.orpg_xml) 442 self.open_rpg.add_component("xml", orpg.orpg_xml)
441 self.open_rpg.add_component("dir_struct", orpg.dirpath.dir_struct) 443 self.open_rpg.add_component("dir_struct", orpg.dirpath.dir_struct)
442 self.validate = orpg.tools.validate.Validate() 444 self.validate = orpg.tools.validate.Validate()
443 self.open_rpg.add_component("validate", self.validate) 445 self.open_rpg.add_component("validate", self.validate)
444 self.updater = updaterFrame(self, "OpenRPG Update Manager Beta 0.6.5", self.open_rpg, self.manifest) 446 self.updater = updaterFrame(self, "OpenRPG Update Manager Beta 0.6.7", self.open_rpg, self.manifest)
445
446 if self.manifest.GetString("updatemana", "auto_update", "") == 'on': 447 if self.manifest.GetString("updatemana", "auto_update", "") == 'on':
447 print 'Auto Update not completed' 448 self.AutoUpdate(); self.OnExit()
448 self.OnExit() 449 if self.manifest.GetString('updatemana', 'no_update', '') == 'on': self.OnExit()
449
450 if self.manifest.GetString('updatemana', 'no_update', '') == 'on':
451 self.OnExit()
452
453 try: 450 try:
454 self.updater.Show() 451 self.updater.Show()
455 self.SetTopWindow(self.updater) 452 self.SetTopWindow(self.updater)
456 self.updater.Fit() 453 self.updater.Fit()
457 except: pass 454 except: pass
458
459 return True 455 return True
460 456
457 def AutoUpdate(self):
458 self.ui = ui.ui()
459 self.repo = hg.repository(self.ui, ".")
460 self.c = self.repo.changectx('tip')
461 filename = '.ignorelist.txt'
462 self.filename = orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep + filename
463 orpg.tools.validate.Validate(orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep).config_file(filename, "default_ignorelist.txt")
464 self.mana = self.LoadDoc()
465 for ignore in self.ignorelist:
466 shutil.copy(ignore, orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep)
467 #hg.clean(self.repo, self.current)
468 for ignore in self.ignorelist:
469 shutil.copyfile(orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep + ignore.split('/')[len(ignore.split('/')) - 1], ignore)
470 os.remove(orpg.dirpath.dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep + ignore.split('/')[len(ignore.split('/')) - 1])
471
472 def LoadDoc(self):
473 ignore = open(self.filename)
474 self.ignorelist = []
475 for i in ignore: self.ignorelist.append(str(i [:len(i)-1]))
476 manifest = ignore.readlines()
477 ignore.close()
478
461 def OnExit(self): 479 def OnExit(self):
462 imported = ['manifest', 'orpg.dirpath', 'orpg.orpgCore', 'orpg.orpg_version', 'orpg.tools.orpg_log', 'orpg.tools.orpg_log', 'orpg.orpg_xml', 'orpg.dirpath', 'orpg.dirpath', 'orpg.tools.validate', 'mercurial.ui', 'mercurial.hg', 'mercurial.commands', 'mercurial.repo', 'mercurial.revlog', 'mercurial.cmdutil'] 480 imported = ['manifest', 'orpg.dirpath', 'orpg.orpgCore', 'orpg.orpg_version', 'orpg.tools.orpg_log', 'orpg.tools.orpg_log', 'orpg.orpg_xml', 'orpg.dirpath', 'orpg.dirpath', 'orpg.tools.validate', 'mercurial.ui', 'mercurial.hg', 'mercurial.commands', 'mercurial.repo', 'mercurial.revlog', 'mercurial.cmdutil', 'shutil']
463
464 for name in imported: 481 for name in imported:
465 if name in sys.modules: 482 if name in sys.modules: del sys.modules[name]
466 #self.log.log("Unimported " + name, ORPG_DEBUG) 483 try: self.updater.Destroy()
467 del sys.modules[name] 484 except: pass
468 self.updater.Destroy()
469
470 #self.log.log("Updater Exit\n\n", ORPG_NOTE)