diff options
author | Christopher Harvey <chris@basementcode.com> | 2010-06-02 06:14:57 -0400 |
---|---|---|
committer | Christopher Harvey <chris@basementcode.com> | 2010-06-02 06:14:57 -0400 |
commit | 817b1b8538f345bb8791fc0af31745c0d9d027fe (patch) | |
tree | f39b7f23a3628e931e1848fe98a104d0f67fc396 /src | |
parent | Fixed a bug removing elements while working in / (diff) | |
parent | Removed use of meld. Diffs are generated with difflib and html is generate wi... (diff) | |
download | ventoo-817b1b8538f345bb8791fc0af31745c0d9d027fe.tar.gz ventoo-817b1b8538f345bb8791fc0af31745c0d9d027fe.tar.bz2 ventoo-817b1b8538f345bb8791fc0af31745c0d9d027fe.zip |
Merge branch 'internalDiff'
Diffstat (limited to 'src')
-rw-r--r-- | src/frontend/main.py | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/frontend/main.py b/src/frontend/main.py index 9c7be75..de37b24 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 = '/' @@ -154,12 +158,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("<html>\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("</html>\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)) @@ -326,22 +348,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) |