def _pvi_path(granule):
    """Determine the PreView Image (PVI) path inside the SAFE pkg."""
    pvi_name = granule._metadata.iter("PVI_FILENAME").next().text
    pvi_name = pvi_name.split("/")
    pvi_path = os.path.join(
        granule.granule_path,
        pvi_name[len(pvi_name)-2], pvi_name[len(pvi_name)-1]
    )
    try:
        assert os.path.isfile(pvi_path) or \
            pvi_path in granule.dataset._zipfile.namelist()
    except (AssertionError, AttributeError):
        return None
    return pvi_path