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