def run_diff_on_saved(self, event=None): """run_diff_on_saved - compare current node content to saved content :Parameters: - `event`: Leo event """ c = self.c gnx = c.p.gnx tree = leosax.get_leo_data(c.fileName()) for node in tree.flat(): if node.gnx == gnx: node.b = ''.join(node.b) self.run_appropriate_diff([node, c.p]) return g.es("Node (gnx) not found in saved file")
def run_diff_on_vcs(self, event=None): """run_diff_on_vcs - try and check out the previous version of the Leo file and compare a node with the same gnx in that file with the current node :Parameters: - `event`: Leo event """ c = self.c dir_, filename = g.os_path_split(c.fileName()) relative_path = [] # path from top of repo. to .leo file mode = None # mode is which VCS to use # given A=/a/b/c/d/e, B=file.leo adjust to A=/a/b/c, B=d/e/file.leo # so that A is the path to the repo. and B the path in the repo. to # the .leo file path = dir_ while not mode: for vcs in 'git', 'bzr': if g.os_path_exists(g.os_path_join(path, '.' + vcs)): mode = vcs break else: path, subpath = g.os_path_split(path) if not subpath: break relative_path[0:0] = [subpath] if not mode: g.es("No supported VCS found in '%s'" % dir_) return gnx = c.p.gnx if mode == 'git': cmd = [ 'git', '--work-tree=%s' % path, 'show', 'HEAD:%s' % g.os_path_join(*(relative_path + [filename])), ] if mode == 'bzr': cmd = [ 'bzr', 'cat', '--revision=revno:-1', c.fileName(), # path, # g.os_path_join( *(relative_path + [filename]) ), ] cmd = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) data, err = cmd.communicate() aFile = StringIO(data) tree = leosax.get_leo_data(aFile) for node in tree.flat(): if node.gnx == gnx: node.b = ''.join(node.b) self.run_appropriate_diff([node, c.p]) return g.es("Node (gnx) not found in previous version")
def run_diff_on_vcs(self, event=None): """run_diff_on_vcs - try and check out the previous version of the Leo file and compare a node with the same gnx in that file with the current node :Parameters: - `event`: Leo event """ c = self.c dir_, filename = g.os_path_split(c.fileName()) relative_path = [] # path from top of repo. to .leo file mode = None # mode is which VCS to use # given A=/a/b/c/d/e, B=file.leo adjust to A=/a/b/c, B=d/e/file.leo # so that A is the path to the repo. and B the path in the repo. to # the .leo file path = dir_ while not mode: for vcs in 'git', 'bzr': if g.os_path_exists(g.os_path_join(path, '.'+vcs)): mode = vcs break else: path, subpath = g.os_path_split(path) if not subpath: break relative_path[0:0] = [subpath] if not mode: g.es("No supported VCS found in '%s'"%dir_) return gnx = c.p.gnx if mode == 'git': cmd = [ 'git', '--work-tree=%s' % path, 'show', 'HEAD:%s' % g.os_path_join( *(relative_path + [filename]) ), ] if mode == 'bzr': cmd = [ 'bzr', 'cat', '--revision=revno:-1', c.fileName(), # path, # g.os_path_join( *(relative_path + [filename]) ), ] cmd = subprocess.Popen( cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) data, err = cmd.communicate() aFile = StringIO(data) tree = leosax.get_leo_data(aFile) for node in tree.flat(): if node.gnx == gnx: break else: g.es("Node (gnx) not found in previous version") return node.b = ''.join(node.b) self.run_appropriate_diff([node, c.p])