def stage(self, startimage, newimage):
client = utils.get_client()<EOL>cprint('<STR_LIT>'<EOL>% (self.sourceimage, self.sourcepath, startimage, self.destpath),<EOL>'<STR_LIT>')<EOL>cachedir = self._setcache(client)<EOL>cacherelpath = os.path.relpath(cachedir, TMPDIR)<EOL>if os.path.exists(cachedir) and not os.path.exists(os.path.join(cachedir, '<STR_LIT>')):<EOL><INDENT>shutil.rmtree(cachedir)<EOL><DEDENT>if not os.path.exists(cachedir):<EOL><INDENT>print('<STR_LIT>' % cacherelpath)<EOL>container = client.containers.create(self.sourceimage)<EOL>try:<EOL><INDENT>tarfile_stream, tarfile_stats = container.get_archive(self.sourcepath)<EOL><DEDENT>except docker.errors.NotFound:<EOL><INDENT>raise errors.MissingFileError(<EOL>'<STR_LIT>' %<EOL>(self.sourcepath, self.sourceimage))<EOL><DEDENT>tempdir = tempfile.mkdtemp(dir=BUILD_TEMPDIR)<EOL>with open(os.path.join(tempdir, '<STR_LIT>'), '<STR_LIT:wb>') as localfile:<EOL><INDENT>for chunk in tarfile_stream:<EOL><INDENT>localfile.write(chunk)<EOL><DEDENT><DEDENT>os.mkdir(cachedir)<EOL>os.rename(tempdir, cachedir)<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>' % cacherelpath)<EOL><DEDENT>dockerfile = '<STR_LIT>' % (startimage, self.destpath)<EOL>with open(os.path.join(cachedir, '<STR_LIT>'), '<STR_LIT:w>') as df:<EOL><INDENT>df.write(dockerfile)<EOL><DEDENT>buildargs = dict(path=cachedir,<EOL>tag=newimage,<EOL>decode=True)<EOL>utils.set_build_cachefrom(self.cache_from, buildargs, client)<EOL>stream = client.api.build(**buildargs)<EOL>try:<EOL><INDENT>utils.stream_docker_logs(stream, newimage)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>raise errors.BuildError(dockerfile, e.args[<NUM_LIT:0>], build_args=buildargs)<EOL><DEDENT>
Copies the file from source to target

        Args:
            startimage (str): name of the image to stage these files into
            newimage (str): name of the created image