def download_tree(url_crowdlabs, vtid, path_to_figures, pdf=False,
                  build_always=False):
    log("download_tree")
    if not path_exists_and_not_empty(path_to_figures) or build_always:
        if not os.path.exists(path_to_figures):
            os.makedirs(path_to_figures)
        
        if check_url(url_crowdlabs):
            website = "://".join(urlparse(url_crowdlabs)[:2])
            if not pdf:
                request = "/vistrails/generate_provenance_image/%s/"%vtid
            else:
                request = "/vistrails/generate_provenance_pdf/%s/"%vtid
            url = url_crowdlabs + request
            log("from %s"%url)
            try:
                page = download_as_text(url)
                # we will look for a list of comma separated in the html
                images = page.split(",")
                if len(images) > 0:
                    failed = False
                    for i in images:
                        msg = ''
                        pngfile = i.strip()
                        if not check_url(pngfile):
                            img = website + pngfile
                        else:
                            img = pngfile
                        if not download(img, os.path.join(path_to_figures,
                                        os.path.basename(img))):
                            msg += "Error when download image: %s. <return>" %\
                                   img
                            failed = True
                    if not failed:
                        log("success")
                        return (True, generate_latex(url_crowdlabs + "/vistrails/", vtid,
                                                     path_to_figures,
                                                     graphics_options))
                    else:
                        log("failed: %s"%msg)
                        return (False, generate_latex_error(msg))
                else:
                    msg = "Web server returned: %s" % page
                    log("failed: %s"%msg)
                    return (False, generate_latex_error(msg))
            
            except Exception, e:
                log("failed with exception: %s"%str(e))
                return (False, generate_latex_error(str(e)))
        else:
            msg = "Invalid url: %s" % url_crowdlabs
            log("failed: %s"%msg)
            return (False, generate_latex_error(msg))
    else:
        log("using cached images")
        return (True, generate_latex(url_crowdlabs + "/vistrails/", vtid,
                                     path_to_figures, graphics_options))
    
    
###############################################################################
download_tree(url_crowdlabs: str, vtid: str, path_to_figures: str, 
dataset/ETHPy150Open VisTrails/VisTrails/extensions/latex/includecrowdlabs.py/download_tree