Example #1
0
 def compare(self, templater, tmpfolder, profile, src, dst, opts=''):
     '''Compare temporary generated dotfile with local one'''
     self.comparing = True
     retval = False, ''
     drysaved = self.dry
     self.dry = False
     diffsaved = self.diff
     self.diff = False
     src = os.path.expanduser(src)
     dst = os.path.expanduser(dst)
     if not os.path.exists(dst):
         retval = False, '\"%s\" does not exist on local\n' % (dst)
     else:
         ret, tmpdst = self._install_to_temp(templater,
                                             profile,
                                             src, dst,
                                             tmpfolder)
         if ret:
             diff = utils.diff(tmpdst, dst, log=False,
                               raw=False, opts=opts)
             if diff == '':
                 retval = True, ''
             else:
                 retval = False, diff
     self.dry = drysaved
     self.diff = diffsaved
     self.comparing = False
     return retval
Example #2
0
 def compare(self, templater, tmpfolder, profile, src, dst, opts=''):
     '''Compare temporary generated dotfile with local one'''
     self.comparing = True
     retval = False, ''
     drysaved = self.dry
     self.dry = False
     diffsaved = self.diff
     self.diff = False
     createsaved = self.create
     self.create = True
     src = os.path.expanduser(src)
     dst = os.path.expanduser(dst)
     if not os.path.exists(dst):
         retval = False, '\"%s\" does not exist on local\n' % (dst)
     else:
         ret, tmpdst = self._install_to_temp(templater, profile, src, dst,
                                             tmpfolder)
         if ret:
             diff = utils.diff(tmpdst, dst, log=False, raw=False, opts=opts)
             if diff == '':
                 retval = True, ''
             else:
                 retval = False, diff
     self.dry = drysaved
     self.diff = diffsaved
     self.comparing = False
     self.create = createsaved
     return retval
Example #3
0
 def compare(self, templater, tmpdir, profile, src, dst, opts=''):
     """compare a temporary generated dotfile with the local one"""
     self.comparing = True
     retval = False, ''
     drysaved = self.dry
     self.dry = False
     diffsaved = self.diff
     self.diff = False
     createsaved = self.create
     self.create = True
     src = os.path.expanduser(src)
     dst = os.path.expanduser(dst)
     self.log.dbg('comparing {} and {}'.format(src, dst))
     if not os.path.exists(dst):
         retval = False, '\"{}\" does not exist on local\n'.format(dst)
     else:
         ret, tmpdst = self._install_to_temp(templater, profile, src, dst,
                                             tmpdir)
         if ret:
             self.log.dbg('diffing {} and {}'.format(tmpdst, dst))
             diff = utils.diff(tmpdst, dst, raw=False, opts=opts)
             if diff == '':
                 retval = True, ''
             else:
                 retval = False, diff
     self.dry = drysaved
     self.diff = diffsaved
     self.comparing = False
     self.create = createsaved
     return retval
Example #4
0
 def compare(self, templater, tmpdir, profile, src, dst, opts=''):
     """compare a temporary generated dotfile with the local one"""
     # saved some flags while comparing
     self.comparing = True
     retval = False, ''
     drysaved = self.dry
     self.dry = False
     diffsaved = self.diff
     self.diff = False
     createsaved = self.create
     self.create = True
     # normalize src and dst
     src = os.path.expanduser(src)
     dst = os.path.expanduser(dst)
     self.log.dbg('comparing {} and {}'.format(src, dst))
     if not os.path.lexists(dst):
         # destination dotfile does not exist
         retval = False, '\"{}\" does not exist on local\n'.format(dst)
     else:
         # install the dotfile to a temp directory for comparing
         ret, tmpdst = self._install_to_temp(templater, profile, src, dst,
                                             tmpdir)
         if ret:
             self.log.dbg('diffing {} and {}'.format(tmpdst, dst))
             diff = utils.diff(tmpdst, dst, raw=False, opts=opts)
             if diff == '':
                 retval = True, ''
             else:
                 retval = False, diff
     # reset flags
     self.dry = drysaved
     self.diff = diffsaved
     self.comparing = False
     self.create = createsaved
     return retval
Example #5
0
 def _diff(self, left, right, header=False):
     """diff two files"""
     out = diff(modified=left, original=right, raw=False,
                diff_cmd=self.diff_cmd, debug=self.debug)
     if header:
         lshort = os.path.basename(left)
         out = '=> diff \"{}\":\n{}'.format(lshort, out)
     return out
Example #6
0
 def _diff(self, local_path, deployed_path, header=False):
     """diff two files"""
     out = diff(modified=local_path,
                original=deployed_path,
                diff_cmd=self.diff_cmd,
                debug=self.debug)
     if header:
         lshort = os.path.basename(local_path)
         out = '=> diff \"{}\":\n{}'.format(lshort, out)
     return out
Example #7
0
 def _diff(self, left, right, header=False):
     """diff using the unix tool diff"""
     diff = utils.diff(left,
                       right,
                       raw=False,
                       opts=self.diffopts,
                       debug=self.debug)
     if header:
         lshort = os.path.basename(left)
         diff = '=> diff \"{}\":\n{}'.format(lshort, diff)
     return diff
Example #8
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)
Example #9
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