예제 #1
0
파일: models.py 프로젝트: clchiou/garage
 def __post_init__(self):
     ASSERT.only_one((self.id, self.name or self.version, self.tag))
     ASSERT.not_xor(self.name, self.version)
     if self.id:
         validate_image_id(self.id)
     elif self.name:
         validate_image_name(self.name)
         validate_image_version(self.version)
     else:
         validate_image_tag(self.tag)
예제 #2
0
def _find_image_dir_path(image_id, name, version, tag):
    """Return path to image directory or None if not found."""
    ASSERT.only_one((image_id, name or version, tag))
    ASSERT.not_xor(name, version)
    if name:
        # We check duplicated image name and version when images are
        # imported, and so we do not check it again here.
        for image_dir_path in _iter_image_dir_paths():
            metadata = read_metadata(image_dir_path)
            if metadata.name == name and metadata.version == version:
                return image_dir_path
        return None
    if image_id:
        image_dir_path = get_image_dir_path(image_id)
    else:
        tag_path = _get_tag_path(tag)
        if not g1.files.lexists(tag_path):
            return None
        image_dir_path = _get_image_dir_path_from_tag(tag_path)
    return image_dir_path if image_dir_path.is_dir() else None