From 031236c106a3b6dadd72d3d95f51fbe097cfeadc Mon Sep 17 00:00:00 2001 From: Christopher Harvey Date: Tue, 1 Jun 2010 12:37:31 -0400 Subject: Removed use of meld. Diffs are generated with difflib and html is generate with pygments. Diffs are displayed in documentation location as requested by the user. --- src/frontend/main.py | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/frontend/main.py b/src/frontend/main.py index 71e2340..141bf59 100644 --- a/src/frontend/main.py +++ b/src/frontend/main.py @@ -35,6 +35,10 @@ import os import re import ErrorDialog import gtkmozembed +import difflib +from pygments import highlight +from pygments.lexers import DiffLexer +from pygments.formatters import HtmlFormatter sandboxDir = '/' @@ -151,12 +155,30 @@ class MainWindow(gtk.Window): #to be sure the save worked. augeas_utils.makeDiffTree(self.a, augeas_utils.getDiffRoot()) diffFiles = [self.currentConfigFilePath, augeas_utils.getDiffLocation(self.a, self.currentConfigFilePath)] - call = "meld " + diffFiles[0] + " " + diffFiles[1] + " &" - print call if not osp.isfile(diffFiles[1]): print "Could not find a diff file...were changes made?" else: - os.system(call) + origFile = open(diffFiles[0]) + origList = file.readlines(origFile) + origFile.close() + newFile = open(diffFiles[1]) + newList = file.readlines(newFile) + newFile.close() + #now we have origList and newList that is the text for the diff + d = difflib.Differ() + thediff = list(d.compare(origList, newList)) + #TODO: append username, to avoid conflicts + outFile = open("/tmp/ventooDiff.html", 'w') + outFile.write("\n") + theDiff = difflib.unified_diff(origList, newList) + text = "" + for l in theDiff: + text += l + highlight(text, DiffLexer(), HtmlFormatter(full=True, linenos=True, cssclass="source"), outFile) + outFile.write("\n") + outFile.close() + self.docWindow.load_url("file:///tmp/ventooDiff.html") + def showErrPressed(self, button, data=None): d = ErrorDialog.ErrorDialog(augeas_utils.getFileErrorList(self.a)) @@ -323,22 +345,7 @@ if __name__ == '__main__': print 'Creating window...' if sandboxDir == '/': - print """ - -You're running this program on your root directory - This program sometimes has problems with the root directory. - If you're running as root it can't display diff. - if you're not running as root it can't save the system files - (because it doesn't have the permissions to do so. - - Displaying diffs as root will be fixed as soon as I figure out the - right way to do it. - - In the meantime, consider: - cp -r /etc /tmp - python thisProgram.py /tmp - (as non-root)""" - + pass #Note, it IS possible to create mutiple windows and augeas #instances to edit multiple "roots" at the same time. window = MainWindow(a) -- cgit v1.2.3-65-gdbad