Ejemplo n.º 1
0
 def _show_patch(self, fpath, tpath):
     """provide a way to manually patch the template"""
     content = self._resolve_template(tpath)
     tmp = write_to_tmpfile(content)
     mirror_file_rights(tpath, tmp)
     cmds = ['diff', '-u', tmp, fpath, '|', 'patch', tpath]
     self.log.warn('try patching with: \"{}\"'.format(' '.join(cmds)))
     return False
Ejemplo n.º 2
0
    def _diff_before_write(self, src, dst, content=None):
        """diff before writing when using --showdiff - not efficient"""
        tmp = None
        if content:
            tmp = utils.write_to_tmpfile(content)
            src = tmp
        diff = utils.diff(src, dst, raw=False)
        utils.remove(tmp, quiet=True)

        # fake the output for readability
        if not diff:
            return
        self.log.log('diff \"{}\" VS \"{}\"'.format(src, dst))
        self.log.emph(diff)
Ejemplo n.º 3
0
 def _is_different(self, src, dst, content=None):
     """
     returns True if file is different and
     needs to be installed
     """
     # check file content
     if content:
         tmp = utils.write_to_tmpfile(content)
         src = tmp
     r = utils.fastdiff(src, dst)
     if r:
         if self.debug:
             self.log.dbg('content differ')
     return r
Ejemplo n.º 4
0
 def _is_different(self, src, dst, content=None):
     """
     returns True if file is different and
     needs to be installed
     """
     # check file content
     tmp = None
     if content:
         tmp = utils.write_to_tmpfile(content)
         src = tmp
     ret = utils.fastdiff(src, dst)
     if ret:
         self.log.dbg('content differ')
     if content:
         utils.removepath(tmp)
     return ret
Ejemplo n.º 5
0
    def _show_diff_before_write(self, src, dst, content=None):
        """
        diff before writing
        using a temp file if content is not None
        returns diff string ('' if same)
        """
        tmp = None
        if content:
            tmp = utils.write_to_tmpfile(content)
            src = tmp
        diff = utils.diff(modified=src, original=dst, diff_cmd=self.diff_cmd)
        if tmp:
            utils.removepath(tmp, logger=self.log)

        if diff:
            self._print_diff(src, dst, diff)
        return diff