def create_virtualenv(srcdir, datadir, preload_image, get_container_name):
try:<EOL><INDENT>if docker.is_boot2docker():<EOL><INDENT>docker.data_only_container(<EOL>get_container_name('<STR_LIT>'),<EOL>['<STR_LIT>'],<EOL>)<EOL>img_id = docker.web_command(<EOL>'<STR_LIT>',<EOL>image=preload_image,<EOL>commit=True,<EOL>)<EOL>docker.web_command(<EOL>command='<STR_LIT>',<EOL>volumes_from=get_container_name('<STR_LIT>'),<EOL>image=img_id,<EOL>)<EOL>docker.remove_image(img_id)<EOL>return<EOL><DEDENT>docker.web_command(<EOL>command='<STR_LIT>',<EOL>rw={datadir + '<STR_LIT>': '<STR_LIT>'},<EOL>image=preload_image,<EOL>)<EOL><DEDENT>finally:<EOL><INDENT>rw = {datadir + '<STR_LIT>': '<STR_LIT>'} if not docker.is_boot2docker() else {}<EOL>volumes_from = get_container_name('<STR_LIT>') if docker.is_boot2docker() else None<EOL>docker.web_command(<EOL>command='<STR_LIT>',<EOL>rw=rw,<EOL>volumes_from=volumes_from,<EOL>ro={srcdir: '<STR_LIT>'},<EOL>)<EOL><DEDENT>
Populate venv from preloaded image