util::resources::download (public)
util::resources::download -resource_info resource_info \ [ -version_segment version_segment ]
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_segment (optional)
- an optional directory, under the resource directory
- Author:
- Gustaf Neumann
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: # # Relevant keys in resource_info: # # "configuredVersion" the version we care about # "resourceDir" is the absolute path in the filesystem # "versionSegment" is the optional version-specific element both in the # URL and in the filesystem. # set version [dict get $resource_info configuredVersion] set resource_dir [dict get $resource_info resourceDir] if {$version_segment eq "" && [dict exists $resource_info versionSegment]} { set version_segment [dict get $resource_info versionSegment] } elseif {$version_segment eq ""} { set version_segment $version } ns_log notice "::util::resources::download" version $version resource_dir $resource_dir version_segment $version_segment if {![::util::resources::can_install_locally -resource_info $resource_info -version_segment $version_segment]} { 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_segment ne ""} { append local_path /$version_segment append download_prefix /$version_segment } 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 "... downloading single file: $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] { ns_log notice "... downloading from URL: $url" 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