'Return the subpath to the dbfile for the given blobname,
or None if not found.
Remember that this is complicated by possible multi-level
imports. E.g. "include(\'foo/bar.php\')".'

def _dbsubpath_from_blobname(self, blobname, ctlr=None, only_look_in_db=False, specific_dir=None):

    lang_zone = self.lang_zone
    self._acquire_lock()
    try:
        if (blobname in self._dir_and_blobbase_from_blobname):
            (blobdir, blobbase) = self._dir_and_blobbase_from_blobname[blobname]
            dbfile_from_blobname = lang_zone.dfb_from_dir(blobdir, self.sublang)
            if (blobbase in dbfile_from_blobname):
                log.debug("have    blob    '%s'    in    '%s'?    yes    (in    weak    cache)", blobname, blobdir)
                return join(lang_zone.dhash_from_dir(blobdir), dbfile_from_blobname[blobbase])
            del self._dir_and_blobbase_from_blobname[blobname]
        assert (self.import_handler.sep is not None), ('%r.sep    is    None,    this    must    be    set' % self.import_handler)
        blobparts = blobname.split(self.import_handler.sep)
        blobbase = blobparts[(-1)]
        for dir in self.dirs:
            if ((specific_dir is not None) and (dir != specific_dir)):
                continue
            if (ctlr and ctlr.is_aborted()):
                log.debug("aborting    search    for    blob    '%s'    on    %s:    ctlr    aborted", blobname, self)
                return None
            blobdir = join(dir, *blobparts[:(-1)])
            dbfile_from_blobname = lang_zone.dfb_from_dir(blobdir, self.sublang, {})
            if (blobbase in dbfile_from_blobname):
                self._dir_and_blobbase_from_blobname[blobname] = (blobdir, blobbase)
                log.debug("have    blob    '%s'    in    '%s'?    yes    (in    dir    index)", blobname, blobdir)
                return join(lang_zone.dhash_from_dir(blobdir), dbfile_from_blobname[blobbase])
            importables = self._importables_from_dir(blobdir)
            if (blobbase not in importables):
                continue
            (blobfile, subdir_blobbase, is_dir_import) = importables[blobbase]
            if (blobfile is None):
                log.debug("have    blob    '%s'    in    %s?    no", blobname, self)
                return None
            elif (os.sep in blobfile):
                blobdir = join(blobdir, dirname(blobfile))
                blobfile = basename(blobfile)
                blobbase = subdir_blobbase
                dbfile_from_blobname = lang_zone.dfb_from_dir(blobdir, self.sublang, {})
                if (blobbase in dbfile_from_blobname):
                    self._dir_and_blobbase_from_blobname[blobname] = (blobdir, blobbase)
                    log.debug("have    blob    '%s'    in    '%s'?    yes    (in    dir    index)", blobname, blobdir)
                    return join(lang_zone.dhash_from_dir(blobdir), dbfile_from_blobname[blobbase])
            if (not only_look_in_db):
                log.debug("%s    importables    in    '%s':\n                %s", self.sublang, blobdir, importables)
                log.debug("'%s'    likely    provided    by    '%s'    in    '%s':    attempting    load", blobname, blobfile, blobdir)
                try:
                    buf = self.mgr.buf_from_path(join(blobdir, blobfile), self.lang)
                except (EnvironmentError, CodeIntelError) as ex:
                    continue
                buf.scan_if_necessary()
                dbfile_from_blobname = lang_zone.dfb_from_dir(blobdir, self.sublang, {})
                if (blobbase in dbfile_from_blobname):
                    self._dir_and_blobbase_from_blobname[blobname] = (blobdir, blobbase)
                    log.debug("have    blob    '%s'    in    '%s'?    yes    (after    load)", blobname, blobdir)
                    return join(lang_zone.dhash_from_dir(blobdir), dbfile_from_blobname[blobbase])
        log.debug("have    blob    '%s'    in    %s?    no", blobname, self)
        return None
    finally:
        self._release_lock()
