summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Macken <lmacken@redhat.com>2011-12-01 19:38:20 (GMT)
committerLuke Macken <lmacken@redhat.com>2011-12-01 19:38:20 (GMT)
commit80dbe214ac33f5c84315877490be02218d24d6dc (patch)
tree7830c1f1c9099bce22404bf259b91676fb806104
parent55e73a72b0a16d3f98d0fbacbd506af583dfdee4 (diff)
downloadfedoracommunity-80dbe214ac33f5c84315877490be02218d24d6dc.zip
fedoracommunity-80dbe214ac33f5c84315877490be02218d24d6dc.tar.gz
fedoracommunity-80dbe214ac33f5c84315877490be02218d24d6dc.tar.xz
Add a basic patch viewer with syntax highlighting.
-rw-r--r--fedoracommunity/widgets/package/sources.py28
-rw-r--r--fedoracommunity/widgets/package/templates/patch.mak1
-rw-r--r--fedoracommunity/widgets/package/templates/patches.mak22
-rwxr-xr-xsetup.py1
4 files changed, 46 insertions, 6 deletions
diff --git a/fedoracommunity/widgets/package/sources.py b/fedoracommunity/widgets/package/sources.py
index 9901fbe..960ec0e 100644
--- a/fedoracommunity/widgets/package/sources.py
+++ b/fedoracommunity/widgets/package/sources.py
@@ -8,6 +8,9 @@ from tg import config
from mako.template import Template
from collections import OrderedDict
from moksha.lib.helpers import DateTimeDisplay
+from pygments import highlight
+from pygments.lexers import DiffLexer
+from pygments.formatters import HtmlFormatter
from package import TabWidget
@@ -38,8 +41,7 @@ class FedoraGitRepo(object):
cwd=config.get('git_repo_path'))
def get_spec(self):
- spec = self.repo.tree()[self.package + '.spec']
- return spec.data_stream.read()
+ return self.repo.tree()[self.package + '.spec'].data_stream.read()
def get_patches(self):
patches = {}
@@ -52,11 +54,13 @@ class FedoraGitRepo(object):
]
return patches
+ def get_patch(self, filename):
+ return self.repo.tree()[filename].data_stream.read()
+
def get_creation_time(self, filename):
date = ' '.join(self.repo.git.log(filename, reverse=True).split('\n')[2].split()[1:-1])
return DateTimeDisplay(date, format='%a %b %d %H:%M:%S %Y').datetime
-
class Sources(TabWidget):
tabs = OrderedDict([
('Spec', 'package.sources.spec'),
@@ -83,14 +87,30 @@ class Spec(twc.Widget):
class Patches(twc.Widget):
kwds = twc.Param(default=None)
patches = twc.Param(default=None)
+ package = twc.Variable()
template = 'mako:fedoracommunity/widgets/package/templates/patches.mak'
def prepare(self):
super(Patches, self).prepare()
- repo = FedoraGitRepo(self.kwds['package_name'])
+ self.package = self.kwds['package_name']
+ repo = FedoraGitRepo(self.package)
self.patches = repo.get_patches()
+class Patch(twc.Widget):
+ package = twc.Param('The name of the package')
+ patch = twc.Param('The filename of the patch')
+ text = twc.Variable('The text of the patch')
+ template = 'mako:fedoracommunity/widgets/package/templates/patch.mak'
+
+ def prepare(self):
+ super(Patch, self).prepare()
+ repo = FedoraGitRepo(self.package)
+ diff = repo.get_patch(self.patch)
+ self.text = highlight(diff, DiffLexer(),
+ HtmlFormatter(full=True, linenos=True))
+
+
class Diffs(twc.Widget):
template = 'mako:fedoracommunity/widgets/package/templates/diffs.mak'
def prepare(self):
diff --git a/fedoracommunity/widgets/package/templates/patch.mak b/fedoracommunity/widgets/package/templates/patch.mak
new file mode 100644
index 0000000..fc4d0c2
--- /dev/null
+++ b/fedoracommunity/widgets/package/templates/patch.mak
@@ -0,0 +1 @@
+${w.text}
diff --git a/fedoracommunity/widgets/package/templates/patches.mak b/fedoracommunity/widgets/package/templates/patches.mak
index a79d8ff..54b0281 100644
--- a/fedoracommunity/widgets/package/templates/patches.mak
+++ b/fedoracommunity/widgets/package/templates/patches.mak
@@ -1,9 +1,27 @@
<table>
% for patch in sorted(w.patches):
- <tr>
- <td>${patch}</td>
+ <tr id="${patch}">
+ <td><a href="#" onclick="return show_patch('${patch}');">${patch}</a></td>
<td>Added ${w.patches[patch][0]} ago</td>
<td>(${w.patches[patch][1]})</td>
</tr>
% endfor
</table>
+
+<script type="text/javascript">
+function show_patch(patch) {
+ var tr = $('#' + patch.replace(/\./g, '\\.'));
+
+ /* If we're already showing the patch, hide it */
+ if ( tr.next().attr('id') == 'patch' ) {
+ tr.next().remove();
+ return false;
+ }
+
+ tr.after(
+ $('<tr/>', {id: 'patch'}).append(
+ $('<td/>', {colspan: 3}).load('/widgets/package.sources.patch',
+ {package: '${w.package}', patch: patch})));
+ return false;
+}
+</script>
diff --git a/setup.py b/setup.py
index 4e729a1..1cad9c8 100755
--- a/setup.py
+++ b/setup.py
@@ -128,6 +128,7 @@ setup(
package.sources = fedoracommunity.widgets.package.sources:Sources
package.sources.spec = fedoracommunity.widgets.package.sources:Spec
package.sources.patches = fedoracommunity.widgets.package.sources:Patches
+ package.sources.patch = fedoracommunity.widgets.package.sources:Patch
package.sources.diffs = fedoracommunity.widgets.package.sources:Diffs
package.sources.tarballs = fedoracommunity.widgets.package.sources:Tarballs
package.sources.git = fedoracommunity.widgets.package.sources:GitRepo