Atoms modified to use archiveExtract and getURL functions 09/17009/2
Kartik Gupta [Fri, 7 Aug 2015 13:10:36 +0000 (18:10 +0530)]
Change-Id: Idd1cd9c6875f1da6188e11dc964a14ba10f86345

scilab/modules/atoms/macros/atoms_internals/atomsDownload.sci
scilab/modules/atoms/macros/atoms_internals/atomsExtract.sci

index df94081..b64bf99 100644 (file)
@@ -63,155 +63,11 @@ function atomsDownload(url_in,file_out,md5sum)
     if (rhs>2) & (length(md5sum)<>32) then
         error(msprintf(gettext("%s: Wrong length for input argument #%d: String which has 32-characters length expected.\n"),"atomsDownload",3));
     end
-
-    // curl, wget or httpdownload
-    // =========================================================================
-
-    CURL     = %F;
-    WGET     = %F;
-    HTTPDOWNLOAD = %F;
-
-    // Maybe the detection has already been done
-
-    if atomsGetConfig("downloadTool") == "wget" then
-        WGET = %T;
-    elseif atomsGetConfig("downloadTool") == "curl" then
-        CURL = %T;
-    elseif atomsGetConfig("downloadTool") == "httpdownload" & getos() == "Windows" then
-        HTTPDOWNLOAD = %T;
-    else
-        // Default values according to platform
-        if LINUX | SOLARIS | BSD then
-
-            // Need to detect under Linux platforms
-            [rep, stat, err] = unix_g("wget --version");
-
-            if stat == 0 then
-                WGET = %T;
-                atomsSetConfig("downloadTool", "wget");
-            else
-                [rep, stat, err] = unix_g("curl --version");
-                if stat == 0 then
-                    CURL = %T;
-                    atomsSetConfig("downloadTool", "curl");
-                else
-                    error(msprintf(gettext("%s: Neither Wget or Curl found: Please install one of them\n"), "atomsDownload"));
-                end
-            end
-        elseif MACOSX | getos() == "Windows" then
-            CURL = %T;
-            atomsSetConfig("downloadTool", "curl");
-        end
-    end
-
-    // Build the command
-    // =========================================================================
-    winId = [];
-
-    if regexp(url_in, "/^(https?|ftp):\/\//", "o") == 1 then
-        proxy_host_arg = "";
-        proxy_user_arg = "";
-        timeout_arg  = "";
-
-        // Timeout configuration
-        if CURL then
-            // Curl
-            timeout_arg = " --connect-timeout ";
-        else
-            // wget
-            timeout_arg = " --timeout=";
-        end
-
-        timeout = strtod(atomsGetConfig("downloadTimeout"));
-
-        if ~isnan(timeout) then // Value found in config file
-            timeout_arg = timeout_arg + string(timeout);
-        else // Default timeout
-            timeout_arg = timeout_arg + "5";
-        end
-
-        timeout_arg = timeout_arg + " ";
-
-        // Proxy configuration
-        if (atomsGetConfig("useProxy") == "True") & (atomsGetConfig("proxyHost") <> "") then
-            // Host
-            proxy_host = atomsGetConfig("proxyHost");
-
-            // Port
-            if atomsGetConfig("proxyPort") <> "" then
-                proxy_host =  proxy_host + ":" + atomsGetConfig("proxyPort");
-            end
-
-            // Host/port Argument
-            if CURL then
-                // Curl
-                proxy_host_arg = " --proxy "+ proxy_host;
-            else
-                // wget
-                proxy_host_arg = " http_proxy="""+proxy_host+""" ";
-            end
-
-            // Username/Password
-            if and([atomsGetConfig("proxyUser");atomsGetConfig("proxyPassword")]<> "") then
-                if CURL then
-                    // Curl
-                    proxy_user_arg = " --proxy-user "+atomsGetConfig("proxyUser")+":"+atomsGetConfig("proxyPassword");
-                else
-                    // wget
-                    proxy_user_arg = " --proxy-user="""+atomsGetConfig("proxyUser")+""" --proxy-password="""+atomsGetConfig("proxyPassword")+"""";
-                end
-            end
-
-        end
-
-        if WGET & atomsGetConfig("useProxy") == "False" then
-            proxy_user_arg = " --no-proxy";
-        end
-
-
-        if getos() == "Windows" & CURL then
-            download_cmd = """" + pathconvert(SCI+"/tools/curl/curl.exe",%F) + """" + proxy_host_arg + proxy_user_arg + timeout_arg + " -s """ + url_in + """ -o """ + file_out + """";
-        elseif CURL then
-            // curl
-            download_cmd = "curl "+proxy_host_arg+proxy_user_arg+timeout_arg+" -s "+url_in + " -o " + file_out;
-        else
-            // wget
-            download_cmd = proxy_host_arg+"wget"+proxy_user_arg+timeout_arg+" "+url_in + " -O " + file_out;
-        end
-
+   
+    if regexp(url_in, "/^(http|ftp):\/\//", "o") == 1 then 
         winId = atomsOpenProgressBar(_("Download in progress... Please be patient."), %f);
-
-        err = [];
-        [rep,stat,err] = unix_g(download_cmd);
-
-        // Second try with httpdownload
-        if ( HTTPDOWNLOAD | stat<>0 ) & (getos() == "Windows") then
-            imode = ilib_verbose();
-            ilib_verbose(0) ;
-            id  = link(SCI+"/bin/windows_tools.dll","httpdownload","c");
-            stat  = call("httpdownload", url_in, 1, "c", file_out, 2, "c", "out", [1,1], 3, "d");
-            ulink(id);
-            ilib_verbose(imode);
-
-            // Save the parameter to always download with httpdownload
-            if stat == 0 then
-                atomsSetConfig("downloadTool","httpdownload");
-            else
-                select stat,
-                case -1 then mprintf(gettext("%s: Error: the response status from the URL %s is invalid.\n"), "atomsDownload", url_in),
-                case -2 then mprintf(gettext("%s: Error while opening an Internet connection.\n"), "atomsDownload"),
-                case -3 then mprintf(gettext("%s: Error while opening the URL %s.\n"), "atomsDownload", url_in),
-                case -4 then mprintf(gettext("%s: Error while creating the file %s on disk.\n"), "atomsDownload", file_out),
-                case -5 then mprintf(gettext("%s: Error while retrieving the size of file at URL %s.\n"), "atomsDownload", url_in),
-                case -6 then mprintf(gettext("%s: Error while reading the file from the URL %s.\n"), "atomsDownload", url_in),
-                case -7 then mprintf(gettext("%s: Error while writing the file %s on disk.\n"), "atomsDownload", file_out),
-                case -8 then mprintf(gettext("%s: Error while downloading the file from the URL %s.\n"), "atomsDownload", url_in),
-                case -9 then mprintf(gettext("%s: Error: out of memory.\n"), "atomsDownload"),
-                end
-            end
-        end
-
-        if stat <> 0 then
+       ret = getURL(url_in,file_out);
+        if ret <> file_out then
             mprintf(gettext("%s: The following file hasn''t been downloaded:\n"), "atomsDownload");
             mprintf(gettext("\t - URL      : ''%s''\n"), url_in);
             mprintf(gettext("\t - Local location : ''%s''\n"), file_out);
index 129dd94..ef89da7 100644 (file)
@@ -59,40 +59,31 @@ function dir_created = atomsExtract(archive_in,dir_out)
 
     // Operating system detection + Architecture detection
     // =========================================================================
-    [OSNAME,ARCH,LINUX,MACOSX,SOLARIS,BSD] = atomsGetPlatform();
+//    [OSNAME,ARCH,LINUX,MACOSX,SOLARIS,BSD] = atomsGetPlatform();
 
     // Get the list of directories before the extraction
     // =========================================================================
     dirs_before = atomsListDir(dir_out);
-
+    ret = -1;
     // Build the extract command
     // =========================================================================
 
     if ( LINUX | MACOSX | SOLARIS | BSD ) & regexp(archive_in,"/(\.tar\.gz|\.tgz)$/","o") <> [] then
-
-        extract_cmd = "tar xzf "+ archive_in + " -C """+ dir_out + """";
-
-    elseif regexp(archive_in,"/\.zip$/","o") <> [] then
+          ret = archiveExtract(archive_in,%t,dir_out);
 
         if getos() == "Windows" then
-            extract_cmd = """" + getshortpathname(pathconvert(SCI+"/tools/zip/unzip.exe",%F)) + """";
-        else
-            extract_cmd = "unzip";
+           ret = archiveExtract(archive_in,%t,pathconvert(dir_out,%F));
         end
 
-        extract_cmd = extract_cmd + " -q """ + archive_in + """ -d """ + pathconvert(dir_out,%F) +"""";
-
+    else
+          ret = archiveExtract(archive_in,%t,dir_out);
     end
-
-    [rep,stat,err] = unix_g(extract_cmd);
-
-    if stat ~= 0 then
+    if ret<>0 then
         atomsError("error", ..
-        msprintf(gettext("%s: The extraction of the archive ''%s'' has failed.\n"), ..
+       msprintf(gettext("%s: The extraction of the archive ''%s'' has failed.\n"), ..
         "atomsExtract", ..
-        strsubst(archive_in,"\","\\") ));
+       strsubst(archive_in,"\","\\") )); 
     end
-
     // Get the list of directories after the extraction
     // =========================================================================