util::resources::download (public)

 util::resources::download -resource_info resource_info \
    [ -version_dir version_dir ]

Defined in packages/acs-tcl/tcl/utilities-procs.tcl

Download resources typically from a CDN and install it for local usage. The installed files are as well gzipped for faster delivery, when gzip is available.-

Switches:
-resource_info
(required)
a dict containing resourceDir, cdn, cssFiles, jsFiles, and extraFiles
-version_dir
(optional)
an optional directory, under the resource directory
Author:
Gustaf Neumann

Partial Call Graph (max 5 caller/called nodes):
%3 bootstrap_icons::download bootstrap_icons::download (private) util::resources::download util::resources::download bootstrap_icons::download->util::resources::download fa_icons::download fa_icons::download (private) fa_icons::download->util::resources::download highcharts::download highcharts::download (private) highcharts::download->util::resources::download packages/cookie-consent/www/sitewide-admin/download.tcl packages/cookie-consent/ www/sitewide-admin/download.tcl packages/cookie-consent/www/sitewide-admin/download.tcl->util::resources::download packages/openacs-bootstrap3-theme/www/sitewide-admin/download.tcl packages/openacs-bootstrap3-theme/ www/sitewide-admin/download.tcl packages/openacs-bootstrap3-theme/www/sitewide-admin/download.tcl->util::resources::download ad_file ad_file (public) util::resources::download->ad_file util::resources::can_install_locally util::resources::can_install_locally (public) util::resources::download->util::resources::can_install_locally util::resources::download_helper util::resources::download_helper (private) util::resources::download->util::resources::download_helper util::resources::version_dir util::resources::version_dir (public) util::resources::download->util::resources::version_dir util::which util::which (public) util::resources::download->util::which

Testcases:
No testcase defined.
Source code:
        set resource_dir [dict get $resource_info resourceDir]
        set version_dir [version_dir  -version_dir $version_dir  -resource_info $resource_info]

        set can_install [::util::resources::can_install_locally  -resource_info $resource_info  -version_dir $version_dir]
        if {!$can_install} {
            error "Cannot download resources to $resource_dir due to permissions"
        }

        #
        # Get the CDN prefix (this does not include the source version
        # information as used on the CDN).
        #
        set download_prefix https:[dict get $resource_info cdn]
        set local_path $resource_dir

        if {$version_dir ne ""} {
            append local_path /$version_dir
            append download_prefix /$version_dir
        }
        if {![ad_file writable $local_path]} {
            file mkdir $local_path
        }

        #
        # Do we have gzip installed?
        #
        set gzip [::util::which gzip]

        #
        # So far, everything went fine. Now download the files and
        # raise an exception, when the download fails.
        #
        foreach file [concat  [dict get $resource_info cssFiles]  [dict get $resource_info jsFiles]  [dict get $resource_info extraFiles]  ] {

            ns_log notice "::util::resources::download $download_prefix/$file"
            set result [download_helper -url $download_prefix/$file]
            #ns_log notice "... returned status code [dict get $result status]"
            set fn [dict get $result file]

            set local_root [ad_file dirname $local_path/$file]
            if {![ad_file isdirectory $local_root]} {
                file mkdir $local_root
            }
            file rename -force -- $fn $local_path/$file

            #
            # Remove potentially stale gzip file.
            #
            if {[ad_file exists $local_path/$file.gz]} {
                file delete -- $local_path/$file.gz
            }

            #
            # When gzip is available, produce a static compressed file
            # as well.
            #
            if {$gzip ne ""} {
                #
                # Recent versions of gzip (starting with gzip 1.6,
                # released 2013) should use:
                #
                #      exec $gzip -9 -k $local_path/$file
                #
                # For backwards compatibility, we use redirects.
                #
                exec $gzip -9 < $local_path/$file > $local_path/$file.gz
            }
        }

        if {[dict exists $resource_info downloadURLs]} {
            #
            # For downloadURLs, just handle here the download. How to
            # decompress these archives and what to do with these to
            # install it properly is handled by package-speficic
            # downloaders, which might call this function.
            #
            foreach url [dict get $resource_info downloadURLs] {
                set result [download_helper -url $url]
                set fn [dict get $result file]
                set file [ad_file tail $url]
                file rename -force -- $fn $local_path/$file
            }
        }
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/utilities-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: