Commit 162ad966 authored by Christophe Dumez's avatar Christophe Dumez

- Improved diff display

- Allow to display full file content with syntax highlight


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6427 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f3c66dde
...@@ -34,6 +34,7 @@ from MethodObject import Method ...@@ -34,6 +34,7 @@ from MethodObject import Method
from Globals import InitializeClass from Globals import InitializeClass
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.PythonScripts.Utility import allow_class
from zLOG import LOG from zLOG import LOG
try: try:
...@@ -67,12 +68,15 @@ try: ...@@ -67,12 +68,15 @@ try:
class SubversionSSLTrustError(SubversionError): class SubversionSSLTrustError(SubversionError):
"""Raised when a SSL certificate is not trusted. """Raised when a SSL certificate is not trusted.
""" """
# Declarative Security
security = ClassSecurityInfo()
def __init__(self, trust_dict = None): def __init__(self, trust_dict = None):
self._trust_dict = trust_dict self._trust_dict = trust_dict
security.declarePublic('getTrustDict')
def getTrustDict(self): def getTrustDict(self):
return self._trust_dict return self._trust_dict
class Callback: class Callback:
"""The base class for callback functions. """The base class for callback functions.
...@@ -102,8 +106,9 @@ try: ...@@ -102,8 +106,9 @@ try:
def __call__(self, realm, username, may_save): def __call__(self, realm, username, may_save):
user, password = self.client.getLogin(realm) user, password = self.client.getLogin(realm)
if user is None: if user is None:
raise SubversionLoginError(realm) self.client.setException(SubversionLoginError(realm))
#return False, '', '', False #raise SubversionLoginError(realm)
return False, '', '', False
return True, user, password, False return True, user, password, False
class NotifyCallback(Callback): class NotifyCallback(Callback):
...@@ -251,6 +256,9 @@ try: ...@@ -251,6 +256,9 @@ try:
def newSubversionClient(container, **kw): def newSubversionClient(container, **kw):
return SubversionClient(container, **kw).__of__(container) return SubversionClient(container, **kw).__of__(container)
InitializeClass(SubversionSSLTrustError)
allow_class(SubversionSSLTrustError)
except ImportError: except ImportError:
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
LOG('SubversionTool', WARNING, LOG('SubversionTool', WARNING,
......
...@@ -34,7 +34,7 @@ from Products.ERP5Type import Permissions ...@@ -34,7 +34,7 @@ from Products.ERP5Type import Permissions
from Products.ERP5Subversion import _dtmldir from Products.ERP5Subversion import _dtmldir
from zLOG import LOG, WARNING, INFO from zLOG import LOG, WARNING, INFO
from Products.ERP5Subversion.SubversionClient import newSubversionClient from Products.ERP5Subversion.SubversionClient import newSubversionClient
import os, re import os, re, commands
from DateTime import DateTime from DateTime import DateTime
from cPickle import dumps, loads from cPickle import dumps, loads
from App.config import getConfiguration from App.config import getConfiguration
...@@ -124,26 +124,28 @@ class DiffFile: ...@@ -124,26 +124,28 @@ class DiffFile:
def toHTML(self): def toHTML(self):
# Adding header of the table # Adding header of the table
html = '''<font color='black'><b>%s</b><br> html = '''
<hr><br>
<table style="text-align: left; width: 100%%;" border="0" cellpadding="0" cellspacing="0"> <table style="text-align: left; width: 100%%;" border="0" cellpadding="0" cellspacing="0">
<tbody> <tbody>
<tr height="18px"> <tr height="18px">
<td style="background-color: grey"><b><center>%s</center></b></td> <td style="background-color: grey"><b><center>%s</center></b></td>
<td style="background-color: black;" width="2"></td>
<td style="background-color: grey"><b><center>%s</center></b></td> <td style="background-color: grey"><b><center>%s</center></b></td>
</tr>'''%(self.path, self.old_revision, self.new_revision) </tr>'''%(self.old_revision, self.new_revision)
First = True First = True
for child in self.children: for child in self.children:
# Adding line number of the modification # Adding line number of the modification
if First: if First:
html += '''<tr height="18px"><td style="background-color: grey">&nbsp;</td><td style="background-color: grey">&nbsp;</td></tr> <tr> html += '''<tr height="18px"><td style="background-color: grey">&nbsp;</td><td style="background-color: black;" width="2"></td><td style="background-color: grey">&nbsp;</td></tr> <tr height="18px">
<td style="background-color: rgb(68, 132, 255);"><b>Line %s</b></td> <td style="background-color: rgb(68, 132, 255);"><b>Line %s</b></td>
<td style="background-color: black;" width="2"></td>
<td style="background-color: rgb(68, 132, 255);"><b>Line %s</b></td> <td style="background-color: rgb(68, 132, 255);"><b>Line %s</b></td>
</tr>'''%(child.old_line, child.new_line) </tr>'''%(child.old_line, child.new_line)
First = False First = False
else: else:
html += '''<tr height="18px"><td style="background-color: white">&nbsp;</td><td style="background-color: white">&nbsp;</td></tr> <tr> html += '''<tr height="18px"><td style="background-color: white">&nbsp;</td><td style="background-color: black;" width="2"></td><td style="background-color: white">&nbsp;</td></tr> <tr height="18px">
<td style="background-color: rgb(68, 132, 255);"><b>Line %s</b></td> <td style="background-color: rgb(68, 132, 255);"><b>Line %s</b></td>
<td style="background-color: black;" width="2"></td>
<td style="background-color: rgb(68, 132, 255);"><b>Line %s</b></td> <td style="background-color: rgb(68, 132, 255);"><b>Line %s</b></td>
</tr>'''%(child.old_line, child.new_line) </tr>'''%(child.old_line, child.new_line)
# Adding diff of the modification # Adding diff of the modification
...@@ -163,6 +165,7 @@ class DiffFile: ...@@ -163,6 +165,7 @@ class DiffFile:
i+=1 i+=1
html += ''' <tr height="18px"> html += ''' <tr height="18px">
<td style="background-color: %s">%s</td> <td style="background-color: %s">%s</td>
<td style="background-color: black;" width="2"></td>
<td style="background-color: %s">%s</td> <td style="background-color: %s">%s</td>
</tr>'''%(old_line_tuple[1], self._escape(old_line).replace(' ', '&nbsp;').replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'), new_line_tuple[1], self._escape(new_line).replace(' ', '&nbsp;').replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')) </tr>'''%(old_line_tuple[1], self._escape(old_line).replace(' ', '&nbsp;').replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'), new_line_tuple[1], self._escape(new_line).replace(' ', '&nbsp;').replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'))
html += ''' </tbody> html += ''' </tbody>
...@@ -405,12 +408,29 @@ class SubversionTool(UniqueObject, Folder): ...@@ -405,12 +408,29 @@ class SubversionTool(UniqueObject, Folder):
def _decodeSSLTrust(self, trust): def _decodeSSLTrust(self, trust):
# Decode login information. # Decode login information.
trust_item_list, permanent = loads(b64decode(login)) trust_item_list, permanent = loads(b64decode(trust))
return dict(trust_item_list), permanent return dict(trust_item_list), permanent
def diffHTML(self, file_path): def diffHTML(self, file_path):
raw_diff = self.diff(file_path) raw_diff = self.diff(file_path)
return DiffFile(raw_diff).toHTML() return DiffFile(raw_diff).toHTML()
# Display a file content in HTML
def fileHTML(self, file_path):
# file = open(file_path, 'r')
# text = file.read()
# file.close()
# # Escaping
# text = text.replace("&", "&amp;")
# text = text.replace(">", "&gt;")
# text = text.replace("<", "&lt;")
# # Adding HTML stuff
# text = text.replace('\n', '<br>')
# text = text.replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')
# text = text.replace(' ', '&nbsp;&nbsp;')
text = commands.getoutput('enscript -B --color --highlight=html --language=html -o - %s'%file_path)
text = '\n'.join(text.split('\n')[10:-4])
return text
security.declareProtected(Permissions.ManagePortal, 'acceptSSLServer') security.declareProtected(Permissions.ManagePortal, 'acceptSSLServer')
def acceptSSLServer(self, trust_dict, permanent=False): def acceptSSLServer(self, trust_dict, permanent=False):
...@@ -421,13 +441,16 @@ class SubversionTool(UniqueObject, Folder): ...@@ -421,13 +441,16 @@ class SubversionTool(UniqueObject, Folder):
request = self.REQUEST request = self.REQUEST
cookie = request.get(self.ssl_trust_cookie_name) cookie = request.get(self.ssl_trust_cookie_name)
if cookie: if cookie:
trust.append(cookie) trust_list.append(cookie)
# Set the cookie. # Set the cookie.
response = request.RESPONSE response = request.RESPONSE
trust_list.append(self._encodeSSLTrust(trust_dict, permanent)) trust_list.append(self._encodeSSLTrust(trust_dict, permanent))
value = ','.join(trust_list) value = ','.join(trust_list)
expires = (DateTime() + 1).toZone('GMT').rfc822() expires = (DateTime() + 1).toZone('GMT').rfc822()
response.setCookie(self.ssl_trust_cookie_name, value, path = '/', expires = expires) response.setCookie(self.ssl_trust_cookie_name, value, path = '/', expires = expires)
def acceptSSLPerm(self, trust_dict):
self.acceptSSLServer(self, trust_dict, True)
def _trustSSLServer(self, target_trust_dict): def _trustSSLServer(self, target_trust_dict):
request = self.REQUEST request = self.REQUEST
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment