Commit 2e2f1943 authored by Christophe Dumez's avatar Christophe Dumez

- code cleanup a little


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6476 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 630ed0b1
...@@ -234,8 +234,6 @@ class SubCodeBlock: ...@@ -234,8 +234,6 @@ class SubCodeBlock:
def __init__(self, code): def __init__(self, code):
self.body = code self.body = code
self.modification = self._getModif() self.modification = self._getModif()
self.old_code_length = self._getOldCodeLength()
self.new_code_length = self._getNewCodeLength()
# Choosing background color # Choosing background color
if self.modification == 'none': if self.modification == 'none':
self.color = 'white' self.color = 'white'
...@@ -262,30 +260,10 @@ class SubCodeBlock: ...@@ -262,30 +260,10 @@ class SubCodeBlock:
return 'none' return 'none'
return 'change' return 'change'
def _getOldCodeLength(self):
nb_lines = 0
for line in self.body.split('\n'):
if not line.startswith("+"):
nb_lines+=1
return nb_lines
def _getNewCodeLength(self):
nb_lines = 0
for line in self.body.split('\n'):
if not line.startswith("-"):
nb_lines+=1
return nb_lines
# Return code before modification # Return code before modification
def getOldCodeList(self): def getOldCodeList(self):
if self.modification=='none': if self.modification=='none':
old_code = [(x, 'white') for x in self.body.split('\n')] old_code = [(x, 'white') for x in self.body.split('\n')]
elif self.modification=='change':
old_code = [self._getOldCodeList(x) for x in self.body.split('\n') if self._getOldCodeList(x)[0]]
# we want old_code_list and new_code_list to have the same length
if(self.old_code_length < self.new_code_length):
filling = [(None, self.color)]*(self.new_code_length-self.old_code_length)
old_code.extend(filling)
else: # deletion or addition else: # deletion or addition
old_code = [self._getOldCodeList(x) for x in self.body.split('\n')] old_code = [self._getOldCodeList(x) for x in self.body.split('\n')]
return old_code return old_code
...@@ -301,12 +279,6 @@ class SubCodeBlock: ...@@ -301,12 +279,6 @@ class SubCodeBlock:
def getNewCodeList(self): def getNewCodeList(self):
if self.modification=='none': if self.modification=='none':
new_code = [(x, 'white') for x in self.body.split('\n')] new_code = [(x, 'white') for x in self.body.split('\n')]
elif self.modification=='change':
new_code = [self._getNewCodeList(x) for x in self.body.split('\n') if self._getNewCodeList(x)[0]]
# we want old_code_list and new_code_list to have the same length
if(self.new_code_length < self.old_code_length):
filling = [(None, self.color)]*(self.old_code_length-self.new_code_length)
new_code.extend(filling)
else: # deletion or addition else: # deletion or addition
new_code = [self._getNewCodeList(x) for x in self.body.split('\n')] new_code = [self._getNewCodeList(x) for x in self.body.split('\n')]
return new_code return new_code
......
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