From 94ec74172a43dac550726073c3687e57185457cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com>
Date: Tue, 17 Aug 2010 09:13:35 +0000
Subject: [PATCH] add a method which returns the list of modified block make
 some variables global

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37859 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/DiffUtils.py | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/product/ERP5Type/DiffUtils.py b/product/ERP5Type/DiffUtils.py
index 90a2bbda7d..64ed5d19f5 100644
--- a/product/ERP5Type/DiffUtils.py
+++ b/product/ERP5Type/DiffUtils.py
@@ -42,6 +42,10 @@ from xml.sax.saxutils import escape
 
 NBSP = '&nbsp;'
 NBSP_TAB = NBSP*8
+NO_DIFF_COLOR = 'white'
+MODIFIED_DIFF_COLOR = 'rgb(253, 228, 6);'#light orange
+DELETED_DIFF_COLOR = 'rgb(253, 117, 74);'#light red
+ADDITION_DIFF_COLOR = 'rgb(83, 253, 74);'#light green
 
 class DiffFile:
   """
@@ -142,13 +146,30 @@ class DiffFile:
     html_list.append('''</tbody></table><br/>''')
     return '\n'.join(html_list)
 
+  def getModifiedBlockList(self):
+    """
+    Return a list of modified blocks
+    List contains tuples (old_modified_code, new_modified_code)
+    """
+    if self.binary:
+      return []
+    block_list = []
+    for child in self.children:
+      old_line_list = [x[0].strip() for x in child.getOldCodeList()
+                       if x[0] is not None and x[1] == MODIFIED_DIFF_COLOR]
+      new_line_list = [x[0].strip() for x in child.getNewCodeList()
+                       if x[0] is not None and x[1] == MODIFIED_DIFF_COLOR]
+      block_list.append((old_line_list, new_line_list))
+    return block_list
+
+
 class CodeBlock:
   """
    A code block contains several SubCodeBlocks
    Members :
    - old_line : line in old code (before modif)
    - new line : line in new code (after modif)
-  
+
    Methods :
    - getOldCodeList() : return code before modif
    - getNewCodeList() : return code after modif
@@ -212,13 +233,13 @@ class SubCodeBlock:
     self.new_code_length = self._getNewCodeLength()
     # Choosing background color
     if self.modification == 'none':
-      self.color = 'white'
+      self.color = NO_DIFF_COLOR
     elif self.modification == 'change':
-      self.color = 'rgb(253, 228, 6);'#light orange
+      self.color = MODIFIED_DIFF_COLOR
     elif self.modification == 'deletion':
-      self.color = 'rgb(253, 117, 74);'#light red
+      self.color = DELETED_DIFF_COLOR
     else: # addition
-      self.color = 'rgb(83, 253, 74);'#light green
+      self.color = ADDITION_DIFF_COLOR
     
   def _getModif(self):
     """ Return type of modification :
-- 
2.30.9