[Erp5-report] r6398 - in /erp5/trunk/products/ERP5Subversion: ./ Tool/

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Mar 31 10:17:40 CEST 2006


Author: chris
Date: Fri Mar 31 10:17:39 2006
New Revision: 6398

URL: http://svn.erp5.org?rev=6398&view=rev
Log:
- fixed typo in allow_module
- added yoshinori's work on exception handling

Modified:
    erp5/trunk/products/ERP5Subversion/SubversionClient.py
    erp5/trunk/products/ERP5Subversion/Tool/SubversionTool.py
    erp5/trunk/products/ERP5Subversion/__init__.py

Modified: erp5/trunk/products/ERP5Subversion/SubversionClient.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Subversion/SubversionClient.py?rev=6398&r1=6397&r2=6398&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Subversion/SubversionClient.py (original)
+++ erp5/trunk/products/ERP5Subversion/SubversionClient.py Fri Mar 31 10:17:39 2006
@@ -38,6 +38,7 @@
 
 try:
   import pysvn
+  
 
   class SubversionError(Exception):
     """The base exception class for the Subversion interface.
@@ -114,8 +115,9 @@
     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 @@
     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 @@
 #     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 @@
       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

Modified: erp5/trunk/products/ERP5Subversion/Tool/SubversionTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Subversion/Tool/SubversionTool.py?rev=6398&r1=6397&r2=6398&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Subversion/Tool/SubversionTool.py (original)
+++ erp5/trunk/products/ERP5Subversion/Tool/SubversionTool.py Fri Mar 31 10:17:39 2006
@@ -81,36 +81,36 @@
   # - 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)))
-    
-
-  def _escape(this, data):
+    self.children.append(CodeBlock('\n'.join(tmp)))
+    
+
+  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 @@
       data = data.replace("<", "&lt;")
       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 @@
     <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">&nbsp;</td><td style="background-color: grey">&nbsp;</td></tr>    <tr>
@@ -164,7 +164,7 @@
         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(' ', '&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>
 </table></font><br><br>'''
     return html
@@ -181,70 +181,70 @@
   # - 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
-    
-  def _getModif(this):
+      self.color = 'rgb(83, 253, 74);'#light green
+    
+  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 @@
     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')]
-  
-  def _getOldCodeList(this, line):
+      return [self._getOldCodeList(x) for x in self.body.split('\n')]
+  
+  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')]
-  
-  def _getNewCodeList(this, line):
+      return [self._getNewCodeList(x) for x in self.body.split('\n')]
+  
+  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.

Modified: erp5/trunk/products/ERP5Subversion/__init__.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Subversion/__init__.py?rev=6398&r1=6397&r2=6398&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Subversion/__init__.py (original)
+++ erp5/trunk/products/ERP5Subversion/__init__.py Fri Mar 31 10:17:39 2006
@@ -56,5 +56,6 @@
 
 from AccessControl.SecurityInfo import allow_module
 
-allow_module('Products.ERP5Subversin.SubversionClient')
+allow_module('Products.ERP5Subversion.SubversionClient')
 
+




More information about the Erp5-report mailing list