summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authormottelet <stephane.mottelet@utc.fr>2020-11-27 09:36:43 +0100
committerClément David <clement.david@esi-group.com>2021-02-18 18:30:07 +0100
commitc79031ff5be0fe30a657060807cbce6706e2cbec (patch)
treea15948f82d7ef3f76ef88c54f746c8b0610b7e61 /scilab
parent613bf779f5469b5286398d1fd42fbeeefa5147fa (diff)
downloadscilab-c79031ff5be0fe30a657060807cbce6706e2cbec.zip
scilab-c79031ff5be0fe30a657060807cbce6706e2cbec.tar.gz
[atoms] add http_get as a failsafe downloading method
Under new macOS 11.0 neither curl or wget seem to work when invoked via unix_w (network entitlement problem). The idea is to propose http_get as a failsafe method for all platforms. Change-Id: Ibdc9c9eb9f8e0c1bc334003bb68cf42f220494b5
Diffstat (limited to 'scilab')
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/atoms/help/en_US/atomsSetConfig.xml2
-rw-r--r--scilab/modules/atoms/macros/atoms_internals/atomsDownload.sci58
3 files changed, 49 insertions, 12 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index 7b1f48b..506007d 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -28,6 +28,7 @@ For a high-level description of the main new features of this release, please co
28 28
29In summary, the main new features are: 29In summary, the main new features are:
30* Webtools utilities added for HTTP protocol, JSON data usage 30* Webtools utilities added for HTTP protocol, JSON data usage
31 - http_get can be used as an alternative download method for ATOMS
31* Profiled values are available as Scilab values 32* Profiled values are available as Scilab values
32* Values have a cleaner display: 33* Values have a cleaner display:
33 - they are displayed in order on assignment 34 - they are displayed in order on assignment
diff --git a/scilab/modules/atoms/help/en_US/atomsSetConfig.xml b/scilab/modules/atoms/help/en_US/atomsSetConfig.xml
index 0bb0b8f..8ec5a12 100644
--- a/scilab/modules/atoms/help/en_US/atomsSetConfig.xml
+++ b/scilab/modules/atoms/help/en_US/atomsSetConfig.xml
@@ -161,7 +161,7 @@
161 <tr> 161 <tr>
162 <td>downloadTool</td> 162 <td>downloadTool</td>
163 <td>Set tool used to download</td> 163 <td>Set tool used to download</td>
164 <td>"curl", "wget" or "httpdownload" (Windows only)</td> 164 <td>"curl", "wget", "http_get" or "httpdownload" (Windows only)</td>
165 </tr> 165 </tr>
166 <tr> 166 <tr>
167 <td>downloadTimeout</td> 167 <td>downloadTimeout</td>
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsDownload.sci b/scilab/modules/atoms/macros/atoms_internals/atomsDownload.sci
index 2e40d3e..4b6e5ee 100644
--- a/scilab/modules/atoms/macros/atoms_internals/atomsDownload.sci
+++ b/scilab/modules/atoms/macros/atoms_internals/atomsDownload.sci
@@ -72,6 +72,7 @@ function atomsDownload(url_in,file_out,md5sum)
72 72
73 CURL = %F; 73 CURL = %F;
74 WGET = %F; 74 WGET = %F;
75 HTTP_GET = %F;
75 HTTPDOWNLOAD = %F; 76 HTTPDOWNLOAD = %F;
76 77
77 // Maybe the detection has already been done 78 // Maybe the detection has already been done
@@ -80,6 +81,8 @@ function atomsDownload(url_in,file_out,md5sum)
80 WGET = %T; 81 WGET = %T;
81 elseif atomsGetConfig("downloadTool") == "curl" then 82 elseif atomsGetConfig("downloadTool") == "curl" then
82 CURL = %T; 83 CURL = %T;
84 elseif atomsGetConfig("downloadTool") == "http_get" then
85 HTTP_GET = %T;
83 elseif atomsGetConfig("downloadTool") == "httpdownload" & getos() == "Windows" then 86 elseif atomsGetConfig("downloadTool") == "httpdownload" & getos() == "Windows" then
84 HTTPDOWNLOAD = %T; 87 HTTPDOWNLOAD = %T;
85 else 88 else
@@ -199,22 +202,55 @@ function atomsDownload(url_in,file_out,md5sum)
199 // Save the parameter to always download with httpdownload 202 // Save the parameter to always download with httpdownload
200 if stat == 0 then 203 if stat == 0 then
201 atomsSetConfig("downloadTool","httpdownload"); 204 atomsSetConfig("downloadTool","httpdownload");
202 else 205 end
203 select stat, 206 end
204 case -1 then mprintf(gettext("%s: Error: the response status from the URL %s is invalid.\n"), "atomsDownload", url_in), 207
205 case -2 then mprintf(gettext("%s: Error while opening an Internet connection.\n"), "atomsDownload"), 208 if (HTTP_GET | stat<>0) then
206 case -3 then mprintf(gettext("%s: Error while opening the URL %s.\n"), "atomsDownload", url_in), 209 try
207 case -4 then mprintf(gettext("%s: Error while creating the file %s on disk.\n"), "atomsDownload", file_out), 210 [res,http_status] = http_get(url_in,file_out);
208 case -5 then mprintf(gettext("%s: Error while retrieving the size of file at URL %s.\n"), "atomsDownload", url_in), 211 select http_status
209 case -6 then mprintf(gettext("%s: Error while reading the file from the URL %s.\n"), "atomsDownload", url_in), 212 case 200 then
210 case -7 then mprintf(gettext("%s: Error while writing the file %s on disk.\n"), "atomsDownload", file_out), 213 stat = 0;
211 case -8 then mprintf(gettext("%s: Error while downloading the file from the URL %s.\n"), "atomsDownload", url_in), 214 else
212 case -9 then mprintf(gettext("%s: Error: out of memory.\n"), "atomsDownload"), 215 stat = -1;
216 end
217 catch
218 error_message = lasterror();
219 select error_message($);
220 case _("Couldn''t resolve host name") then
221 stat = -2;
222 case msprintf(_("%s: Wrong value for input argument #%d: The given path does not exist.\n"),"http_get",2) then
223 stat = -7;
213 end 224 end
214 end 225 end
226
227 // Save the parameter to always download with http_get
228 if stat == 0 then
229 atomsSetConfig("downloadTool","http_get");
230 end
215 end 231 end
216 232
217 if stat <> 0 then 233 if stat <> 0 then
234 select stat,
235 case -1 then
236 mprintf(gettext("%s: Error: the response status from the URL %s is invalid.\n"), "atomsDownload", url_in),
237 case -2 then
238 mprintf(gettext("%s: Error while opening an Internet connection.\n"), "atomsDownload"),
239 case -3 then
240 mprintf(gettext("%s: Error while opening the URL %s.\n"), "atomsDownload", url_in),
241 case -4 then
242 mprintf(gettext("%s: Error while creating the file %s on disk.\n"), "atomsDownload", file_out),
243 case -5 then
244 mprintf(gettext("%s: Error while retrieving the size of file at URL %s.\n"), "atomsDownload", url_in),
245 case -6 then
246 mprintf(gettext("%s: Error while reading the file from the URL %s.\n"), "atomsDownload", url_in),
247 case -7 then
248 mprintf(gettext("%s: Error while writing the file %s on disk.\n"), "atomsDownload", file_out),
249 case -8 then
250 mprintf(gettext("%s: Error while downloading the file from the URL %s.\n"), "atomsDownload", url_in),
251 case -9 then
252 mprintf(gettext("%s: Error: out of memory.\n"), "atomsDownload"),
253 end
218 mprintf(gettext("%s: The following file hasn''t been downloaded:\n"), "atomsDownload"); 254 mprintf(gettext("%s: The following file hasn''t been downloaded:\n"), "atomsDownload");
219 mprintf(gettext("\t - URL : ''%s''\n"), url_in); 255 mprintf(gettext("\t - URL : ''%s''\n"), url_in);
220 mprintf(gettext("\t - Local location : ''%s''\n"), file_out); 256 mprintf(gettext("\t - Local location : ''%s''\n"), file_out);