<s> import os <EOL> from bareon import errors <EOL> class Image ( object ) : <EOL> SUPPORTED_CONTAINERS = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , uri , target_device , <EOL> format , container , size = None , md5 = None , os_id = None , <EOL> os_boot = False , image_name = '<STR_LIT>' , image_uuid = '<STR_LIT>' , <EOL> deployment_flags = { } ) : <EOL> self . uri = uri <EOL> self . target_device = target_device <EOL> self . format = format <EOL> if container not in self . SUPPORTED_CONTAINERS : <EOL> raise errors . WrongImageDataError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . container = container <EOL> self . size = size <EOL> self . md5 = md5 <EOL> self . img_tmp_file = None <EOL> self . os_id = os_id <EOL> self . os_boot = os_boot <EOL> self . image_name = image_name <EOL> self . image_uuid = image_uuid <EOL> self . deployment_flags = deployment_flags <EOL> class ImageScheme ( object ) : <EOL> def __init__ ( self , images = None ) : <EOL> self . images = images or [ ] <EOL> def add_image ( self , ** kwargs ) : <EOL> self . images . append ( Image ( ** kwargs ) ) <EOL> def get_images_sorted_by_depth ( self , os_id = None , reverse = False ) : <EOL> key = lambda x : x . target_device . rstrip ( os . path . sep ) . count ( os . path . sep ) <EOL> return sorted ( self . get_os_images ( ) , key = key , reverse = reverse ) <EOL> def get_os_images ( self , os_id = None ) : <EOL> if os_id : <EOL> return filter ( lambda img : os_id in img . os_id , self . images ) <EOL> return self . images <EOL> def get_os_root ( self , os_id = None ) : <EOL> images = self . get_os_images ( os_id ) <EOL> return next ( ( image for image in images if image . target_device == '<STR_LIT:/>' ) ) </s>
