Returns a dictionary of the form:

            { SRC_PATH: DiffViolations(SRC_PATH) }

        where `SRC_PATH` is the path to the source file.

        To make this efficient, we cache and reuse the result.
341252
def _diff_violations(self):
        
        if not self._diff_violations_dict:
            self._diff_violations_dict = {
                    src_path: DiffViolations(
                        self._violations.violations(src_path),
                        self._violations.measured_lines(src_path),
                        self._diff.lines_changed(src_path),
                    )
                 for src_path in self._diff.src_paths_changed()
            }
        return self._diff_violations_dict
1253991
def CopyToDict(self):
    
    path_spec_dict = {}
    for attribute_name, attribute_value in iter(self.__dict__.items()):
      if attribute_value is None:
        continue

      if attribute_name == 'parent':
        attribute_value = attribute_value.CopyToDict()

      path_spec_dict[attribute_name] = attribute_value

    return path_spec_dict
885376
def _get_diff(self):
        """"""
        diff = []
        self._create_sot_file()
        command = ('show diff rollback-patch file {0} file {1}'.format(
                   'sot_file', self.replace_file.split('/')[-1]))
        diff_out = self.device.send_command(command)
        try:
            diff_out = diff_out.split(
                '#Generating Rollback Patch')[1].replace(
                    'Rollback Patch is Empty', '').strip()
            for line in diff_out.splitlines():
                if line:
                    if line[0].strip() != '!' and line[0].strip() != '.':
                        diff.append(line.rstrip(' '))
        except (AttributeError, KeyError):
            raise ReplaceConfigException(
                'Could not calculate diff. It\'s possible the given file doesn\'t exist.')
        return '\n'.join(diff)
1009286
def get_project_source_path(path: str) -> str:
    

    path = environ.paths.clean(path)

    if not path.endswith('cauldron.json'):
        return os.path.join(path, 'cauldron.json')

    return path
541459
def diff(path_from, path_to, ignore_empty = False):
  
  fh_from = open(path_from, 'rb')
  fh_to = open(path_to, 'rb')
  diffs = file_diff(fh_from, fh_to, ignore_empty)
  fh_to.close()
  fh_from.close()
  return diffs
948792
def malloc_diff(func):
    
    def _f(*args, **kwargs):
        print("\n<<<---")
        tracemalloc.start()
        snapshot1 = tracemalloc.take_snapshot()
        res = func(*args, **kwargs)
        snapshot2 = tracemalloc.take_snapshot()
        top_stats = snapshot2.compare_to(snapshot1, 'lineno')
        print("[ Top 10 differences]")
        for stat in top_stats[:10]:
            print(stat)
        print("--->>>\n")
        return res
    return _f
842465
def normalize_path():
    
    # Normalize Python paths
    whole_path = [
        os.path.abspath(path) for path in sys.path if os.path.exists(path)
    ]

    # Keep the "dynamic" current folder indicator and add the "static"
    # current path
    # Use an OrderedDict to have a faster lookup (path not in whole_set)
    whole_set = collections.OrderedDict((("", 1), (os.getcwd(), 1)))

    # Add original path entries
    for path in whole_path:
        if path not in whole_set:
            whole_set[path] = 1

    # Set the new content of sys.path (still ordered thanks to OrderedDict)
    sys.path = list(whole_set)

    # Normalize paths in loaded modules
    for module_ in sys.modules.values():
        try:
            module_.__path__ = [
                os.path.abspath(path)
                for path in module_.__path__
                if _package_exists(path)
            ]
        except AttributeError:
            # builtin modules don't have a __path__
            pass
        except ImportError:
            pass
1184211
def dest_fpath(self, source_fpath: str) -> str:
        """"""
        relative_fpath = os.path.join(*source_fpath.split(os.sep)[1:])
        relative_dirpath = os.path.dirname(relative_fpath)

        source_fname = relative_fpath.split(os.sep)[-1]
        base_fname = source_fname.split('.')[0]
        dest_fname = f'{base_fname}.json'

        return os.path.join(self.dest_dir, relative_dirpath, dest_fname)
305276
def violation_lines(self, src_path):
        

        diff_violations = self._diff_violations().get(src_path)

        if diff_violations is None:
            return []

        return sorted(diff_violations.lines)
1195059
def _file_timestamp_info(self, path):
        
        files = [os.path.join(path, fname) for fname in os.listdir(path) if '.py' in fname]
        return dict ([(fname, os.path.getmtime(fname)) for fname in files])
1258049
def _get_config_dict_from_file(config_path=None):
    
    if config_path is None:
        config_path = DEFAULT_CONFIG_PATH

    # Default (empty) content will be used if config file does not exist.
    config_content = {}

    # If the config file exists we use that content.
    if os.path.isfile(config_path):
        with open(config_path) as fh:
            config_content = json.load(fh)

    return config_content
231717
def raw_diff(self):
        
        udiff_copy = self.copy_iterator()
        if self.__format == 'gitdiff':
            udiff_copy = self._parse_gitdiff(udiff_copy)
        return u''.join(udiff_copy)
1370407
def _get_values(cls, diff_dict, type='new'):
        '''
        
        '''
        ret_dict = {}
        for p in diff_dict.keys():
            if type in diff_dict[p].keys():
                ret_dict.update({p: diff_dict[p][type]})
            else:
                ret_dict.update(
                    {p: cls._get_values(diff_dict[p], type=type)})
        return ret_dict
1202313
def diff(actual, expected):
    
    return '\n'.join(list(
        difflib.unified_diff(actual.splitlines(), expected.splitlines())
    ))
1080952
def GetFileEntryByPath(self, path):
    
    if path is None:
      return None

    file_entry_type, _ = self._paths.get(path, (None, None))
    if not file_entry_type:
      return None

    path_spec = fake_path_spec.FakePathSpec(location=path)
    return fake_file_entry.FakeFileEntry(
        self._resolver_context, self, path_spec,
        file_entry_type=file_entry_type)
870486
def get_filenames_diff(self, r):
        """"""
        cmd = self.filenames_diff_cmd(r)

        diff_files = shell_out_ignore_exitcode(cmd, cwd=self.root)
        diff_files = self.parse_diff_filenames(diff_files)

        return set(f for f in diff_files if f.endswith('.py'))
820721
def get_file_encoding(self, file_path, preferred_encoding=None):
        
        _logger().debug('getting encoding for %s', file_path)
        try:
            map = json.loads(self._settings.value('cachedFileEncodings'))
        except TypeError:
            map = {}
        try:
            return map[file_path]
        except KeyError:
            encodings = self.preferred_encodings
            if preferred_encoding:
                encodings.insert(0, preferred_encoding)
            for encoding in encodings:
                _logger().debug('trying encoding: %s', encoding)
                try:
                    with open(file_path, encoding=encoding) as f:
                        f.read()
                except (UnicodeDecodeError, IOError, OSError):
                    pass
                else:
                    return encoding
            raise KeyError(file_path)