Create a reference of site images by hash

        If there are duplicate images, only store the first
        and create warnings for other images
184394
def get_image_details(self):
        '''
        
        '''
        if Image.objects.count() == 0:
            return None

        total = Image.objects.count()
        count = 1
        for local_image in Image.objects.all():
            if not hasattr(local_image, 'image_info'):
                ImageInfo.objects.create(image=local_image)
                local_image.refresh_from_db()

            hash_ = local_image.image_info.image_hash

            if hash_ in self.image_hashes:
                self.log(WARNING, "Image found with matching hash", context={
                    "composite hash": hash_,
                    "hashed image ID": self.image_hashes[hash_].id,
                    "matching image ID": local_image.id,
                })
            else:
                self.image_hashes[hash_] = local_image

            self.log(ACTION, "{}/{} images processed".format(count, total))
            count += 1
1269493
def report
      dups = duplicates
      s = "Base dir: #{@dirname}\n"
      s += "Nr. file: #{size}"
      if dups.size > 0
        s+= " (duplicates #{dups.size})"
      end
      s += "\nBytes: #{bytes.with_separator}"
      s
    end
988126
def _get_original_site(structure, site):
        """"""
        for i, s in enumerate(structure):
            if site.is_periodic_image(s):
                return i
        raise Exception('Site not found!')
827048
def _mark_image_file_stored(cls, mapper, connection, target):
        
        try:
            file_ = target.file
        except AttributeError:
            raise TypeError('sqlalchemy_imageattach.entity.Image which is '
                            'to be inserted must have file to store')
        try:
            try:
                store = target.store
            except AttributeError:
                raise TypeError('sqlalchemy_imageattach.entity.Image which is '
                                'to be inserted must have store for the file')
            store.store(target, file_)
            cls._stored_images.add((target, store))
            del target.file, target.store
        finally:
            file_.close()
168694
def url(name = nil)
      if name
        if version_identifiers.include?(name.to_s)
          self[:@versions][name.to_s][:@url]
        else
          raise "Invalid Image Version identifier: '#{name}' (must be #{version_identifiers.join(', ')})"
        end
      else
        self[:@url]
      end
    end
211252
def merge_id_hashes_helper(hash, array_of_refs, src, path = [])
      ref = array_of_refs.shift
      field = hash[ref]

      if array_of_refs.empty? && field
        value = value_from_hash(src, path + [ref])
        if value.is_a?(Array)
          hash[ref] = (field + value).uniq
        else
          hash.delete(ref)
        end
      else
        case field
        when Array
          field.each_with_index do |f, index|
            merge_id_hashes_helper(f, array_of_refs.dup, src, path + [ref, index])
          end
        when Hash
          merge_id_hashes_helper(field, array_of_refs, src, path + [ref])
        end
      end
    end
1158620
def check_if_not_duplicate(key, values, name)
      if values.key? key
        raise SwaggerInvalidException.new("#{name} already exist for #{key} with value [#{values[key]}]")
      end
    end
1000835
def WriteHashBlobReferences(self, references_by_hash, cursor):
    """"""
    values = []
    for hash_id, blob_refs in iteritems(references_by_hash):
      refs = rdf_objects.BlobReferences(items=blob_refs).SerializeToString()
      values.append({
          "hash_id": hash_id.AsBytes(),
          "blob_references": refs,
      })
    _Insert(cursor, "hash_blob_references", values)
256601
function(checksum, callback) {
        var query = (new ImboQuery()).originalChecksums([checksum]).limit(1);
        this.getImages(query, function(err, images, search) {
            if (err) {
                return callback(err);
            }

            var exists = search.hits > 0;
            callback(err, exists, exists ? images[0].imageIdentifier : err);
        });

        return this;
    }
558761
def avail_images(call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The avail_images function must be called with '
            '-f or --function, or with the --list-images option'
        )

    fetch = True
    page = 1
    ret = {}

    while fetch:
        items = query(method='images', command='?page=' + six.text_type(page) + '&per_page=200')

        for image in items['images']:
            ret[image['name']] = {}
            for item in six.iterkeys(image):
                ret[image['name']][item] = image[item]

        page += 1
        try:
            fetch = 'next' in items['links']['pages']
        except KeyError:
            fetch = False

    return ret
594432
def deep_dup(obj)
      if obj.is_a?(Hash)
        result = {}
        obj.each { |k,v| result[k] = deep_dup(v) }
        result
      elsif obj.is_a?(Array)
        obj.map { |el| deep_dup(el) }
      else
        dup_or_self(obj)
      end
    end
835665
def photos=(values)
      @photos = values.map do |photo|
        photo.map do |photo_size_attrs|
          PhotoSize.new(photo_size_attrs)
        end
      end
    end
429634
function Image(src) {
  if (!(this instanceof Image)) {
    return new Image(src)
  }

  if (typeof src !== 'string') {
    throw new Error('param `src` must be a string')
  }

  var ret = reg.exec(src)

  if (!ret) {
    throw new Error('invalid param `src`')
  }

  this.src = src
  this.host = ret[1] || defaultHost
  this.version = ret[2] ? ret[2].slice(0, -1) : ''
  this.hash = ret[3]
  this.ext = ret[4]
}
789881
function allUnique(arr) {
    var hash = {},
        index,
        len;

    for (index = 0, len = arr.length; index < len; index++) {
        if (hash[arr[index]]) {
            return false;
        }
        hash[arr[index]] = true;
    }
    return true;
}
606571
def images(args={})
      hashes = con.describe_images('Owner' => 'self').body['imagesSet'].collect do |hash|
        h = {}
        h[:image_id]  = hash['imageId']
        h[:name]  = hash['name']
        h[:rootDeviceType] = hash['rootDeviceType']
        h
      end 
      puts Formatador.display_table(hashes)
    end
321585
function stripDuplicates(results) {
  var i;
  var placeshash = {};
  var stripped = [];
  for (i = 0; i < results.length; i++) {
    var lat = Number(results[i].location.split(",")[0]).toFixed(1);
    var lng = Number(results[i].location.split(",")[1]).toFixed(1);

    var hash = results[i].name + "_" + lat + " " + lng;
    if (!defined(placeshash[hash])) {
      placeshash[hash] = results[i];
      stripped.push(results[i]);
    }
  }
  return stripped;
}
548904
def update_photo
      content_tag = params[:content_tag]
      # photo = ContentPhoto.find(params[:id])
      # find would throw error if not found
      photo = ContentPhoto.find_by_id(params[:id])
      unless photo
        if content_tag
          # where photo has never been set before, associated Content will not exist
          content = Content.find_by_key(content_tag) || Content.create({ key: content_tag, tag: 'appearance' })
          photo = ContentPhoto.create
          if content_tag == "logo"
            # TODO: This is a workaround
            # need to have a way of determining content that should only have
            # one photo and enforcing that
            content.content_photos.destroy_all
          end
          content.content_photos.push photo
        end
        # TODO: - handle where no photo or content_tag..
      end
      if params[:file]
        photo.image = params[:file]
      end
      photo.save!
      photo.reload
      render json: photo.to_json
    end