                               frame_name, str(idx))
          return del_count
  
  
  class Legacy():
      """ Update legacy alignments:
  
          - Add frame dimensions
          - Rotate landmarks and bounding boxes on legacy alignments
            and remove the 'r' parameter
          - Add face hashes to alignments file
      """
  
      def __init__(self, alignments, arguments, frames=None, faces=None, child_process=False):
          logger.debug("Initializing %s: (arguments: %s, child_process: %s)",
                       self.__class__.__name__, arguments, child_process)
          self.alignments = alignments
          if child_process:
              self.frames = frames
              self.faces = faces
          else:
              self.frames = Frames(arguments.frames_dir)
              self.faces = Faces(arguments.faces_dir)
          logger.debug("Initialized %s", self.__class__.__name__)
  
      def process(self):
          """ Run the rotate alignments process """
          no_dims = self.alignments.get_legacy_no_dims()
          rotated = self.alignments.get_legacy_rotation()
          hashes = self.alignments.get_legacy_no_hashes()
          if (not self.frames or (not no_dims and not rotated)) and (not self.faces or not hashes):
              return
          logger.info("[UPDATE LEGACY LANDMARKS]")  # Tidy up cli output
          if no_dims and self.frames:
              logger.info("Legacy landmarks found. Adding frame dimensions...")
              self.add_dimensions(no_dims)
              self.alignments.save()
          if rotated and self.frames:
              logger.info("Legacy rotated frames found. Converting...")
              self.rotate_landmarks(rotated)
              self.alignments.save()
          if hashes and self.faces:
              logger.info("Legacy alignments found. Adding Face Hashes...")
              self.add_hashes(hashes)
              self.alignments.save()
  
      def add_dimensions(self, no_dims):
          """ Add width and height of original frame to alignments """
          for no_dim in tqdm(no_dims, desc="Adding Frame Dimensions"):
              if no_dim not in self.frames.items.keys():
                  continue
              dims = self.frames.load_image(no_dim).shape[:2]
              self.alignments.add_dimensions(no_dim, dims)
  
      def rotate_landmarks(self, rotated):
          """ Rotate the landmarks """
          for rotate_item in tqdm(rotated, desc="Rotating Landmarks"):
              if rotate_item not in self.frames.items.keys():
                  continue
              self.alignments.rotate_existing_landmarks(rotate_item)
  
      def add_hashes(self, hashes):
          """ Add Face Hashes to the alignments file """
          all_faces = dict()
          logger.info("Getting original filenames, indexes and hashes...")
          for face in self.faces.file_list_sorted:
              filename = face["face_name"]
              extension = face["face_extension"]
              if "_" not in face["face_name"]:
                  logger.warning("Unable to determine index of file. Skipping: '%s'", filename)
                  continue
              index = filename[filename.rfind("_") + 1:]
              if not index.isdigit():
                  logger.warning("Unable to determine index of file. Skipping: '%s'", filename)
                  continue
              orig_frame = filename[:filename.rfind("_")] + extension
              all_faces.setdefault(orig_frame, dict())[int(index)] = face["face_hash"]
  
          logger.info("Updating hashes to alignments...")
          for frame in hashes:
              if frame not in all_faces.keys():
                  logger.warning("Skipping missing frame: '%s'", frame)
                  continue
              self.alignments.add_face_hashes(frame, all_faces[frame])
  
  
  class Rename():
      """ Rename faces to match their source frame and position index """
      def __init__(self, alignments, arguments, faces=None):
          logger.debug("Initializing %s: (arguments: %s, faces: %s)",
                       self.__class__.__name__, arguments, faces)
 
</s> remove             frame name and their index in the frame """
        return{face["hash"]: (frame_name, idx)
               for frame_name, faces in self.data.items()
               for idx, face in enumerate(faces)}
 </s> add             frame name(s) and their index in the frame
            """
        hash_faces = dict()
        for frame_name, faces in self.data.items():
            for idx, face in enumerate(faces):
                hash_faces.setdefault(face["hash"], dict())[frame_name] = idx
        return hash_faces </s> remove 
            if self.alignments.frame_has_multiple_faces(frame):
                if self.type == "faces":
                    # Add correct alignments index for moving faces
                    retval = (retval, idx)
                logger.trace("Returning: '%s'", retval)
                yield retval
 </s> add             for frame, idx in frame_idx:
                if self.alignments.frame_has_multiple_faces(frame):
                    if self.type == "faces":
                        # Add correct alignments index for moving faces
                        retval = (retval, idx)
                    logger.trace("Returning: '%s'", retval)
                    yield retval </s> remove                 frame, idx = self.alignments.hashes_to_frame[frame]
 </s> add                 frame_idx = [(frame, idx)
                             for frame, idx in self.alignments.hashes_to_frame[frame].items()] </s> remove             rename_count += 1
            logger.verbose("Renamed '%s' to '%s'", old, new)
 </s> add                 if action == "final":
                    rename_count += 1
                    logger.verbose("Renamed '%s' to '%s'", old, new)
                               frame_name, str(idx))
          return del_count
  
  


















































































  class Rename():
      """ Rename faces to match their source frame and position index """
      def __init__(self, alignments, arguments, faces=None):
          logger.debug("Initializing %s: (arguments: %s, faces: %s)",
                       self.__class__.__name__, arguments, faces)
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Alignments tool: Filename clash bugfix 
tools/lib_alignments/jobs.py