def onHGrevertall(self, evt): dlg = wx.MessageDialog( None, 'Do you discard all changes since the last commit?', 'Revert', wx.OK | wx.CANCEL) ret = dlg.ShowModal() dlg.Destroy() if ret != wx.ID_OK: return d = self.owndir() fpath = os.path.join(d, ".hg_data_hg") if not os.path.exists(os.path.join(d, ".hg")): return # not a repo ichild = self.get_ichild() owndir = self.owndir() name = self._name parent = self.get_parent() repo = hgapi.Repo(owndir) # repo.hg_revert(True) repo.hg_revert(all) self.hg_set_projtreeviewer_status(repo=repo) # puting the tree back vars = self.getvar().copy() self.destroy(clean_owndir=False) if not os.path.exists(fpath): # # In this case, it makes a containing folder # and gather *.py to make PyScript # I should be handling other files here too? # print(vars) td = handle_pure_file_repo(parent, name, owndir) td.setvar(vars) load_fpath = False else: load_fpath = True if load_fpath: fid = open(fpath, 'rb') td, olist, nlist = TreeDict().load(fid, keep_zorder=True) fid.close() parent.add_child(td._name, td, keep_zorder=True) parent.move_child(td.get_ichild(), ichild) if load_fpath: for obj in td.walk_tree(): obj.init_after_load(olist, nlist) for item in repo.hg_status()['?']: os.remove(os.path.join(d, item)) ifigure.events.SendFileSystemChangedEvent(parent, reload=True) evt.Skip()
def onHGrevertall(self, evt): dlg=wx.MessageDialog(None, 'Do you discard all changes since the last commit?', 'Revert', wx.OK|wx.CANCEL) ret=dlg.ShowModal() dlg.Destroy() if ret != wx.ID_OK: return d = self.owndir() fpath=os.path.join(d, ".hg_data_hg") if not os.path.exists(os.path.join(d, ".hg")): return ## not a repo ichild = self.get_ichild() owndir = self.owndir() name = self._name parent = self.get_parent() repo = hgapi.Repo(owndir) #repo.hg_revert(True) repo.hg_revert(all) self.hg_set_projtreeviewer_status(repo=repo) ## puting the tree back vars = self.getvar().copy() self.destroy(clean_owndir=False) if not os.path.exists(fpath): # # In this case, it makes a containing folder # and gather *.py to make PyScript # I should be handling other files here too? # print vars td = handle_pure_file_repo(parent, name, owndir) td.setvar(vars) load_fpath = False else: load_fpath = True if load_fpath: fid= open(fpath, 'rb') td, olist, nlist = TreeDict().load(fid, keep_zorder=True) fid.close() parent.add_child(td._name, td, keep_zorder = True) parent.move_child(td.get_ichild(), ichild) if load_fpath: for obj in td.walk_tree(): obj.init_after_load(olist, nlist) for item in repo.hg_status()['?']: os.remove(os.path.join(d, item)) ifigure.events.SendFileSystemChangedEvent(parent, reload = True) evt.Skip()
def onHGupdate(self, evt=None, m=None): repo = hgapi.Repo(self.owndir()) app0 = wx.GetApp().TopWindow if m is None: latest = repo.revisions(slice(-1,-1))[0].rev ret, m = dialog.textentry(app0, "Enter revision #", "Mercurial Update", str(latest)) if not ret: return None status = repo.hg_status() for key in status: if key == '?': continue if len(status[key]) != 0: print(status) ret, m = dialog.message(app0, "Local repo status is not clean. \n(" + self.get_full_path()+')', "Mercurial Update Error") self.hg_set_projtreeviewer_status(repo) # self._status = '!' return None repo.hg_update(long(m)) parent = self.get_parent() owndir = self.owndir() name = self._name ichild = self.get_ichild() url, root, path = self.get_mercurial_url() self.destroy(clean_owndir=False) del_old_treedata = False load_fpath = True fpath=os.path.join(owndir, ".tree_data_hg") if not os.path.exists(fpath): fpath=os.path.join(owndir, ".tree_data") if not os.path.exists(fpath): print((url, root, path)) td = handle_pure_file_repo(parent, name, owndir) load_fpath = False else: dlg=wx.MessageDialog(None, 'HG update succeeded but .tree_data_hg is not found.', 'Old style for HG repo', wx.OK) ret=dlg.ShowModal() dlg.Destroy() fpath=os.path.join(owndir, ".tree_data") del_old_treedata = True if load_fpath: fid= open(fpath, 'rb') td, olist, nlist = TreeDict().load(fid, keep_zorder=True) fid.close() parent.add_child(name, td, keep_zorder = True) parent.move_child(td.get_ichild(), ichild) if load_fpath: for obj in td.walk_tree(): obj.init_after_load(olist, nlist) if del_old_treedata: os.remove(fpath) if url is not None: td.set_mercurial_url(root, path) if evt is not None: # evt.GetEventObject().update_widget_request2() ifigure.events.SendFileSystemChangedEvent(parent, reload = True) evt.Skip() return td
def load_subtree_hg(parent, root = '', path='', name = '', overwrite=False, run_setup=False, launch_gui=False): app = wx.GetApp().TopWindow if root == '': list6 = [ ["root repository", None, 304, dlg_s()], ["source ", path, 0], ["destination", '', 0], [None, True, 3, {"text":'Run setup script'}],] value = DialogEditList(list6, modal = True, style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, tip = None, parent=app, title = 'retrieve subtree from HG repo.') if not value[0]: return if not parent.has_owndir(): parent.mk_owndir() # url = rootpath2url( root = str(value[1][0]) path = str(value[1][1]) name = str(value[1][2]) run_setup = value[1][3] if name.strip() == '': name = value[1][1].split('/')[-1] else: if not parent.has_owndir(): parent.mk_owndir() if name == '': name = path.split('/')[-1] if parent.has_child(name): if overwrite: parent.get_child(name = name).destroy() else: print(parent.get_full_path()+'.'+name + ' already exists.') obj = parent.get_child(name = name) _add_include_exclude(obj) return obj if path.startswith('/'): path = path[1:] url = rootpath2url(root, path) dpath = os.path.join(parent.owndir(), name) repo = hgapi.Repo(parent.owndir()) try: repo2 = repo.hg_clone(url, dpath) except: print url, dpath dialog.showtraceback(parent = app, txt='Failed to clone subtree from '+url, title='Failed to clone', traceback=traceback.format_exc()) return load_fpath = True fpath=os.path.join(dpath, ".tree_data_hg") if not os.path.exists(fpath): fpath=os.path.join(dpath, ".tree_data") if not os.path.exists(fpath): # # In this case, it makes a containing folder # and gather *.py to make PyScript # I should be handling other files here too? # td = handle_pure_file_repo(parent, name, dpath) load_fpath = False else: dlg=wx.MessageDialog(None, 'HG update succeeded but .tree_data_hg is not found.', 'Old style for HG repo', wx.OK) ret=dlg.ShowModal() dlg.Destroy() del_old_treedata = True else: del_old_treedata = False if load_fpath: fid= open(fpath, 'rb') td, olist, nlist = TreeDict().load(fid, keep_zorder=True) fid.close() parent.add_child(name, td, keep_zorder = True) ### for sub repo subrepos = [] for name, child in td.get_children(): # print child for obj in child.walk_tree(): if has_repo(obj): #print 'subrepo', obj load_repo_treedata(obj) if del_old_treedata: os.remove(fpath) for obj in td.walk_tree(): obj.init_after_load(olist, nlist) td.set_mercurial_url(root, path) for name, child in td.get_children(): # print child for obj in child.walk_tree(): if has_repo(obj): r = hgapi.Repo(obj.owndir()) latest = r.revisions(slice(-1,-1))[0].rev current = r.hg_rev() if latest > current: dprint1('updating ' + str(obj)+ ' ' + str(r.hg_rev()) + '->' + str(latest)) obj.onHGupdate(evt=None, m=latest) if run_setup: # try: if (td.has_child("scripts") and td.scripts.has_child("setup")): # wx.CallAfter(td.scripts.setup.Run) td.scripts.setup.Run() # except: # dialog.showtraceback(parent = td.get_root_parent().app, # txt='Failed to run setup script', # title='Setup script failced', # traceback=traceback.format_exc()) _add_include_exclude(td) return td
def onHGupdate(self, evt=None, m=None): repo = hgapi.Repo(self.owndir()) app0 = wx.GetApp().TopWindow if m is None: latest = repo.revisions(slice(-1, -1))[0].rev ret, m = dialog.textentry(app0, "Enter revision #", "Mercurial Update", str(latest)) if not ret: return None status = repo.hg_status() for key in status: if key == '?': continue if len(status[key]) != 0: print(status) ret, m = dialog.message( app0, "Local repo status is not clean. \n(" + self.get_full_path() + ')', "Mercurial Update Error") self.hg_set_projtreeviewer_status(repo) # self._status = '!' return None repo.hg_update(long(m)) parent = self.get_parent() owndir = self.owndir() name = self._name ichild = self.get_ichild() url, root, path = self.get_mercurial_url() self.destroy(clean_owndir=False) del_old_treedata = False load_fpath = True fpath = os.path.join(owndir, ".tree_data_hg") if not os.path.exists(fpath): fpath = os.path.join(owndir, ".tree_data") if not os.path.exists(fpath): print((url, root, path)) td = handle_pure_file_repo(parent, name, owndir) load_fpath = False else: dlg = wx.MessageDialog( None, 'HG update succeeded but .tree_data_hg is not found.', 'Old style for HG repo', wx.OK) ret = dlg.ShowModal() dlg.Destroy() fpath = os.path.join(owndir, ".tree_data") del_old_treedata = True if load_fpath: fid = open(fpath, 'rb') td, olist, nlist = TreeDict().load(fid, keep_zorder=True) fid.close() parent.add_child(name, td, keep_zorder=True) parent.move_child(td.get_ichild(), ichild) if load_fpath: for obj in td.walk_tree(): obj.init_after_load(olist, nlist) if del_old_treedata: os.remove(fpath) if url is not None: td.set_mercurial_url(root, path) if evt is not None: # evt.GetEventObject().update_widget_request2() ifigure.events.SendFileSystemChangedEvent(parent, reload=True) evt.Skip() return td
def load_subtree_hg(parent, root='', path='', name='', overwrite=False, run_setup=False, launch_gui=False): app = wx.GetApp().TopWindow if root == '': list6 = [ ["root repository", None, 304, dlg_s()], ["source ", path, 0], ["destination", '', 0], [None, True, 3, { "text": 'Run setup script' }], ] value = DialogEditList(list6, modal=True, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, tip=None, parent=app, title='retrieve subtree from HG repo.') if not value[0]: return if not parent.has_owndir(): parent.mk_owndir() # url = rootpath2url( root = str(value[1][0]) path = str(value[1][1]) name = str(value[1][2]) run_setup = value[1][3] if name.strip() == '': name = value[1][1].split('/')[-1] else: if not parent.has_owndir(): parent.mk_owndir() if name == '': name = path.split('/')[-1] if parent.has_child(name): if overwrite: parent.get_child(name=name).destroy() else: print(parent.get_full_path() + '.' + name + ' already exists.') obj = parent.get_child(name=name) _add_include_exclude(obj) return obj if path.startswith('/'): path = path[1:] url = rootpath2url(root, path) dpath = os.path.join(parent.owndir(), name) repo = hgapi.Repo(parent.owndir()) try: repo2 = repo.hg_clone(url, dpath) except: print url, dpath dialog.showtraceback(parent=app, txt='Failed to clone subtree from ' + url, title='Failed to clone', traceback=traceback.format_exc()) return load_fpath = True fpath = os.path.join(dpath, ".tree_data_hg") if not os.path.exists(fpath): fpath = os.path.join(dpath, ".tree_data") if not os.path.exists(fpath): # # In this case, it makes a containing folder # and gather *.py to make PyScript # I should be handling other files here too? # td = handle_pure_file_repo(parent, name, dpath) load_fpath = False else: dlg = wx.MessageDialog( None, 'HG update succeeded but .tree_data_hg is not found.', 'Old style for HG repo', wx.OK) ret = dlg.ShowModal() dlg.Destroy() del_old_treedata = True else: del_old_treedata = False if load_fpath: fid = open(fpath, 'rb') td, olist, nlist = TreeDict().load(fid, keep_zorder=True) fid.close() parent.add_child(name, td, keep_zorder=True) ### for sub repo subrepos = [] for name, child in td.get_children(): # print child for obj in child.walk_tree(): if has_repo(obj): #print 'subrepo', obj load_repo_treedata(obj) if del_old_treedata: os.remove(fpath) for obj in td.walk_tree(): obj.init_after_load(olist, nlist) td.set_mercurial_url(root, path) for name, child in td.get_children(): # print child for obj in child.walk_tree(): if has_repo(obj): r = hgapi.Repo(obj.owndir()) latest = r.revisions(slice(-1, -1))[0].rev current = r.hg_rev() if latest > current: dprint1('updating ' + str(obj) + ' ' + str(r.hg_rev()) + '->' + str(latest)) obj.onHGupdate(evt=None, m=latest) if run_setup: # try: if (td.has_child("scripts") and td.scripts.has_child("setup")): # wx.CallAfter(td.scripts.setup.Run) td.scripts.setup.Run() # except: # dialog.showtraceback(parent = td.get_root_parent().app, # txt='Failed to run setup script', # title='Setup script failced', # traceback=traceback.format_exc()) _add_include_exclude(td) return td