mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 17:24:46 +00:00
correctly handle showdiff with templates
This commit is contained in:
@@ -183,10 +183,7 @@ class Installer:
|
||||
if self.debug:
|
||||
self.log.dbg('change detected for {}'.format(dst))
|
||||
if self.showdiff:
|
||||
comp = Comparator(debug=self.debug)
|
||||
diff = comp.compare(src, dst)
|
||||
self.log.log('diff \"{}\" VS \"{}\"'.format(src, dst))
|
||||
self.log.emph(diff)
|
||||
self._diff_before_write(src, dst, content)
|
||||
if not self.log.ask('Overwrite \"{}\"'.format(dst)):
|
||||
self.log.warn('ignoring {}'.format(dst))
|
||||
return 1
|
||||
@@ -208,6 +205,20 @@ class Installer:
|
||||
os.chmod(dst, rights)
|
||||
return 0
|
||||
|
||||
def _diff_before_write(self, src, dst, src_content):
|
||||
"""diff before writing when using --showdiff - not efficient"""
|
||||
# create tmp to diff for templates
|
||||
tmpfile = utils.get_tmpfile()
|
||||
with open(tmpfile, 'wb') as f:
|
||||
f.write(src_content)
|
||||
comp = Comparator(debug=self.debug)
|
||||
diff = comp.compare(tmpfile, dst)
|
||||
# fake the output for readability
|
||||
self.log.log('diff \"{}\" VS \"{}\"'.format(src, dst))
|
||||
self.log.emph(diff)
|
||||
if tmpfile:
|
||||
utils.remove(tmpfile)
|
||||
|
||||
def _create_dirs(self, directory):
|
||||
"""mkdir -p <directory>"""
|
||||
if not self.create and not os.path.exists(directory):
|
||||
|
||||
@@ -84,7 +84,8 @@ class Templategen:
|
||||
if not src.startswith(self.base):
|
||||
src = os.path.join(self.base, src)
|
||||
with open(src, 'rb') as f:
|
||||
return f.read()
|
||||
content = f.read()
|
||||
return content
|
||||
|
||||
def _read_bad_encoded_text(self, path):
|
||||
"""decode non utf-8 data"""
|
||||
|
||||
Reference in New Issue
Block a user