docs: def location_purge(location_id, delete=False, verbosity=0):
      """Print and conditionally delete files not referenced by meta data.
  
      :param location_id: Id of the
          :class:`~resolwe.flow.models.DataLocation` model that data
          objects reference to.
      :param delete: If ``True``, then delete unreferenced files.
      """
      try:
          location = DataLocation.objects.get(id=location_id)
      except DataLocation.DoesNotExist:
          logger.warning("Data location does not exist", extra={'location_id': location_id})
          return
  
      unreferenced_files = set()
      purged_data = Data.objects.none()
      referenced_by_data = location.data.exists()
      if referenced_by_data:
          if location.data.exclude(status__in=[Data.STATUS_DONE, Data.STATUS_ERROR]).exists():
              return
  
          # Perform cleanup.
          purge_files_sets = list()
          purged_data = location.data.all()
          for data in purged_data:
              purge_files_sets.append(get_purge_files(
                  location.get_path(),
                  data.output,
                  data.process.output_schema,
                  data.descriptor,
                  getattr(data.descriptor_schema, 'schema', [])
              ))
  
          intersected_files = set.intersection(*purge_files_sets) if purge_files_sets else set()
          unreferenced_files.update(intersected_files)
      else:
          # Remove data directory.
          unreferenced_files.add(location.get_path())
          unreferenced_files.add(location.get_runtime_path())
  
      if verbosity >= 1:
          # Print unreferenced files
          if unreferenced_files:
              logger.info(__("Unreferenced files for location id {} ({}):", location_id, len(unreferenced_files)))
              for name in unreferenced_files:
                  logger.info(__("  {}", name))
          else:
              logger.info(__("No unreferenced files for location id {}", location_id))
  
      # Go through unreferenced files and delete them.
      if delete:
          for name in unreferenced_files:
              if os.path.isfile(name) or os.path.islink(name):
                  os.remove(name)
              elif os.path.isdir(name):
                  shutil.rmtree(name)
  
          location.purged = True
          location.save()
  
          if not referenced_by_data:
              location.delete()