@log_calls
def changelist_for_fingerprints(old_fingerprints, new_fingerprints, fill_md5s=True, lazy_md5s=False, root_path=None, expect_exact=True, mod_all=False):
  '''
  Compute Changelist on working directory side: Given two FingerprintLists,
  return a Changelist with the adds, removes, and modifies needed to get to the
  second. Fingerprints may or may not have hashes. If fill_md5 is set, fill in
  hashes in both directions into FingerprintLists. If lazy_md5 is set, compute
  MD5 as needed to resolve uncertainties. If expect_exact is set, raise exception
  if any needed hashes are missing. If mod_all is set, skip all fingerprint
  checks and mark all files as modified.
  '''
  changelist = Changelist()

  if lazy_md5s and not root_path:
    raise InvalidOperation("root_path required to compute MD5s")

  if fill_md5s:
    old_fingerprints.fill_md5s(new_fingerprints)
    new_fingerprints.fill_md5s(old_fingerprints)
  
  # These are dictionaries of full path -> fingerprint
  old_dict = old_fingerprints.fingerprints
  new_dict = new_fingerprints.fingerprints

  # Added files
  for new_path in new_dict.keys():
    if new_path not in old_dict:
      changelist.update(new_path, Changelist.Status.ADDED)
  # Modified and removed files
  for old_path in old_dict.keys():
    if old_path not in new_dict:
      changelist.update(old_path, Changelist.Status.REMOVED)
    else:
      if mod_all:
        changelist.update(old_path, Changelist.Status.MODIFIED)
      else:
        old_fp = old_dict[old_path]
        new_fp = new_dict[old_path]
        c = old_fp.compare(new_fp)
        log.debug("fingerprint compare: %s: %s: %s %s", old_path, c, old_fp, new_fp)
        if c == Fingerprint.UNCERTAIN and lazy_md5s:
          if not old_fp.md5:
            old_fp.read_from_file(join_path(root_path, old_path), compute_md5=True)
          if not new_fp.md5:
            new_fp.read_from_file(join_path(root_path, old_path), compute_md5=True)
          c = old_fp.compare(new_fp)
          log.debug("lazy compare: %s: %s", old_path, c)
        if c == Fingerprint.DIFFER:
          changelist.update(old_path, Changelist.Status.MODIFIED)
        elif c == Fingerprint.UNCERTAIN:
          if lazy_md5s or expect_exact:
            raise AssertionError("should have computed MD5s in all Fingerprints already (old=%s, new=%s, lazy=%s, exact=%s)" % (old_fp, new_fp, lazy_md5s, expect_exact))
          else:
            log.debug("assuming uncertain file is modified: %s", old_path)
            changelist.update(old_path, Changelist.Status.MODIFIED)

  return changelist
dataset/ETHPy150Open bloomreach/zinc/zinc.py/changelist_for_fingerprints/original