def _get_file_hash(self, path):
        indb = False
        if self._is_cache:
            try:
                rr = self._cc.execute(
                    "select path, %s from files where path=?" %
                    self._method, (path, ))
                row = rr.fetchone()
                if row is not None:
                    indb = True
                    if row[1] != '':
                        debug('get path: %s hash: %s from db' %
                              (path, row[1]))
                        return row[1]

            except sqlite3.OperationalError:
                traceback.print_exc()

        res = ''
        try:
            with open(path, "rb") as fh:
                if self._method == 'crc':
                    res = self._crc_fh(fh)

                elif self._method in ['md5', 'sha1']:
                    res = self._method_fh(fh)

                elif self._method in ['part_md5', 'part_sha1']:
                    res = self._part_method_fh(fh)

                if self._is_cache:
                    if indb is False:
                        self._cc.execute(
                            "insert into files (path, size, %s) \
                            values (?, ?, ?)" %
                            self._method,
                            (path,
                             self._path_files[path]['size'],
                             res))

                    else:
                        self._cc.execute(
                            "update files set %s=? where path=?" %
                            self._method,
                            (res, path))

                    self._cache_conn.commit()

                debug("hash of %s is: %s" % (path, res))

        except IOError as e:
            warning("file hash error: %s: %s" % (e.filename, e.strerror))
            res = ''

        return res
    def _get_file_hash(self, path, method='ahash'):
        func = imagehash.average_hash
        if method == 'phash':
            func = imagehash.phadh

        elif method == 'dhash':
            func = imagehash.dhash

        try:
            res = func(Image.open(path))
            info("hash of %s is: %s" % (path, res))
            return res

        except IOError as e:
            warning("load file %s error: %s" % (path, repr(e)))