diff options
author | Sean Finney <seanius@debian.org> | 2010-05-13 12:17:57 +0200 |
---|---|---|
committer | Sean Finney <seanius@debian.org> | 2010-05-13 12:17:57 +0200 |
commit | 9649bd16ef6cadc96c2c6e96f3449aa62646df66 (patch) | |
tree | a79f67398b8b36bdc4a46a5cf1a3aae9398b2ece /patchtracker/Patch.py | |
parent | e2a079386b6f95deeadcea4cd3e2a04fafbf467a (diff) | |
download | patch-tracker-9649bd16ef6cadc96c2c6e96f3449aa62646df66.tar.gz |
Implement series patch download and view in django
Diffstat (limited to 'patchtracker/Patch.py')
-rw-r--r-- | patchtracker/Patch.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/patchtracker/Patch.py b/patchtracker/Patch.py index 6533910..09f4911 100644 --- a/patchtracker/Patch.py +++ b/patchtracker/Patch.py @@ -2,6 +2,9 @@ import sys import os import errno from glob import glob +import pygments +import pygments.lexers +import pygments.formatters import tarfile class Diffstat: @@ -39,6 +42,14 @@ class Patch: def diffstat(self): return Diffstat(self) + def highlight(self): + for enc in ['utf-8', 'latin-1']: + try: + return pygments.highlight(str(self).decode(enc), pygments.lexers.DiffLexer(), + pygments.formatters.HtmlFormatter(style='colorful', noclasses=True, encoding=enc, nobackground=True)) + except UnicodeDecodeError: + pass + class GenericPatchSeries (list): def blank(self): self.names = [] |