# Own modules
-__version__ = '0.2.2'
+__version__ = '0.2.3'
LOG = logging.getLogger(__name__)
DEFAULT_COMMENT_CHAR = '#'
pat = r'^(\s*(?:[^\s"' + r"'" + r']+|\\["' + r"'" + r'])+)(?#token-wo-quote)'
self.re_token_list.append(re.compile(pat, re_flags))
+ self.re_whitespace = re.compile(r'\s+', re_flags)
+
self.re_empty = re.compile(r'^(\s*)$')
if self.comment_chars:
i += 1
- # -------------------------------------------------------------------------
- def is_equal(self, a, b):
-
- equal = True
- for line in self.compare(a, b):
- if line.startswith('+') or line.startswith('-'):
- subline = line[1:]
- if self.is_line_junk(subline):
- LOG.debug("Line {!r} is junk.".format(subline))
- else:
- equal = False
-
- return equal
-
# -------------------------------------------------------------------------
def remove_comments(self, line):
out += ", ".join(fields) + ")>"
return out
+ # -------------------------------------------------------------------------
+ def _mangle_lines(self, lines):
+
+ if isinstance(lines, (list, set, tuple)):
+ line_list = copy.copy(lines)
+ else:
+ line_list = [str(lines)]
+
+ if ( not self.ignore_empty and not self.ignore_whitespace and
+ not self.ignore_comment and not self.case_insensitive):
+ return line_list
+
+ reult_list = []
+ for item in line_list:
+ if self.ignore_empty and self.re_empty.search(item):
+ continue
+ item_cp = str(item)
+ if self.ignore_whitespace:
+ item_cp = self.re_whitespace.sub(' ', item_cp)
+ if self.ignore_comment:
+ item_cp = = self.remove_comments(item_cp)
+ if self.case_insensitive:
+ item_cp = item_cp.lower()
+ reult_list.append(item_cp)
+
+ return reult_list
+
+ # -------------------------------------------------------------------------
+ def compare(self, a, b):
+
+ list_a = self._mangle_lines(a)
+ list_b = self._mangle_lines(b)
+
+ return super(ConfigDiffer, self).compare(list_a, list_b)
+
+ # -------------------------------------------------------------------------
+ def unified_diff(self, a, b, n=3, lineterm='\n'):
+
+ list_a = self._mangle_lines(a)
+ list_b = self._mangle_lines(b)
+
+ return difflib.unified_diff(list_a, list_b, n=n, lineterm=lineterm)
+
+ # -------------------------------------------------------------------------
+ def is_equal(self, a, b):
+
+ equal = True
+ for line in self.compare(a, b):
+ if not line.startswith(' '):
+ LOG.debug("Difference line: {}".format(line))
+ equal = False
+
+ return equal
# =============================================================================