Mercurial > traipse_dev
comparison upmana/updatemana.py @ 70:52a5fa913008 ornery-dev
Update Manager: Started working on the control panel. Right now the GUI is the hardest part. If you look through the code you will see that I can already obtain revision numbers.
author | sirebral |
---|---|
date | Tue, 18 Aug 2009 20:48:36 -0500 |
parents | c54768cffbd4 |
children | 8bc955faf819 |
comparison
equal
deleted
inserted
replaced
69:8fb07d0a1ca0 | 70:52a5fa913008 |
---|---|
1 import wx | 1 import wx |
2 import manifest | 2 import manifest |
3 from orpg.orpgCore import * | |
4 #import tempfile | |
5 import shutil | |
3 from orpg.dirpath import dir_struct | 6 from orpg.dirpath import dir_struct |
4 from orpg.orpgCore import * | 7 from orpg.tools.orpg_log import logger |
5 import orpg.orpg_version | 8 from orpg.tools.decorators import debugging |
6 import orpg.tools.orpg_log | 9 from upmana.validate import validate |
7 import orpg.orpg_xml | |
8 from orpg.dirpath import dir_struct | 10 from orpg.dirpath import dir_struct |
9 import upmana.validate | |
10 import tempfile | |
11 import shutil | |
12 from mercurial import ui, hg, commands, repo, revlog, cmdutil, util | 11 from mercurial import ui, hg, commands, repo, revlog, cmdutil, util |
13 | 12 |
14 | 13 |
15 class Updater(wx.Panel): | 14 class Updater(wx.Panel): |
15 @debugging | |
16 def __init__(self, parent, component, manifest): | 16 def __init__(self, parent, component, manifest): |
17 wx.Panel.__init__(self, parent) | 17 wx.Panel.__init__(self, parent) |
18 | 18 |
19 ### Update Manager | 19 ### Update Manager |
20 self.ui = ui.ui() | 20 self.ui = ui.ui() |
21 self.repo = hg.repository(self.ui, ".") | 21 self.repo = hg.repository(self.ui, ".") |
22 self.c = self.repo.changectx('tip') | 22 self.c = self.repo.changectx('tip') |
23 self.manifest = manifest | 23 self.manifest = manifest |
24 self.xml = component.get('xml') | |
25 self.parent = parent | 24 self.parent = parent |
26 self.log = component.get("log") | 25 #logger.debug("Enter updaterFrame") #Need to set logging level |
27 self.log.log("Enter updaterFrame", ORPG_DEBUG) | |
28 self.SetBackgroundColour(wx.WHITE) | 26 self.SetBackgroundColour(wx.WHITE) |
29 self.sizer = wx.GridBagSizer(hgap=1, vgap=1) | 27 self.sizer = wx.GridBagSizer(hgap=1, vgap=1) |
30 self.changelog = wx.TextCtrl(self, wx.ID_ANY, size=(325, -1), style=wx.TE_MULTILINE | wx.TE_READONLY) | 28 self.changelog = wx.TextCtrl(self, wx.ID_ANY, size=(325, -1), style=wx.TE_MULTILINE | wx.TE_READONLY) |
31 self.filelist = wx.TextCtrl(self, wx.ID_ANY, size=(275, 300), style=wx.TE_MULTILINE | wx.TE_READONLY) | 29 self.filelist = wx.TextCtrl(self, wx.ID_ANY, size=(275, 300), style=wx.TE_MULTILINE | wx.TE_READONLY) |
32 self.buttons = {} | 30 self.buttons = {} |
90 | 88 |
91 def Update(self, evt=None): | 89 def Update(self, evt=None): |
92 self.ui = ui.ui() | 90 self.ui = ui.ui() |
93 self.repo = hg.repository(self.ui, ".") | 91 self.repo = hg.repository(self.ui, ".") |
94 self.c = self.repo.changectx('tip') | 92 self.c = self.repo.changectx('tip') |
95 | |
96 filename = 'ignorelist.txt' | 93 filename = 'ignorelist.txt' |
97 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename | 94 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename |
98 upmana.validate.Validate(dir_struct["home"] + 'upmana' + os.sep).config_file(filename, "default_ignorelist.txt") | 95 component.get('validate').config_file(filename, "default_ignorelist.txt") |
99 self.mana = self.LoadDoc() | 96 self.mana = self.LoadDoc() |
100 for ignore in self.ignorelist: | 97 for ignore in self.ignorelist: |
101 shutil.copy(ignore, dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep +ignore.split('/')[len(ignore.split('/')) - 1]) | 98 shutil.copy(ignore, dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep +ignore.split('/')[len(ignore.split('/')) - 1]) |
102 hg.clean(self.repo, self.current) | 99 hg.clean(self.repo, self.current) |
103 for ignore in self.ignorelist: | 100 for ignore in self.ignorelist: |
174 self.BranchInfo(self.current) | 171 self.BranchInfo(self.current) |
175 | 172 |
176 def BranchInfo(self, branch): | 173 def BranchInfo(self, branch): |
177 cs = self.repo.changectx( self.current ).changeset() | 174 cs = self.repo.changectx( self.current ).changeset() |
178 rev = self.repo.changelog.rev(self.repo.branchtags()[self.current]) #Current revision number. Use in Controls | 175 rev = self.repo.changelog.rev(self.repo.branchtags()[self.current]) #Current revision number. Use in Controls |
176 #print self.repo.changelog.reachable(self.repo.branchtags()[self.current]) | |
177 #for heads in self.repo.changelog.reachable(self.repo.branchtags()[self.current]): | |
178 # print self.repo.changelog.rev(heads) | |
179 self.changelog.SetValue('') | 179 self.changelog.SetValue('') |
180 changelog = cs[4] | 180 changelog = cs[4] |
181 self.changelog.AppendText(changelog + '\n') | 181 self.changelog.AppendText(changelog + '\n') |
182 self.filelist.SetValue('') | 182 self.filelist.SetValue('') |
183 self.filelist.AppendText("Currently selected branch: " + branch + "\n\nAuthor: "+cs[1]+"\n\nFiles Modified (in update): \n") | 183 self.filelist.AppendText("Currently selected branch: " + branch + "\n\nAuthor: "+cs[1]+"\n\n") |
184 self.filelist.AppendText("Files Modified (in update): \n") | |
184 for f in cs[3]: self.filelist.AppendText(f+"\n") | 185 for f in cs[3]: self.filelist.AppendText(f+"\n") |
185 | 186 |
186 def get_packages(self, type=None): | 187 def get_packages(self, type=None): |
187 #Fixed and ready for Test. Can be cleaner | 188 #Fixed and ready for Test. Can be cleaner |
188 self.package_list = [] | 189 self.package_list = [] |
371 self.sizer = wx.GridBagSizer(hgap=1, vgap=1) | 372 self.sizer = wx.GridBagSizer(hgap=1, vgap=1) |
372 self.manifestlog = wx.CheckListBox( self, -1, wx.DefaultPosition, wx.DefaultSize, self.manifestlist, | 373 self.manifestlog = wx.CheckListBox( self, -1, wx.DefaultPosition, wx.DefaultSize, self.manifestlist, |
373 wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES) | 374 wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES) |
374 filename = 'ignorelist.txt' | 375 filename = 'ignorelist.txt' |
375 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename | 376 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename |
376 upmana.validate.Validate(dir_struct["home"] + 'upmana' + os.sep).config_file(filename, "default_ignorelist.txt") | 377 component.get('validate').config_file(filename, "default_ignorelist.txt") |
377 self.mana = self.LoadDoc() | 378 self.mana = self.LoadDoc() |
378 self.manifestlog.Bind(wx.EVT_CHECKLISTBOX, self.GetChecked) | 379 self.manifestlog.Bind(wx.EVT_CHECKLISTBOX, self.GetChecked) |
379 self.sizer.Add(self.manifestlog, (0,0), flag=wx.EXPAND) | 380 self.sizer.Add(self.manifestlog, (0,0), flag=wx.EXPAND) |
380 self.sizer.AddGrowableCol(0) | 381 self.sizer.AddGrowableCol(0) |
381 self.sizer.AddGrowableRow(0) | 382 self.sizer.AddGrowableRow(0) |
407 | 408 |
408 class Control(wx.Panel): | 409 class Control(wx.Panel): |
409 def __init__(self, parent): | 410 def __init__(self, parent): |
410 wx.Panel.__init__(self, parent) | 411 wx.Panel.__init__(self, parent) |
411 | 412 |
413 ### Control Panel | |
414 self.ui = ui.ui() | |
415 self.repo = hg.repository(self.ui, ".") | |
416 self.c = self.repo.changectx('tip') | |
417 self.manifest = manifest | |
418 self.parent = parent | |
419 #logger.debug("Enter updaterFrame") #Need to set logging level | |
420 | |
421 self.get_packages() | |
422 self.SetBackgroundColour(wx.WHITE) | |
423 self.sizer = wx.GridBagSizer(hgap=1, vgap=1) | |
424 | |
425 self.buttons = {} | |
426 | |
427 ## Changelog / File List | |
428 changelogcp = wx.Panel(self) | |
429 self.changelogcp = wx.GridBagSizer(hgap=1, vgap=1) | |
430 self.changelog = wx.TextCtrl(changelogcp, wx.ID_ANY, size=(300, 240), style=wx.TE_MULTILINE | wx.TE_READONLY) | |
431 self.filelist = wx.TextCtrl(changelogcp, wx.ID_ANY, size=(300, 240), style=wx.TE_MULTILINE | wx.TE_READONLY) | |
432 self.changelogcp.Add(self.changelog, (0,0), flag=wx.EXPAND) | |
433 self.changelogcp.Add(self.filelist, (1,0), flag=wx.EXPAND) | |
434 changelogcp.SetSizer(self.changelogcp) | |
435 self.changelogcp.AddGrowableCol(0) | |
436 self.changelogcp.AddGrowableRow(0) | |
437 self.changelogcp.AddGrowableRow(1) | |
438 changelogcp.SetAutoLayout(True) | |
439 | |
440 ## Branches / Revisions | |
441 branchcp = wx.Panel(self) | |
442 self.branchcp = wx.GridBagSizer(hgap=1, vgap=1) | |
443 self.branches = wx.Choice(branchcp, wx.ID_ANY, size=(125, 25), choices=self.package_list) | |
444 self.branch_txt = wx.StaticText(branchcp, wx.ID_ANY, "Branches") | |
445 | |
446 revlistcp = wx.Panel(self) | |
447 self.revlistcp = wx.GridBagSizer(hgap=1, vgap=1) | |
448 self.revlist1 = wx.ListCtrl(revlistcp, -1, wx.DefaultPosition, size=(290, 240), style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_HRULES) | |
449 self.revlist1.InsertColumn(0, 'Revs', 145) | |
450 self.revlist1.InsertColumn(1, 'Revs', 145) | |
451 self.revlistcp.Add(self.revlist1, (0,0), span=(1,2), flag=wx.EXPAND) | |
452 revlistcp.SetSizer(self.revlistcp) | |
453 self.revlistcp.AddGrowableCol(0) | |
454 self.revlistcp.AddGrowableRow(0) | |
455 self.revlistcp.AddGrowableRow(1) | |
456 revlistcp.SetAutoLayout(True) | |
457 | |
458 self.branchcp.Add(self.branches, (0,0), flag=wx.ALIGN_LEFT) | |
459 self.branchcp.Add(self.branch_txt, (0,1), flag=wx.ALIGN_CENTER_VERTICAL) | |
460 self.branchcp.Add(revlistcp, (1,13), flag=wx.EXPAND|wx.ALIGN_RIGHT) | |
461 branchcp.SetSizer(self.branchcp) | |
462 self.branchcp.AddGrowableCol(1) | |
463 self.branchcp.AddGrowableRow(0) | |
464 branchcp.SetAutoLayout(True) | |
465 | |
466 ## Control Panel | |
467 cp = wx.Panel(self) | |
468 self.cp = wx.GridBagSizer(hgap=1, vgap=1) | |
469 self.buttons['update'] = wx.Button(cp, wx.ID_ANY, "Revision Update") | |
470 self.buttons['delete'] = wx.Button(cp, wx.ID_ANY, "Delete Branch") | |
471 self.cp.Add(self.buttons['update'], (0,0)) | |
472 self.cp.Add(self.buttons['delete'], (0,1)) | |
473 cp.SetSizer(self.cp) | |
474 self.cp.AddGrowableCol(0) | |
475 self.cp.AddGrowableRow(0) | |
476 cp.SetAutoLayout(True) | |
477 | |
478 self.sizer.Add(changelogcp, (0,0), span=(2,1),flag=wx.EXPAND) | |
479 self.sizer.Add(branchcp, (0,1)) | |
480 self.sizer.Add(cp, (1,1), span=(2,1)) | |
481 | |
482 self.buttons['delete'].Disable() | |
483 self.sizer.AddGrowableCol(0) | |
484 self.sizer.AddGrowableRow(0) | |
485 self.sizer.AddGrowableCol(1) | |
486 self.sizer.AddGrowableRow(1) | |
487 self.SetSizer(self.sizer) | |
488 self.SetAutoLayout(True) | |
489 | |
490 self.current = self.repo.dirstate.branch() | |
491 self.BranchInfo(self.current) | |
492 | |
493 def BranchInfo(self, branch): | |
494 cs = self.repo.changectx( self.current ).changeset() | |
495 rev = self.repo.changelog.rev(self.repo.branchtags()[self.current]) #Current revision number. Use in Controls | |
496 #print self.repo.changelog.reachable(self.repo.branchtags()[self.current]) | |
497 #for heads in self.repo.changelog.reachable(self.repo.branchtags()[self.current]): #grabs revision list depending on branch. | |
498 # print self.repo.changelog.rev(heads) | |
499 #self.changelog.SetValue('') | |
500 changelog = cs[4] | |
501 #self.changelog.AppendText(changelog + '\n') | |
502 #self.filelist.SetValue('') | |
503 #self.filelist.AppendText("Currently selected branch: " + branch + "\n\nAuthor: "+cs[1]+"\n\n") | |
504 #self.filelist.AppendText("Files Modified (in update): \n") | |
505 #for f in cs[3]: self.filelist.AppendText(f+"\n") | |
506 | |
507 def get_packages(self, type=None): | |
508 #Fixed and ready for Test. Can be cleaner | |
509 self.package_list = [] | |
510 b = self.repo.branchtags() | |
511 heads = dict.fromkeys(self.repo.heads(), 1) #The code below looks superfluous but there is good info inside | |
512 l = [((n in heads), self.repo.changelog.rev(n), n, t) for t, n in b.items()] | |
513 l.sort() | |
514 l.reverse() | |
515 for ishead, r, n, t in l: self.package_list.append(t) | |
516 | |
517 def get_package(self): | |
518 self.get_packages() | |
519 if self.package_list == None: return None | |
520 return None | |
412 | 521 |
413 class updaterFrame(wx.Frame): | 522 class updaterFrame(wx.Frame): |
414 def __init__(self, parent, title, openrpg, manifest, main): | 523 def __init__(self, parent, title, openrpg, manifest, main): |
415 dir_struct = component.get("dir_struct") | |
416 | 524 |
417 wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(600,480), style=wx.DEFAULT_FRAME_STYLE) | 525 wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(600,480), style=wx.DEFAULT_FRAME_STYLE) |
418 if wx.Platform == '__WXMSW__': icon = wx.Icon(dir_struct["icon"]+'d20.ico', wx.BITMAP_TYPE_ICO) | 526 if wx.Platform == '__WXMSW__': icon = wx.Icon(dir_struct["icon"]+'d20.ico', wx.BITMAP_TYPE_ICO) |
419 else: icon = wx.Icon(dir_struct["icon"]+"d20.xpm", wx.BITMAP_TYPE_XPM ) | 527 else: icon = wx.Icon(dir_struct["icon"]+"d20.xpm", wx.BITMAP_TYPE_XPM ) |
528 | |
420 self.SetIcon(icon) | 529 self.SetIcon(icon) |
421 | |
422 self.CenterOnScreen() | 530 self.CenterOnScreen() |
423 self.main = main | 531 self.main = main |
424 ####### Panel Stuff ###### | 532 ####### Panel Stuff ###### |
425 p = wx.Panel(self) | 533 p = wx.Panel(self) |
426 nb = wx.Notebook(p) | 534 nb = wx.Notebook(p) |
448 if self.main == False: self.Destroy() | 556 if self.main == False: self.Destroy() |
449 if self.main == True: self.Hide() | 557 if self.main == True: self.Hide() |
450 | 558 |
451 class updateApp(wx.App): | 559 class updateApp(wx.App): |
452 def OnInit(self): | 560 def OnInit(self): |
453 self.component = component | |
454 self.main = False | 561 self.main = False |
455 self.log = orpg.tools.orpg_log.orpgLog(dir_struct["user"] + "runlogs/") | 562 #logger.setLogToConsol(False) |
456 self.log.setLogToConsol(False) | 563 #logger. ??? ("Updater Start", ORPG_NOTE) |
457 self.log.log("Updater Start", ORPG_NOTE) | |
458 self.manifest = manifest.ManifestChanges() | 564 self.manifest = manifest.ManifestChanges() |
459 self.component.add("log", self.log) | 565 component.add('validate', validate) |
460 self.component.add("xml", orpg.orpg_xml) | 566 self.updater = updaterFrame(self, "OpenRPG Update Manager 0.7.2 (open beta)", |
461 self.component.add("dir_struct", dir_struct) | 567 component, self.manifest, self.main) |
462 self.validate = upmana.validate.Validate() | |
463 self.component.add("validate", self.validate) | |
464 self.updater = updaterFrame(self, "OpenRPG Update Manager 0.7.2 (open beta)", self.component, self.manifest, self.main) | |
465 if self.manifest.GetString("updatemana", "auto_update", "") == 'on' and self.main == False: | 568 if self.manifest.GetString("updatemana", "auto_update", "") == 'on' and self.main == False: |
466 self.AutoUpdate(); self.OnExit() | 569 self.AutoUpdate(); self.OnExit() |
467 else: pass | 570 else: pass |
468 if self.manifest.GetString('updatemana', 'no_update', '') == 'on' and self.main == False: | 571 if self.manifest.GetString('updatemana', 'no_update', '') == 'on' and self.main == False: |
469 self.OnExit() | 572 self.OnExit() |
483 capture = self.manifest.GetString('updaterepo', 'default', '') | 586 capture = self.manifest.GetString('updaterepo', 'default', '') |
484 if capture != '': | 587 if capture != '': |
485 commands.pull(self.ui, self.repo, capture, rev='', update=False, force=True) | 588 commands.pull(self.ui, self.repo, capture, rev='', update=False, force=True) |
486 filename = 'ignorelist.txt' | 589 filename = 'ignorelist.txt' |
487 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename | 590 self.filename = dir_struct["home"] + 'upmana' + os.sep + filename |
488 upmana.validate.Validate(dir_struct["home"] + 'upmana' + os.sep).config_file(filename, "default_ignorelist.txt") | 591 component.get('validate').config_file(filename, "default_ignorelist.txt") |
592 | |
489 self.mana = self.LoadDoc() | 593 self.mana = self.LoadDoc() |
490 for ignore in self.ignorelist: | 594 for ignore in self.ignorelist: |
491 shutil.copy(ignore, dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep +ignore.split('/')[len(ignore.split('/')) - 1]) | 595 shutil.copy(ignore, dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep +ignore.split('/')[len(ignore.split('/')) - 1]) |
492 hg.clean(self.repo, self.current) | 596 hg.clean(self.repo, self.current) |
493 for ignore in self.ignorelist: | 597 for ignore in self.ignorelist: |
494 print ignore.split('/')[len(ignore.split('/')) - 1] | 598 print ignore.split('/')[len(ignore.split('/')) - 1] |
495 shutil.copyfile(dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep + ignore.split('/')[len(ignore.split('/')) - 1], ignore) | 599 shutil.copyfile(dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep + ignore.split('/')[len(ignore.split('/')) - 1], ignore) |
496 os.remove(dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep + ignore.split('/')[len(ignore.split('/')) - 1]) | 600 os.remove(dir_struct["home"] + 'upmana' + os.sep + 'tmp' + os.sep + ignore.split('/')[len(ignore.split('/')) - 1]) |
497 else: print 'No default repository set, skipping Auto Update!' | 601 else: print 'No default repository set, skipping Auto Update!' #Add better warning! |
498 | 602 |
499 def LoadDoc(self): | 603 def LoadDoc(self): |
500 ignore = open(self.filename) | 604 ignore = open(self.filename) |
501 self.ignorelist = [] | 605 self.ignorelist = [] |
502 for i in ignore: self.ignorelist.append(str(i [:len(i)-1])) | 606 for i in ignore: self.ignorelist.append(str(i [:len(i)-1])) |
503 manifest = ignore.readlines() | 607 manifest = ignore.readlines() |
504 ignore.close() | 608 ignore.close() |
505 | 609 |
506 def OnExit(self): | 610 def OnExit(self): |
507 imported = ['manifest', 'orpg.dirpath', 'orpg.orpgCore', 'orpg.orpg_version', 'orpg.tools.orpg_log', 'orpg.tools.orpg_log', 'orpg.orpg_xml', 'orpg.dirpath', 'orpg.dirpath', 'upmana.validate', 'mercurial.ui', 'mercurial.hg', 'mercurial.commands', 'mercurial.repo', 'mercurial.revlog', 'mercurial.cmdutil', 'shutil'] | 611 imported = ['manifest', 'orpg.dirpath', 'orpg.orpgCore', 'orpg.orpg_version', |
612 'orpg.tools.orpg_log', 'orpg.tools.orpg_log', 'orpg.orpg_xml', 'orpg.dirpath', | |
613 'orpg.dirpath', 'upmana.validate', 'mercurial.ui', 'mercurial.hg', | |
614 'mercurial.commands', 'mercurial.repo', 'mercurial.revlog', 'mercurial.cmdutil', 'shutil'] | |
508 for name in imported: | 615 for name in imported: |
509 if name in sys.modules: del sys.modules[name] | 616 if name in sys.modules: del sys.modules[name] |
510 | 617 |
511 try: self.updater.Destroy() | 618 try: self.updater.Destroy() |
512 except: pass | 619 except: pass |