def add(self, image_path=None,<EOL>image_uri=None,<EOL>image_name=None,<EOL>url=None,<EOL>metadata=None,<EOL>save=True, <EOL>copy=False):
from sregistry.database.models import (<EOL>Container,<EOL>Collection<EOL>)<EOL>if image_path is not None:<EOL><INDENT>if not os.path.exists(image_path) and save is True:<EOL><INDENT>bot.error('<STR_LIT>' %image_path)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if image_uri is None:<EOL><INDENT>bot.error('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>names = parse_image_name( remove_uri(image_uri) )<EOL>bot.debug('<STR_LIT>' % names['<STR_LIT>'])    <EOL>metadata = self.get_metadata(image_path, names=names)<EOL>collection = self.get_or_create_collection(names['<STR_LIT>'])<EOL>version = names.get('<STR_LIT:version>')<EOL>if version == None:<EOL><INDENT>if image_path != None:<EOL><INDENT>version = get_image_hash(image_path)<EOL><DEDENT>else:<EOL><INDENT>version = '<STR_LIT>'  <EOL><DEDENT>names = parse_image_name( remove_uri(image_uri), version=version )<EOL><DEDENT>if save is True and image_path is not None:<EOL><INDENT>if image_name is None:      <EOL><INDENT>image_name = self._get_storage_name(names)<EOL><DEDENT>if copy is True:<EOL><INDENT>copyfile(image_path, image_name)<EOL><DEDENT>else:<EOL><INDENT>shutil.move(image_path, image_name)<EOL><DEDENT>image_path = image_name<EOL><DEDENT>if url is None and "<STR_LIT:url>" in metadata:<EOL><INDENT>url = metadata['<STR_LIT:url>']<EOL><DEDENT>container = self.get_container(name=names['<STR_LIT:image>'],<EOL>collection_id=collection.id, <EOL>tag=names['<STR_LIT>'],<EOL>version=version)<EOL>if container is None:<EOL><INDENT>action = "<STR_LIT>"<EOL>container = Container(metrics=json.dumps(metadata),<EOL>name=names['<STR_LIT:image>'],<EOL>image=image_path,<EOL>client=self.client_name,<EOL>tag=names['<STR_LIT>'],<EOL>version=version,<EOL>url=url,<EOL>uri=names['<STR_LIT>'],<EOL>collection_id=collection.id)<EOL>self.session.add(container)<EOL>collection.containers.append(container)<EOL><DEDENT>else:<EOL><INDENT>action="<STR_LIT>"<EOL>metrics=json.loads(container.metrics)<EOL>metrics.update(metadata)<EOL>container.url= url<EOL>container.client=self.client_name<EOL>if image_path is not None:<EOL><INDENT>container.image=image_path<EOL><DEDENT>container.metrics=json.dumps(metrics)<EOL><DEDENT>self.session.commit()<EOL>bot.info("<STR_LIT>" % (action,names['<STR_LIT>']))<EOL>return container<EOL>
get or create a container, including the collection to add it to.
    This function can be used from a file on the local system, or via a URL
    that has been downloaded. Either way, if one of url, version, or image_file
    is not provided, the model is created without it. If a version is not
    provided but a file path is, then the file hash is used.

    Parameters
    ==========
    image_path: full path to image file
    image_name: if defined, the user wants a custom name (and not based on uri)
    metadata: any extra metadata to keep for the image (dict)
    save: if True, move the image to the cache if it's not there
    copy: If True, copy the image instead of moving it.

    image_name: a uri that gets parsed into a names object that looks like:

    {'collection': 'vsoch',
     'image': 'hello-world',
     'storage': 'vsoch/hello-world-latest.img',
     'tag': 'latest',
     'version': '12345'
     'uri': 'vsoch/hello-world:latest@12345'}

    After running add, the user will take some image in a working
    directory, add it to the database, and have it available for search
    and use under SREGISTRY_STORAGE/<collection>/<container>

    If the container was retrieved from a webby place, it should have version
    If no version is found, the file hash is used.