diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-08-16 09:29:58 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-08-16 09:29:58 -0400 |
commit | 4efd4785d9e919ed3abf57377487475dc89de5c5 (patch) | |
tree | 98c5bb7e7c3fdd4a36b6283b7d107b9bfd0c6457 /src/lib | |
parent | 87bb829a4a415922a9a738c11fa9e0a87fda6a95 (diff) | |
download | bcfg2-4efd4785d9e919ed3abf57377487475dc89de5c5.tar.gz bcfg2-4efd4785d9e919ed3abf57377487475dc89de5c5.tar.bz2 bcfg2-4efd4785d9e919ed3abf57377487475dc89de5c5.zip |
POSIX: added tests, fixes for File._get_diffs
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/File.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/File.py b/src/lib/Bcfg2/Client/Tools/POSIX/File.py index 73ed2d8bf..6013d864e 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/File.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/File.py @@ -141,14 +141,14 @@ class POSIXFile(POSIXTool): return POSIXTool.install(self, entry) and rv - def _get_diffs(entry, interactive=False, sensitive=False, is_binary=False, - content=None): + def _get_diffs(self, entry, interactive=False, sensitive=False, + is_binary=False, content=None): if not interactive and sensitive: return prompt = [entry.get('qtext', '')] attrs = dict() - if not is_binary and content is None: + if content is None: # it's possible that we figured out the files are # different without reading in the local file. if the # supplied version of the file is not binary, we now have @@ -161,14 +161,15 @@ class POSIXFile(POSIXTool): self.logger.error("POSIX: Failed to read %s: %s" % (entry.get("name"), sys.exc_info()[1])) return False - is_binary &= self._is_string(content, self.setup['encoding']) + if not is_binary: + is_binary |= not self._is_string(content, self.setup['encoding']) if is_binary: # don't compute diffs if the file is binary prompt.append('Binary file, no printable diff') attrs['current_bfile'] = binascii.b2a_base64(content) else: if interactive: - diff = self._diff(content, tempdata, + diff = self._diff(content, entry.text, difflib.unified_diff, filename=entry.get("name")) if diff: @@ -181,17 +182,17 @@ class POSIXFile(POSIXTool): prompt.append("Diff took too long to compute, no " "printable diff") if not sensitive: - diff = self._diff(content, tempdata, difflib.ndiff, + diff = self._diff(content, entry.text, difflib.ndiff, filename=entry.get("name")) if diff: - ndiff = binascii.b2a_base64("\n".join(diff)) - attrs["current_bdiff"] = ndiff + attrs["current_bdiff"] = \ + binascii.b2a_base64("\n".join(diff)) else: attrs['current_bfile'] = binascii.b2a_base64(content) if interactive: entry.set("qtext", "\n".join(prompt)) if not sensitive: - for attr, val in attrs: + for attr, val in attrs.items(): entry.set(attr, val) def _diff(self, content1, content2, difffunc, filename=None): |