Commit b2e25a4a authored by Christophe Dumez's avatar Christophe Dumez

- fixed typo in allow_module

- added yoshinori's work on exception handling


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6398 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3d37eda5
...@@ -38,6 +38,7 @@ from zLOG import LOG ...@@ -38,6 +38,7 @@ from zLOG import LOG
try: try:
import pysvn import pysvn
class SubversionError(Exception): class SubversionError(Exception):
"""The base exception class for the Subversion interface. """The base exception class for the Subversion interface.
...@@ -114,8 +115,9 @@ try: ...@@ -114,8 +115,9 @@ try:
def __call__(self, trust_dict): def __call__(self, trust_dict):
trust, permanent = self.client.trustSSLServer(trust_dict) trust, permanent = self.client.trustSSLServer(trust_dict)
if not trust: if not trust:
raise SubversionSSLTrustError(trust_dict) #raise SubversionSSLTrustError(trust_dict)
#return False, 0, False self.client.setException(SubversionSSLTrustError(trust_dict))
return False, 0, False
# XXX SSL server certificate failure bits are not defined in pysvn. # XXX SSL server certificate failure bits are not defined in pysvn.
# 0x8 means that the CA is unknown. # 0x8 means that the CA is unknown.
return True, 0x8, permanent return True, 0x8, permanent
...@@ -177,15 +179,16 @@ try: ...@@ -177,15 +179,16 @@ try:
log_message = None log_message = None
timeout = 60 * 5 timeout = 60 * 5
def __init__(self, **kw): def __init__(self, container, **kw):
self.client = pysvn.Client() self.client = pysvn.Client()
self.client.set_auth_cache(0) self.client.set_auth_cache(0)
self.client.callback_cancel = CancelCallback(self) obj = self.__of__(container)
self.client.callback_get_log_message = GetLogMessageCallback(self) self.client.callback_cancel = CancelCallback(obj)
self.client.callback_get_login = GetLoginCallback(self) self.client.callback_get_log_message = GetLogMessageCallback(obj)
self.client.callback_get_login = GetLoginCallback(obj)
#self.client.callback_get_login = self.callback_get_Login #self.client.callback_get_login = self.callback_get_Login
self.client.callback_notify = NotifyCallback(self) self.client.callback_notify = NotifyCallback(obj)
self.client.callback_ssl_server_trust_prompt = SSLServerTrustPromptCallback(self) self.client.callback_ssl_server_trust_prompt = SSLServerTrustPromptCallback(obj)
#self.client.callback_ssl_server_trust_prompt = self.callback_ssl_server_trust_prompt #self.client.callback_ssl_server_trust_prompt = self.callback_ssl_server_trust_prompt
self.creation_time = time.time() self.creation_time = time.time()
self.__dict__.update(kw) self.__dict__.update(kw)
...@@ -218,10 +221,19 @@ try: ...@@ -218,10 +221,19 @@ try:
# def callback_ssl_server_trust_prompt( self, trust_data ): # def callback_ssl_server_trust_prompt( self, trust_data ):
# # Always trusting # # Always trusting
# return True, trust_data['failures'], True # return True, trust_data['failures'], True
def setException(self, exc):
self.exception = exc
def getException(self):
return self.exception
def checkin(self, path, log_message, recurse): def checkin(self, path, log_message, recurse):
self._getPreferences() self._getPreferences()
return self.client.checkin(path, log_message=log_message, recurse=recurse) try:
return self.client.checkin(path, log_message=log_message, recurse=recurse)
except pysvn.ClientError:
raise self.getException()
def status(self, path, **kw): def status(self, path, **kw):
# Since plain Python classes are not convenient in Zope, convert the objects. # Since plain Python classes are not convenient in Zope, convert the objects.
...@@ -237,7 +249,7 @@ try: ...@@ -237,7 +249,7 @@ try:
return self.client.revert(path) return self.client.revert(path)
def newSubversionClient(container, **kw): def newSubversionClient(container, **kw):
return SubversionClient(**kw).__of__(container) return SubversionClient(container, **kw).__of__(container)
except ImportError: except ImportError:
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
......
...@@ -81,36 +81,36 @@ class DiffFile: ...@@ -81,36 +81,36 @@ class DiffFile:
# - old_revision # - old_revision
# - new_revision # - new_revision
def __init__(this, raw_diff): def __init__(self, raw_diff):
this.header = raw_diff.split('@@')[0][:-1] self.header = raw_diff.split('@@')[0][:-1]
# Getting file path in header # Getting file path in header
this.path = this.header.split('====')[0][:-1].strip() self.path = self.header.split('====')[0][:-1].strip()
# Getting revisions in header # Getting revisions in header
for line in this.header.split('\n'): for line in self.header.split('\n'):
if line.startswith('--- '): if line.startswith('--- '):
tmp = re.search('\\([\w\s]+\\)$', line) tmp = re.search('\\([\w\s]+\\)$', line)
this.old_revision = tmp.string[tmp.start():tmp.end()][1:-1].strip() self.old_revision = tmp.string[tmp.start():tmp.end()][1:-1].strip()
if line.startswith('+++ '): if line.startswith('+++ '):
tmp = re.search('\\([\w\s]+\\)$', line) tmp = re.search('\\([\w\s]+\\)$', line)
this.new_revision = tmp.string[tmp.start():tmp.end()][1:-1].strip() self.new_revision = tmp.string[tmp.start():tmp.end()][1:-1].strip()
# Splitting the body from the header # Splitting the body from the header
this.body = '\n'.join(raw_diff.strip().split('\n')[4:]) self.body = '\n'.join(raw_diff.strip().split('\n')[4:])
# Now splitting modifications # Now splitting modifications
this.children = [] self.children = []
first = True first = True
tmp = [] tmp = []
for line in this.body.split('\n'): for line in self.body.split('\n'):
if line: if line:
if line.startswith('@@') and not first: if line.startswith('@@') and not first:
this.children.append(CodeBlock('\n'.join(tmp))) self.children.append(CodeBlock('\n'.join(tmp)))
tmp = [line,] tmp = [line,]
else: else:
first = False first = False
tmp.append(line) tmp.append(line)
this.children.append(CodeBlock('\n'.join(tmp))) self.children.append(CodeBlock('\n'.join(tmp)))
def _escape(this, data): def _escape(self, data):
""" """
Escape &, <, and > in a string of data. Escape &, <, and > in a string of data.
This is a copy of the xml.sax.saxutils.escape function. This is a copy of the xml.sax.saxutils.escape function.
...@@ -122,7 +122,7 @@ class DiffFile: ...@@ -122,7 +122,7 @@ class DiffFile:
data = data.replace("<", "&lt;") data = data.replace("<", "&lt;")
return data return data
def toHTML(this): def toHTML(self):
# Adding header of the table # Adding header of the table
html = '''<font color='black'><b>%s</b><br> html = '''<font color='black'><b>%s</b><br>
<hr><br> <hr><br>
...@@ -131,9 +131,9 @@ class DiffFile: ...@@ -131,9 +131,9 @@ class DiffFile:
<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: grey"><b><center>%s</center></b></td> <td style="background-color: grey"><b><center>%s</center></b></td>
</tr>'''%(this.path, this.old_revision, this.new_revision) </tr>'''%(self.path, self.old_revision, self.new_revision)
First = True First = True
for child in this.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: grey">&nbsp;</td></tr> <tr>
...@@ -164,7 +164,7 @@ class DiffFile: ...@@ -164,7 +164,7 @@ class DiffFile:
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: %s">%s</td> <td style="background-color: %s">%s</td>
</tr>'''%(old_line_tuple[1], this._escape(old_line).replace(' ', '&nbsp;').replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'), new_line_tuple[1], this._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>
</table></font><br><br>''' </table></font><br><br>'''
return html return html
...@@ -181,70 +181,70 @@ class CodeBlock: ...@@ -181,70 +181,70 @@ class CodeBlock:
# - getNewCodeList() : return code after modif # - getNewCodeList() : return code after modif
# Note: the code returned is a list of tuples (code line, background color) # Note: the code returned is a list of tuples (code line, background color)
def __init__(this, raw_diff): def __init__(self, raw_diff):
# Splitting body and header # Splitting body and header
this.body = '\n'.join(raw_diff.split('\n')[1:]) self.body = '\n'.join(raw_diff.split('\n')[1:])
this.header = raw_diff.split('\n')[0] self.header = raw_diff.split('\n')[0]
# Getting modifications lines # Getting modifications lines
tmp = re.search('^@@ -\d+', this.header) tmp = re.search('^@@ -\d+', self.header)
this.old_line = tmp.string[tmp.start():tmp.end()][4:] self.old_line = tmp.string[tmp.start():tmp.end()][4:]
tmp = re.search('\+\d+,', this.header) tmp = re.search('\+\d+,', self.header)
this.new_line = tmp.string[tmp.start():tmp.end()][1:-1] self.new_line = tmp.string[tmp.start():tmp.end()][1:-1]
# Splitting modifications in SubCodeBlocks # Splitting modifications in SubCodeBlocks
in_modif = False in_modif = False
this.children = [] self.children = []
tmp=[] tmp=[]
for line in this.body.split('\n'): for line in self.body.split('\n'):
if line: if line:
if (line.startswith('+') or line.startswith('-')): if (line.startswith('+') or line.startswith('-')):
if in_modif: if in_modif:
tmp.append(line) tmp.append(line)
else: else:
this.children.append(SubCodeBlock('\n'.join(tmp))) self.children.append(SubCodeBlock('\n'.join(tmp)))
tmp = [line,] tmp = [line,]
in_modif = True in_modif = True
else: else:
if in_modif: if in_modif:
this.children.append(SubCodeBlock('\n'.join(tmp))) self.children.append(SubCodeBlock('\n'.join(tmp)))
tmp = [line,] tmp = [line,]
in_modif = False in_modif = False
else: else:
tmp.append(line) tmp.append(line)
this.children.append(SubCodeBlock('\n'.join(tmp))) self.children.append(SubCodeBlock('\n'.join(tmp)))
# Return code before modification # Return code before modification
def getOldCodeList(this): def getOldCodeList(self):
tmp = [] tmp = []
for child in this.children: for child in self.children:
tmp.extend(child.getOldCodeList()) tmp.extend(child.getOldCodeList())
return tmp return tmp
# Return code after modification # Return code after modification
def getNewCodeList(this): def getNewCodeList(self):
tmp = [] tmp = []
for child in this.children: for child in self.children:
tmp.extend(child.getNewCodeList()) tmp.extend(child.getNewCodeList())
return tmp return tmp
# a SubCodeBlock contain 0 or 1 modification (not more) # a SubCodeBlock contain 0 or 1 modification (not more)
class SubCodeBlock: class SubCodeBlock:
def __init__(this, code): def __init__(self, code):
this.body=code self.body=code
this.modification=this._getModif() self.modification=self._getModif()
# Choosing background color # Choosing background color
if this.modification == 'none': if self.modification == 'none':
this.color = 'white' self.color = 'white'
elif this.modification == 'change': elif self.modification == 'change':
this.color = 'rgb(253, 228, 6);'#light orange self.color = 'rgb(253, 228, 6);'#light orange
elif this.modification == 'deletion': elif self.modification == 'deletion':
this.color = 'rgb(253, 117, 74);'#light red self.color = 'rgb(253, 117, 74);'#light red
else: else:
this.color = 'rgb(83, 253, 74);'#light green self.color = 'rgb(83, 253, 74);'#light green
def _getModif(this): def _getModif(self):
nb_plus = 0 nb_plus = 0
nb_minus = 0 nb_minus = 0
for line in this.body.split('\n'): for line in self.body.split('\n'):
if line.startswith("-"): if line.startswith("-"):
nb_minus-=1 nb_minus-=1
elif line.startswith("+"): elif line.startswith("+"):
...@@ -258,36 +258,36 @@ class SubCodeBlock: ...@@ -258,36 +258,36 @@ class SubCodeBlock:
return 'change' return 'change'
# Return code before modification # Return code before modification
def getOldCodeList(this): def getOldCodeList(self):
if this.modification=='none': if self.modification=='none':
return [(x, 'white') for x in this.body.split('\n')] return [(x, 'white') for x in self.body.split('\n')]
elif this.modification=='change': elif self.modification=='change':
return [this._getOldCodeList(x) for x in this.body.split('\n') if this._getOldCodeList(x)[0]] return [self._getOldCodeList(x) for x in self.body.split('\n') if self._getOldCodeList(x)[0]]
else: # deletion or addition else: # deletion or addition
return [this._getOldCodeList(x) for x in this.body.split('\n')] return [self._getOldCodeList(x) for x in self.body.split('\n')]
def _getOldCodeList(this, line): def _getOldCodeList(self, line):
if line.startswith('+'): if line.startswith('+'):
return (None, this.color) return (None, self.color)
if line.startswith('-'): if line.startswith('-'):
return (' '+line[1:], this.color) return (' '+line[1:], self.color)
return (line, this.color) return (line, self.color)
# Return code after modification # Return code after modification
def getNewCodeList(this): def getNewCodeList(self):
if this.modification=='none': if self.modification=='none':
return [(x, 'white') for x in this.body.split('\n')] return [(x, 'white') for x in self.body.split('\n')]
elif this.modification=='change': elif self.modification=='change':
return [this._getNewCodeList(x) for x in this.body.split('\n') if this._getNewCodeList(x)[0]] return [self._getNewCodeList(x) for x in self.body.split('\n') if self._getNewCodeList(x)[0]]
else: # deletion or addition else: # deletion or addition
return [this._getNewCodeList(x) for x in this.body.split('\n')] return [self._getNewCodeList(x) for x in self.body.split('\n')]
def _getNewCodeList(this, line): def _getNewCodeList(self, line):
if line.startswith('-'): if line.startswith('-'):
return (None, this.color) return (None, self.color)
if line.startswith('+'): if line.startswith('+'):
return (' '+line[1:], this.color) return (' '+line[1:], self.color)
return (line, this.color) return (line, self.color)
class SubversionTool(UniqueObject, Folder): class SubversionTool(UniqueObject, Folder):
"""The SubversionTool provides a Subversion interface to ERP5. """The SubversionTool provides a Subversion interface to ERP5.
......
...@@ -56,5 +56,6 @@ def initialize( context ): ...@@ -56,5 +56,6 @@ def initialize( context ):
from AccessControl.SecurityInfo import allow_module from AccessControl.SecurityInfo import allow_module
allow_module('Products.ERP5Subversin.SubversionClient') allow_module('Products.ERP5Subversion.SubversionClient')
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