'Prepare process. Create temp directories, download and/or unpack files.'

def prepare_files(self, finder, force_root_egg_info=False, bundle=False):

    unnamed = list(self.unnamed_requirements)
    reqs = list(self.requirements.values())
    while (reqs or unnamed):
        if unnamed:
            req_to_install = unnamed.pop(0)
        else:
            req_to_install = reqs.pop(0)
        install = True
        best_installed = False
        not_found = None
        if ((not self.ignore_installed) and (not req_to_install.editable)):
            req_to_install.check_if_exists()
            if req_to_install.satisfied_by:
                if self.upgrade:
                    if ((not self.force_reinstall) and (not req_to_install.url)):
                        try:
                            url = finder.find_requirement(req_to_install, self.upgrade)
                        except BestVersionAlreadyInstalled:
                            best_installed = True
                            install = False
                        except DistributionNotFound:
                            not_found = sys.exc_info()[1]
                        else:
                            req_to_install.url = url.url
                    if (not best_installed):
                        if (not (self.use_user_site and (not dist_in_usersite(req_to_install.satisfied_by)))):
                            req_to_install.conflicts_with = req_to_install.satisfied_by
                        req_to_install.satisfied_by = None
                else:
                    install = False
            if req_to_install.satisfied_by:
                if best_installed:
                    logger.notify(('Requirement    already    up-to-date:    %s' % req_to_install))
                else:
                    logger.notify(('Requirement    already    satisfied    (use    --upgrade    to    upgrade):    %s' % req_to_install))
        if req_to_install.editable:
            logger.notify(('Obtaining    %s' % req_to_install))
        elif install:
            if (req_to_install.url and req_to_install.url.lower().startswith('file:')):
                logger.notify(('Unpacking    %s' % display_path(url_to_path(req_to_install.url))))
            else:
                logger.notify(('Downloading/unpacking    %s' % req_to_install))
        logger.indent += 2
        try:
            is_bundle = False
            is_wheel = False
            if req_to_install.editable:
                if (req_to_install.source_dir is None):
                    location = req_to_install.build_location(self.src_dir)
                    req_to_install.source_dir = location
                else:
                    location = req_to_install.source_dir
                if (not os.path.exists(self.build_dir)):
                    _make_build_dir(self.build_dir)
                req_to_install.update_editable((not self.is_download))
                if self.is_download:
                    req_to_install.run_egg_info()
                    req_to_install.archive(self.download_dir)
                else:
                    req_to_install.run_egg_info()
            elif install:
                location = req_to_install.build_location(self.build_dir, (not self.is_download))
                unpack = True
                url = None
                if req_to_install.from_bundle:
                    pass
                elif os.path.exists(os.path.join(location, 'setup.py')):
                    raise PreviousBuildDirError(textwrap.dedent(("\n                                                                                                        pip    can't    proceed    with    requirement    '%s'    due    to    a    pre-existing    build    directory.\n                                                                                                            location:    %s\n                                                                                                        This    is    likely    due    to    a    previous    installation    that    failed.\n                                                                                                        pip    is    being    responsible    and    not    assuming    it    can    delete    this.\n                                                                                                        Please    delete    it    and    try    again.\n                                                                                                " % (req_to_install, location))))
                else:
                    if (req_to_install.url is None):
                        if not_found:
                            raise not_found
                        url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
                    else:
                        url = Link(req_to_install.url)
                        assert url
                    if url:
                        try:
                            if (url.filename.endswith(wheel_ext) and self.wheel_download_dir):
                                download_dir = self.wheel_download_dir
                                do_download = True
                            else:
                                download_dir = self.download_dir
                                do_download = self.is_download
                            self.unpack_url(url, location, download_dir, do_download)
                        except HTTPError as exc:
                            logger.fatal(('Could    not    install    requirement    %s    because    of    error    %s' % (req_to_install, exc)))
                            raise InstallationError(('Could    not    install    requirement    %s    because    of    HTTP    error    %s    for    URL    %s' % (req_to_install, e, url)))
                    else:
                        unpack = False
                if unpack:
                    is_bundle = req_to_install.is_bundle
                    is_wheel = (url and url.filename.endswith(wheel_ext))
                    if is_bundle:
                        req_to_install.move_bundle_files(self.build_dir, self.src_dir)
                        for subreq in req_to_install.bundle_requirements():
                            reqs.append(subreq)
                            self.add_requirement(subreq)
                    elif self.is_download:
                        req_to_install.source_dir = location
                        if (not is_wheel):
                            req_to_install.run_egg_info()
                        if (url and (url.scheme in vcs.all_schemes)):
                            req_to_install.archive(self.download_dir)
                    elif is_wheel:
                        req_to_install.source_dir = location
                        req_to_install.url = url.url
                    else:
                        req_to_install.source_dir = location
                        req_to_install.run_egg_info()
                        if force_root_egg_info:
                            req_to_install.run_egg_info(force_root_egg_info=True)
                        req_to_install.assert_source_matches_version()
                        if (bundle and req_to_install.url):
                            self.copy_to_build_dir(req_to_install)
                            install = False
                    if (not self.ignore_installed):
                        req_to_install.check_if_exists()
                    if req_to_install.satisfied_by:
                        if (self.upgrade or self.ignore_installed):
                            if (not (self.use_user_site and (not dist_in_usersite(req_to_install.satisfied_by)))):
                                req_to_install.conflicts_with = req_to_install.satisfied_by
                            req_to_install.satisfied_by = None
                        else:
                            logger.notify(('Requirement    already    satisfied    (use    --upgrade    to    upgrade):    %s' % req_to_install))
                            install = False
            if is_wheel:
                dist = list(pkg_resources.find_distributions(location))[0]
                if (not req_to_install.req):
                    req_to_install.req = dist.as_requirement()
                    self.add_requirement(req_to_install)
                if (not self.ignore_dependencies):
                    for subreq in dist.requires(req_to_install.extras):
                        if self.has_requirement(subreq.project_name):
                            continue
                        subreq = InstallRequirement(str(subreq), req_to_install)
                        reqs.append(subreq)
                        self.add_requirement(subreq)
            elif (not is_bundle):
                finder.add_dependency_links(req_to_install.dependency_links)
                if req_to_install.extras:
                    logger.notify(('Installing    extra    requirements:    %r' % ','.join(req_to_install.extras)))
                if (not self.ignore_dependencies):
                    for req in req_to_install.requirements(req_to_install.extras):
                        try:
                            name = pkg_resources.Requirement.parse(req).project_name
                        except ValueError:
                            e = sys.exc_info()[1]
                            logger.error(('Invalid    requirement:    %r    (%s)    in    requirement    %s' % (req, e, req_to_install)))
                            continue
                        if self.has_requirement(name):
                            continue
                        subreq = InstallRequirement(req, req_to_install)
                        reqs.append(subreq)
                        self.add_requirement(subreq)
                if (not self.has_requirement(req_to_install.name)):
                    self.add_requirement(req_to_install)
            if (not is_bundle):
                if (self.is_download or (req_to_install._temp_build_dir is not None)):
                    self.reqs_to_cleanup.append(req_to_install)
            if install:
                self.successfully_downloaded.append(req_to_install)
                if (bundle and (req_to_install.url and req_to_install.url.startswith('file:///'))):
                    self.copy_to_build_dir(req_to_install)
        finally:
            logger.indent -= 2
