- Add some usefull functions
Pierre MARECHAL [Thu, 26 Mar 2009 14:31:37 +0000 (15:31 +0100)]
 - Add input parameter tests

14 files changed:
scilab/modules/atoms/macros/atomsCheck.sci
scilab/modules/atoms/macros/atomsDownloadPackage.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atomsInfo.sci
scilab/modules/atoms/macros/atomsInstall.sci
scilab/modules/atoms/macros/atomsUpdate.sci
scilab/modules/atoms/macros/atoms_internals/atomsConstant.sci
scilab/modules/atoms/macros/atoms_internals/atomsDlInstall.sci
scilab/modules/atoms/macros/atoms_internals/atomsGetDesc.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsGetMRVersion.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsGetTOOLBOXES.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsIsPackage.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsReadDesc.sci
scilab/modules/atoms/macros/atoms_internals/atomsReadDescFunctions.sci
scilab/modules/atoms/macros/atoms_internals/atomsReadTOOLBOXES.sci [new file with mode: 0644]

index 63431be..7ab12c9 100644 (file)
@@ -18,7 +18,7 @@ function result = atomsCheck(name)
 
   if rhs == 1 then
   // We remove the special characters
-  name = atomsSubstituteString(name)
+  name = atomsNormalizeName(name)
   // We go in the repectory with toolboxes
   rep = atomsToolboxDirectory()
   d = rep + name
diff --git a/scilab/modules/atoms/macros/atomsDownloadPackage.sci b/scilab/modules/atoms/macros/atomsDownloadPackage.sci
new file mode 100644 (file)
index 0000000..ca3fa7c
--- /dev/null
@@ -0,0 +1,144 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// End user function
+
+// Download packages and return the path of the downloaded files
+
+function result = atomsDownloadPackage(package_names,package_versions,allusers)
+       
+       result       = "";
+       
+       // Check input parameters
+       // =========================================================================
+       
+       rhs = argn(2);
+       
+       if rhs < 2 | rhs > 3 then
+               error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"atomsInstall",2,3))
+       end
+       
+       if type(package_names) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstall",1));
+       end
+       
+       if type(package_versions) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstall",2));
+       end
+       
+       // Install for all users or just for me ?
+       // =========================================================================
+       
+       if rhs == 1 then
+               // By default, install for all users (if we have write access of course !)
+               if atomsAUWriteAccess() then
+                       allusers = %T; 
+               else
+                       allusers = %F;
+               end
+       
+       else
+               // Just check if it's a boolean
+               if type(allusers) <> 4 then
+                       error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsInstall",2));
+               end
+               
+               // Check if we have the write access
+               if allusers & ~ atomsAUWriteAccess() then
+                       error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsInstall",2,pathconvert(SCI+"/.atoms")));
+               end
+       end
+       
+       // Manage download path
+       // =========================================================================
+       
+       if allusers then
+               download_path = pathconvert(SCI+"/.atoms");
+       else
+               download_path = pathconvert(SCIHOME+"/atoms");
+       end
+       
+       if ~ chdir(download_path) then
+               error(msprintf(gettext("%s: The directory %s is not accessible\n"),"atomsInstall",download_path));
+       end
+       
+       // Loop on packages
+       // =========================================================================
+       
+       for i=1:size(packages,"*")
+       end
+       
+
+       
+
+//     global conflictingList
+//     global conflictLocal
+//     global nomconflictLocal
+//     global conflictVersion
+// 
+//     rhs = argn(2)
+//     if (rhs == 2 | rhs == 1 | rhs == 3) then
+//     // We check if the arguments exist
+//     if rhs == 1
+//             checkVersionScilab = %t
+//     end
+//     if rhs <= 2
+//             version = ""
+//     end
+//     // We remove the special characters
+//     name = atomsNormalizeName(name)
+//     // We go to the dedicated directory
+//     rep = atomsToolboxDirectory()
+//     cd (rep)
+//     // Required to empty the global variables before any use of atomsCheckConflict
+//     clearglobal conflictingList
+//     clearglobal conflictLocal
+//     clearglobal nomconflictLocal
+//     clearglobal conflictVersion
+//     // Retrieve of the list of toolboxes to install
+//     listTool = atomsCheckConflict(name, version, checkVersionScilab)
+//     // If there is an empty line, it is because a dependency is missing
+//     if find(listTool == "") <> []
+//             if conflictLocal == 1
+//             atomsDisplayMessage(sprintf(_("The Toolbox version %s locally present doesn''t match. Update it.\n"),nomconflictLocal))
+//             elseif listTool <> ""
+//             atomsDisplayMessage(_("Impossible to install all the dependencies.\n"))
+//             end
+//             result =  %f
+//             return result
+//     elseif conflictVersion == 1
+//             atomsDisplayMessage(sprintf(_("Conflit of version for %s"),nomconflictLocal))
+//             result =  %f
+//             return result
+//     end
+//     // Retrieve of the toolboxes list which are already in local
+//     cd (rep)
+//     listLocal = ls()
+//     // Treatment of the toolboxes to install
+//     [m, n] = size(listTool)
+//     for i=1:m
+//             [name, version] = atomsSeparateVersionDep(listTool(i))
+//             // If it is locally present, we pass to the following one
+//             if find(listLocal == name) <> []
+//             continue
+//             else
+//             atomsDisplayMessage(_("Is going to be install: ") + name)
+//             if ~atomsDlInstall(name, version)
+//                     disp(_("Error during the installation"))
+//                     result = %f
+//                     return result
+//             end
+//             end
+//     end
+//     result = %t
+//     return result
+
+
+
+endfunction
index 9925bb9..baec9d2 100644 (file)
 
 // Display of the toolbox information
 
-function atomsInfo(name)
+function atomsInfo(name,version)
 
-       rhs=argn(2);
+       rhs = argn(2);
        
-       if rhs <> 1 then
-               error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"atomsInfo",1));
+       if rhs < 1 | rhs > 2 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsInfo",1,2));
        end
        
        // we remove the special characters
-       normalized_name = atomsSubstituteString(name)
+       normalized_name = atomsNormalizeName(name);
        
        // We try to find the information locally
        // =========================================================================
index 5184b23..caf1553 100644 (file)
@@ -1,6 +1,4 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2008 - INRIA - Delphine GASC <delphine.gasc@scilab.org>
-// Copyright (C) 2009 - DIGITEO - Sylvestre LEDRU <sylvestre.ledru@scilab.org>
 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
 //
 // This file must be used under the terms of the CeCILL.
 
 // Installation of a toolbox
 
-function result = atomsInstall(name, checkVersionScilab, version)
-  global conflictingList
-  global conflictLocal
-  global nomconflictLocal
-  global conflictVersion
-  rhs = argn(2)
-  if (rhs == 2 | rhs == 1 | rhs == 3) then
-  // We check if the arguments exist
-  if rhs == 1
-    checkVersionScilab = %t
-  end
-  if rhs <= 2
-    version = ""
-  end
-  // We remove the special characters
-  name = atomsSubstituteString(name)
-  // We go to the dedicated directory
-  rep = atomsToolboxDirectory()
-  cd (rep)
-  // Required to empty the global variables before any use of atomsCheckConflict
-  clearglobal conflictingList
-  clearglobal conflictLocal
-  clearglobal nomconflictLocal
-  clearglobal conflictVersion
-  // Retrieve of the list of toolboxes to install
-  listTool = atomsCheckConflict(name, version, checkVersionScilab)
-  // If there is an empty line, it is because a dependency is missing
-  if find(listTool == "") <> []
-    if conflictLocal == 1
-      atomsDisplayMessage(sprintf(_("The Toolbox version %s locally present doesn''t match. Update it.\n"),nomconflictLocal))
-    elseif listTool <> ""
-      atomsDisplayMessage(_("Impossible to install all the dependencies.\n"))
-    end
-    result =  %f
-    return result
-  elseif conflictVersion == 1
-    atomsDisplayMessage(sprintf(_("Conflit of version for %s"),nomconflictLocal))
-    result =  %f
-    return result
-  end
-  // Retrieve of the toolboxes list which are already in local
-  cd (rep)
-  listLocal = ls()
-  // Treatment of the toolboxes to install
-  [m, n] = size(listTool)
-  for i=1:m
-    [name, version] = atomsSeparateVersionDep(listTool(i))
-    // If it is locally present, we pass to the following one
-    if find(listLocal == name) <> []
-      continue
-    else
-      atomsDisplayMessage(_("Is going to be install: ") + name)
-      if ~atomsDlInstall(name, version)
-        disp(_("Error during the installation"))
-        result = %f
-        return result
-      end
-    end
-  end
-  result = %t
-  return result
+function result = atomsInstall(packages,allusers)
+       
+       result = %F;
+       
+       // Check input parameters
+       // =========================================================================
+       
+       rhs = argn(2);
+       
+       if rhs < 1 | rhs > 2 then
+               error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"atomsInstall",1,2))
+       end
+       
+       if type(packages) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstall",1));
+       end
+       
+       packages = stripblanks(packages);
+       
+       // Install for all users or just for me ?
+       // =========================================================================
+       
+       if rhs == 1 then
+               // By default, install for all users (if we have write access of course !)
+               if atomsAUWriteAccess() then
+                       allusers = %T; 
+               else
+                       allusers = %F;
+               end
+       
+       else
+               // Just check if it's a boolean
+               if type(allusers) <> 4 then
+                       error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsInstall",2));
+               end
+               
+               // Check if we have the write access
+               if allusers & ~ atomsAUWriteAccess() then
+                       error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsInstall",2,pathconvert(SCI+"/.atoms")));
+               end
+       end
+       
+       // We are installing new package, so we have a net connection
+       // => update the package list
+       // =========================================================================
+       
+       atomsGetTOOLBOXES(%T);
+       
+       // Loop on packages
+       // =========================================================================
+       
+       for i=1:size(packages,"*")
+               
+               package = packages(i);
+               
+               if size(regexp(package,"/\s/") ,"*" ) > 1 then
+                       error(msprintf(gettext("%s: Wrong value for input argument #%d: it must contain at most one space.\n"),"atomsInstall",1));
+               end
+               
+               if size(regexp(package,"/\s/") ,"*" ) == 0 then
+                       // install the most recent version of the package
+                       name    = package;
+                       version = "0";
+               else
+                       // A version is specified
+                       space = regexp(package,"/\s/");
+                       name  = part(package,[1:space-1]);
+                       version = part(package,[space+1:length(package)]);
+               end
+               
+               package_names(i)    = name;
+               package_versions(i) = version;
+               
+               // Ok, The syntax is correct, Now check if it's a valid package
+               
+               if ~ atomsIsPackage(package_names(i),package_versions(i)) then
+                       if package_versions(i) == "0" then
+                               package_full_name = package_names(i);
+                       else
+                               package_full_name = package_names(i)+" - "+package_versions(i);
+                       end
+                       error(msprintf(gettext("%s: The package %s is not available.\n"),"atomsInstall",1,package_full_name));
+               end
+               
+               // Get the package version is not specified, get the most recent version
+               if package_versions(i) == "0" then
+                       package_versions(i) = atomsGetMRVersion(package_names(i));
+               end
+               
+       end
+       
+
+       
+
+//     global conflictingList
+//     global conflictLocal
+//     global nomconflictLocal
+//     global conflictVersion
+// 
+//     rhs = argn(2)
+//     if (rhs == 2 | rhs == 1 | rhs == 3) then
+//     // We check if the arguments exist
+//     if rhs == 1
+//             checkVersionScilab = %t
+//     end
+//     if rhs <= 2
+//             version = ""
+//     end
+//     // We remove the special characters
+//     name = atomsNormalizeName(name)
+//     // We go to the dedicated directory
+//     rep = atomsToolboxDirectory()
+//     cd (rep)
+//     // Required to empty the global variables before any use of atomsCheckConflict
+//     clearglobal conflictingList
+//     clearglobal conflictLocal
+//     clearglobal nomconflictLocal
+//     clearglobal conflictVersion
+//     // Retrieve of the list of toolboxes to install
+//     listTool = atomsCheckConflict(name, version, checkVersionScilab)
+//     // If there is an empty line, it is because a dependency is missing
+//     if find(listTool == "") <> []
+//             if conflictLocal == 1
+//             atomsDisplayMessage(sprintf(_("The Toolbox version %s locally present doesn''t match. Update it.\n"),nomconflictLocal))
+//             elseif listTool <> ""
+//             atomsDisplayMessage(_("Impossible to install all the dependencies.\n"))
+//             end
+//             result =  %f
+//             return result
+//     elseif conflictVersion == 1
+//             atomsDisplayMessage(sprintf(_("Conflit of version for %s"),nomconflictLocal))
+//             result =  %f
+//             return result
+//     end
+//     // Retrieve of the toolboxes list which are already in local
+//     cd (rep)
+//     listLocal = ls()
+//     // Treatment of the toolboxes to install
+//     [m, n] = size(listTool)
+//     for i=1:m
+//             [name, version] = atomsSeparateVersionDep(listTool(i))
+//             // If it is locally present, we pass to the following one
+//             if find(listLocal == name) <> []
+//             continue
+//             else
+//             atomsDisplayMessage(_("Is going to be install: ") + name)
+//             if ~atomsDlInstall(name, version)
+//                     disp(_("Error during the installation"))
+//                     result = %f
+//                     return result
+//             end
+//             end
+//     end
+//     result = %t
+//     return result
+
 
-  else
-    error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"atomsInstall",1,3))
-  end
 
 endfunction
index 4a1602f..92895a6 100644 (file)
@@ -29,7 +29,7 @@ function result = atomsUpdate(name,checkVersionScilab)
        end
        
        // We remove special characters
-       normalized_name = atomsSubstituteString(name)
+       normalized_name = atomsNormalizeName(name)
        
        // if name = "all" we update all the Toolboxes
        // =========================================================================
index 4f56313..fa713d7 100644 (file)
@@ -14,9 +14,9 @@
 // Recup of the basics informations
 
 // Fields present in the DESCRIPTION file
-function [listeObl, listeOpt] = atomsConstant()
+function [mandatory, optional] = atomsConstant()
   // Compulsory field
-  listeObl = ["Toolbox","Version","Title","Author","Maintainer","Description","License","Category","ScilabVersion"]
+  mandatory = ["Toolbox","Version","Title","Author","Maintainer","Description","License","Category","ScilabVersion"]
   // Optionnal field
-  listeOpt = ["Date","Depends","ExternalDepends","URL","Entity"]
+  optional = ["Date","Depends","ExternalDepends","URL","Entity"]
 endfunction
index 745c315..2ecf077 100644 (file)
@@ -18,7 +18,7 @@ function result = atomsDlInstall(nom, version)
   arch = nom + "." + version + ".tar.gz"
   // Download of the archive
   cd (rep)
-  listMirror = atomsToolboxMirror()
+  listMirror = atomsOfclRepositories()
   if dlArchive(listMirror, 1, arch)
     // Unzip
     if dezipp(arch)
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsGetDesc.sci b/scilab/modules/atoms/macros/atoms_internals/atomsGetDesc.sci
new file mode 100644 (file)
index 0000000..9effcff
--- /dev/null
@@ -0,0 +1,133 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - INRIA - Delphine GASC <delphine.gasc@scilab.org>
+// Copyright (C) 2009 - DIGITEO - Sylvestre LEDRU <sylvestre.ledru@scilab.org>
+// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// Internal function
+
+// Get the Full Description of a toolbox
+
+function description = atomsGetDesc(name)
+       
+       // Check input arguments
+       // =========================================================================
+       
+       rhs  = argn(2);
+       
+       if rhs <> 1 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"atomsGetDesc",1));
+       end
+       
+       if type(name) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsGetDesc",2));
+       end
+       
+       DESCRIPTION           = "";
+       DESCRIPTIONFUNCTIONS  = "";
+       
+       // First case, name = absolute/relative path of the DESCRIPTION file
+       if regexp(name,"/\/DESCRIPTION$/") <> [] then
+               if fileinfo(name) <> [] then
+                       DESCRIPTION = pathconvert(name,%f);
+               else
+                       error(msprintf(gettext("%s: The description file you''ve enterer as input argument (%s) doesn''t exist.\n"),"atomsGetDesc",name));
+               end
+       
+       // Second Case, name = absolute/relative path of the toolbox 
+       elseif isdir(name) then
+               check_file = pathconvert(name)+"DESCRIPTION";
+               if fileinfo(check_file) <> [] then
+                       DESCRIPTION = check_file;
+               end
+               
+       // third case, name = Just the name of the toobox, we have to search in the 
+       // atoms standard directory
+       else
+               atoms_directories = atomsToolboxDirectory();
+               
+               for k=1:size(atoms_directories,"*")
+                       check_file      = pathconvert(atoms_directories(k)+"/"+name)+"DESCRIPTION";
+                       if fileinfo(check_file) <> [] then
+                               DESCRIPTION = check_file;
+                               break;
+                       end
+               end
+               
+               // Fourth case, try to download the DESCRIPTION file
+               if DESCRIPTION == "" then
+                       DESCRIPTION = download_file(name,"DESCRIPTION");
+               end
+               
+       end
+       
+       // No DESCRIPTION file found
+       if DESCRIPTION == "" then
+               error(msprintf(gettext("%s: No DESCRIPTION file was found.\n"),"atomsGetDesc"));
+       end
+       
+       // Now check if the DESCRIPTION-FUNCTION exists
+       DESCRIPTIONFUNCTIONS = DESCRIPTION+"-FUNCTIONS";
+       
+       disp(DESCRIPTION);
+       
+       if fileinfo(DESCRIPTIONFUNCTIONS) == [] then
+               error(msprintf(gettext("%s: The DESCRIPTION-FUNCTIONS file was found.\n"),"atomsGetDesc"));
+       end
+       
+       // Creation the template of description hash
+       [mandatory,optional] = atomsConstant();
+       
+       for i=1:size(mandatory,"*")
+               description(mandatory(i))= []
+       end
+       
+       for i=1:size(optional,"*")
+               description(optional(i))= []
+       end
+       
+       // Filling of the hash table with the DESCRIPTION file information
+       description = atomsReadDesc(DESCRIPTION,description)
+       
+       // Filling of the hash table with the DESCRIPTION-FUNCTIONS file information 
+       description("Functions") = atomsReadDescFunctions(DESCRIPTIONFUNCTIONS);
+       
+endfunction
+
+// =============================================================================
+// result = download_file(toolboxname,filename)
+// Try to download the file (DESCRIPTION OR DESCRIPTION-FUNCTIONS) of the 
+// toolbox "toolboxname"
+//
+// if success : return the absolute path of the downloaded file
+// else : return an empty string
+//
+// Date : 20/03/2009
+// =============================================================================
+
+function result = download_file(toolboxname,filename)
+       
+       mirrors = atomsOfclRepositories();
+       result  = "";
+       
+       if ~isdir(pathconvert(TMPDIR+"/atoms")) then
+               mkdir(pathconvert(TMPDIR+"/atoms"));
+       end
+       
+       for i=1:size(mirrors,"*")
+               url            = mirrors(i)+"/"+toolboxname+"/"+filename;
+               file_out       = TMPDIR+"/atoms/"+filename;
+               [rep,stat,err] = unix_g("wget "+url + " -O " + file_out)
+               if stat == 0 then
+                       // Download successfull
+                       result = file_out;
+                       break;
+               end
+       end
+       
+endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsGetMRVersion.sci b/scilab/modules/atoms/macros/atoms_internals/atomsGetMRVersion.sci
new file mode 100644 (file)
index 0000000..3271e6b
--- /dev/null
@@ -0,0 +1,56 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// Internal function
+
+// Return the most recent version of each package specified as first input argument
+
+function versions = atomsGetMRVersion(packages)
+       
+       // Initialize
+       versions = [];
+       
+       // Check input parameters
+       // =========================================================================
+       
+       rhs  = argn(2);
+       
+       if rhs <> 1 then
+               error(msprintf(gettext("%s: Wrong number of input argument: at most %d expected.\n"),"atomsGetMRVersion",1));
+       end
+       
+       if type(packages) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsGetMRVersion",1));
+       end
+       
+       // Get all package description
+       // =========================================================================
+       
+       allpackages = atomsGetTOOLBOXES();
+       
+       // Loop on packages
+       // =========================================================================
+       
+       for i=1:size(packages,"*")
+               
+               versions(i) = "-1";
+               
+               if ~ isfield(allpackages,packages(i)) then
+                       continue;
+               end
+               
+               package_versions          = allpackages(packages(i));
+               package_versions_tab      = getfield(1,package_versions);
+               package_versions_tab(1:2) = [];
+               package_versions_tab      = gsort(package_versions_tab);
+               versions(i)               = package_versions_tab(1);
+               
+       end
+       
+endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsGetTOOLBOXES.sci b/scilab/modules/atoms/macros/atoms_internals/atomsGetTOOLBOXES.sci
new file mode 100644 (file)
index 0000000..8906a19
--- /dev/null
@@ -0,0 +1,88 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// Internal function
+
+// Return the full packages of the TOOLBOXES present in the differents repositories
+
+function packages = atomsGetTOOLBOXES(update)
+       
+       // Initialize
+       packages = struct();
+       
+       // Check input parameters
+       // =========================================================================
+       
+       rhs  = argn(2);
+       
+       if rhs > 1 then
+               error(msprintf(gettext("%s: Wrong number of input argument: at most %d expected.\n"),"atomsGetTOOLBOXES",1));
+       end
+       
+       if (rhs == 1) & (type(update) <> 4) then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsGetTOOLBOXES",1));
+       end
+       
+       // If necessary, loop on available mirrors and download TOOLBOXES files
+       
+       if (fileinfo(pathconvert(SCIHOME+"/.atoms/packages",%F)) == []) | (rhs == 1 & update) then
+               
+               nb_TOOLBOXES = 0;
+               TOOLBOXES    = []; // Liste des paths des fichiers TOOLBOXES
+               
+               mirrors = atomsRepositories();
+               
+               if ~isdir(pathconvert(TMPDIR+"/atoms")) then
+                       mkdir(pathconvert(TMPDIR+"/atoms"));
+               end
+               
+               for i=1:size(mirrors,"*")
+                       
+                       url            = mirrors(i)+"/TOOLBOXES";
+                       file_out       = pathconvert(TMPDIR+"/atoms/"+sprintf("TOOLBOXES_%d",nb_TOOLBOXES),%f);
+                       
+                       if( fileinfo(file_out) <> [] ) then
+                               mdelete(file_out);
+                       end
+                       
+                       [rep,stat,err] = unix_g("wget "+url + " -O " + file_out)
+                       if stat == 0 then
+                               // Download successfull
+                               nb_TOOLBOXES = nb_TOOLBOXES + 1;
+                               TOOLBOXES    = [ TOOLBOXES ; file_out ];
+                       else
+                               disp("wget "+url + " -O " + file_out);
+                               disp(err);
+                       end
+               end
+               
+               if nb_TOOLBOXES == 0 then
+                       error(msprintf(gettext("%s: Internal Error : No TOOLBOXES file has successfully been downloaded.\n"),"atomsGetTOOLBOXES"));
+               end
+               
+               for i=1:size(TOOLBOXES,"*")
+                       packages = atomsReadTOOLBOXES( TOOLBOXES(i) , packages );
+               end
+               
+               // Save the "packages" variable in a file
+               
+               if ~isdir(pathconvert(SCIHOME+"/.atoms")) then
+                       mkdir(pathconvert(SCIHOME+"/.atoms"));
+               end
+               
+               save(pathconvert(SCIHOME+"/.atoms/packages",%F),packages)
+               
+       else
+               
+               // Just load from file
+               load(pathconvert(SCIHOME+"/.atoms/packages",%F),"packages");
+
+       end
+       
+endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsIsPackage.sci b/scilab/modules/atoms/macros/atoms_internals/atomsIsPackage.sci
new file mode 100644 (file)
index 0000000..8575586
--- /dev/null
@@ -0,0 +1,75 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// Internal function
+
+// Return the most recent version of each package specified as first input argument
+
+function result = atomsIsPackage(package_names,package_versions)
+       
+       // Initialize
+       // =========================================================================
+       result = [];
+       
+       // Check input parameters
+       // =========================================================================
+       rhs  = argn(2);
+       
+       if rhs < 1 | rhs > 2 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsIsPackage",1,2));
+       end
+       
+       if type(package_names) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsIsPackage",1));
+       end
+       
+       if (rhs == 2) & type(package_versions) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsIsPackage",1));
+       end
+       
+       if (rhs == 2) & or( size(package_names) <> size(package_versions) ) then
+               error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"atomsIsPackage",1,2));
+       end
+       
+       // Get all package description
+       // =========================================================================
+       allpackages = atomsGetTOOLBOXES();
+       
+       // Loop on packages
+       // =========================================================================
+       
+       for i=1:size(package_names,"*")
+               
+               result(i) = %F;
+               
+               if rhs == 1 then
+                       version = "0";
+               else
+                       version = package_versions(i);
+               end
+               
+               // 1st case : just test the name, not the version
+               if version == "0" then
+                       if isfield(allpackages,package_names(i)) then
+                               result(i) = %T;
+                       end
+               
+               // 2nd case : Check a specific version
+               else
+                       if isfield(allpackages,package_names(i)) then
+                               this_package = allpackages(package_names(i));
+                               if isfield(this_package,version) then
+                                       result(i) = %T;
+                               end
+                       end
+               end
+               
+       end
+       
+endfunction
index d7fbb8e..04a7ae4 100644 (file)
@@ -1,6 +1,4 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2008 - INRIA - Delphine GASC <delphine.gasc@scilab.org>
-// Copyright (C) 2009 - DIGITEO - Sylvestre LEDRU <sylvestre.ledru@scilab.org>
 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
 //
 // This file must be used under the terms of the CeCILL.
 
 // Internal function
 
-// Parsing of the Description file
+// Parsing of the DESCRIPTION file
 
-function desc = atomsReadDesc(nom)
-  // We go to the directory with the toolboxes
-  rep = atomsToolboxDirectory()
-  d = rep + nom
-  // Support of the different OS 
-  if getos() == "Windows"
-    directory = d + "\DESCRIPTION"
-  else // linux and mac
-    directory = d + "/DESCRIPTION"
-  end
-  // If we find the repertory in local and the DESCRIPTION file is present
-  if (isdir(d) & ls(directory) <> [])
-    cd (d)
-    // Reading of the DESCRIPTION file which we stock in a array
-    tab = atomsReadFile("DESCRIPTION")
-    // Creation of a "hash table"
-    desc = atomsListDescription()
-    // Filling of the hash table
-    desc = hashTable(desc, tab)
-    // Treatment of the file name (special characteres) to insure the validity of the name file and the PATH 
-    desc("Toolbox") = atomsSubstituteString(desc("Toolbox"))
-    // We add the function field
-    clearglobal numberFunction
-    desc("Function") = atomsReadDescFunctions(nom)
-  // Else we search in the net
-  else
-       cd (rep)
-       // Creation of a "hash table"
-       desc = atomsListDescription()
-       // Sites list to cross
-       listMirror = atomsToolboxMirror()
-       [n, m] = size(listMirror)
-       clearglobal numberFunction
-       global numberFunction
-       numberFunction = 0
-       for i=1:m
-         // We recup the file in the net and we put a copy in the directory under the name TOOLBOXES
-         if dlFile(listMirror(i), "TOOLBOXES")
-        // Reading of the TOOLBOXES file which we stock in a array
-        tab = atomsReadFile("TOOLBOXES")
-        // We delete the temporary file created
-        if ~removeFile("TOOLBOXES")
-             disp(_("Please delete the file TOOLBOXES of your current directory"))
-           end
-        // We fill the array with the different toolboxes
-        desc = hashTable2(desc, tab)
-        // Treatment of the file name (special characteres) to insure the validity of the name file and the PATH 
-        [a, b] = size(desc("Toolbox"))
-        for j=1:a
-          desc("Toolbox")(j) = atomsSubstituteString(desc("Toolbox")(j))
-        end
-      else
-        result = %f
-        return result
-      end
-    end
-  end
-  result = %t
-  return result
-endfunction
+// =============================================================================
+// description_out = atomsReadDesc(file_in,description_in)
+// Parse a DESCRIPTION file
+// 
+// Date : 20/03/2009
+// =============================================================================
 
-// Retrieve of the file in the web
-function result = dlFile(web, fileWeb)
-       URL=web + "/TOOLBOXES";
-       [rep,stat,err] = unix_g("wget "+URL + " -O " + fileWeb)
-       // If the file is not present
-       if stat <> 0
-         atomsDisplayMessage(_("Please check the validity of the repository:"))
-         atomsDisplayMessage(sprintf(_("Download of ''%s'' failed"),URL))
-         if ~removeFile(fileWeb)
-           disp(sprintf(_("Please delete the file %s in your current repertory."),fileWeb))
-         end
-         result = %f
-         return result
+function description_out = atomsReadDesc(file_in,description_in)
+       
+       description_out = struct();
+       
+       rhs  = argn(2);
+       
+       if rhs < 1 | rhs > 2 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsReadDesc",1,2));
        end
-       result = %t
-       return result
-endfunction
-
-// Delete function of the file
-function result = removeFile(fileR)
-  result = deletefile(fileR)
-  return result
-endfunction
-
-// Easy filling of the hash table (DESCRIPTION file)
-function listDesc = hashTable(listDesc, tabDesc)
-  [listeObl, listeOpt] = atomsConstant()
-  // We create all the values for all the keys so that even if one optional field is not present in the array, there is no error.
-  [o, p] = size(listeOpt)
-  for i=1:p
-    listDesc(listeOpt(i))= ""
-  end
-  [n, m] = size(tabDesc)
-  for i=1:n
-    ind = strindex(tabDesc(i),':')
-    // If ind = [] we are always in the previous field
-    if ind == []
-      listDesc(temp(1)) = listDesc(temp(1)) + tabDesc(i)
-    else
-      // ind+1 to remove the space before the second field
-      temp = strsplit(tabDesc(i),ind+1)
-      // We remove the ": "
-      temp(1) = strsubst(temp(1), ": ", "")
-      listDesc(temp(1))= temp(2)
-    end
-  end
-endfunction
-
-// Filling of the hash table (TOOLBOX file)
-function listDesc = hashTable2(listDesc, tabDesc)
-  global numberFunction
-  [listeObl, listeOpt] = atomsConstant()
-  [n, m] = size(tabDesc)
-  [nbTool, m] = size(listDesc("Toolbox"))
-  [o, p] = size(listeOpt)
-  inFunct = %f
-  for i=1:n
-    // We create a flag to know if we are in the function part
-    if tabDesc(i) == "--"
-      inFunct = %t
-    elseif tabDesc(i) == "//"
-      inFunct = %f
-    end
-    if tabDesc(i) <> "//" & ~inFunct
-      ind = strindex(tabDesc(i),':')
-      // ind+1 to remove the space before the second field
-      temp = strsplit(tabDesc(i),ind+1)
-      // We remove the ": "
-      temp(1) = strsubst(temp(1), ": ", "")
-      listDesc(temp(1))(nbTool+1)= temp(2)
-    elseif tabDesc(i) == "--"
-      clear tmp
-      nbFunct = 0
-    elseif tabDesc(i) <> "--" & inFunct
-      ind = strindex(tabDesc(i),'-')
-      // If ind = [] we are always in the previous field
-      if ind == []
-        tmp(string(nbFunct)) = tmp(string(nbFunct)) + tabDesc(i)
-      else
-        nbFunct = nbFunct + 1
-        tmp(string(nbFunct)) = tabDesc(i)
-        if numberFunction < nbFunct
-          numberFunction = nbFunct
-        end
-      end
-    elseif tabDesc(i) == "//"
-      // If a toolbox doesn't have functions, to avoid the bug : "Undefined variable: tmp"
-      if isdef("tmp")
-        listDesc("Function")(nbTool+1)= tmp
-      end
-      // We create all the values for all the keys so that even if one optional field is not present in the array, there is no error
-      // But only if the // is followed by other things
-      if i <> n
-        for j=1:p
-          listDesc(listeOpt(j))(nbTool+2) = ""
-        end
-      end
-      nbTool=nbTool+1
-    end
-  end
+       
+       if regexp( file_in,"/DESCRIPTION$/") == [] then
+               error(msprintf(gettext("%s: Wrong value for input argument #%d: A string that end with DESCRIPTION expected.\n"),"atomsReadDesc",1));
+       end
+       
+       if rhs==2 & type(description_in)<>17 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: mlist expected.\n"),"atomsReadDesc",2));
+       end
+       
+       if rhs==2 then
+               description_out = description_in;
+       end
+       
+       tabDesc         = mgetl(file_in);
+       current_field   = "";
+       
+       for i=1:size(tabDesc,"*")
+               
+               // First case : new field
+               if regexp(tabDesc(i),"/^[a-zA-Z0-9]*:\s/","o") == 1 then
+                       current_field_length    = regexp(tabDesc(i),"/:\s/","o")
+                       current_field           = part(tabDesc(i),1:current_field_length-1);
+                       current_value           = part(tabDesc(i),current_field_length+2:length(tabDesc(i)));
+                       description_out(current_field) = current_value;
+                       continue;
+               end
+               
+               // Second case : Current field continuation
+               if regexp(tabDesc(i),"/^\s/","o") == 1 then
+                       current_value = part(tabDesc(i),2:length(tabDesc(i)));
+                       description_out(current_field) = [ description_out(current_field) ; current_value ];
+                       continue;
+               end
+               
+               // Third case : Blank line
+               if length(tabDesc(i)) == 0 then
+                       continue;
+               end
+               
+               // Else Error
+               error(msprintf(gettext("%s: The description is not well formated at line %d\n"),"atomsReadDesc",i));
+               
+       end
+       
 endfunction
index d361ed0..8b1847c 100644 (file)
@@ -1,6 +1,4 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2008 - INRIA - Delphine GASC <delphine.gasc@scilab.org>
-// Copyright (C) 2009 - DIGITEO - Sylvestre LEDRU <sylvestre.ledru@scilab.org>
 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
 //
 // This file must be used under the terms of the CeCILL.
 
 // Parsing of the Description-Function file
 
-function descFunct = atomsReadDescFunctions(nom)
-  global numberFunction
-  rep = atomsToolboxDirectory()
-  d = rep + nom
-  // Support of the different OS 
-  if getos() == "Windows"
-    directory = d + "\DESCRIPTION-FUNCTIONS"
-  else // linux and mac
-    directory = d + "/DESCRIPTION-FUNCTIONS"
-  end
-  // If we find the local directory and the DESCRIPTION-FUNCTIONS file is present
-  if (isdir(d) & ls(directory) <> [])
-    cd (d)
-    // Reading of thedescription file which we store in a array
-    tab = atomsReadFile("DESCRIPTION-FUNCTIONS")
-    // Creation of a liste
-    [n, m] = size(tab)
-    numberFunction = 0
-    for i=1:n
-      ind = strindex(tab(i),'-')
-      // If ind = [] we are always in the previous field
-      if ind == []
-        descFunct(string(numberFunction)) = descFunct(string(numberFunction)) + tab(i)
-      else
-        numberFunction = numberFunction + 1
-        descFunct(string(numberFunction)) = tab(i)
-      end
-    end
-  else
-    atomsDisplayMessage(sprintf(_("The DESCRIPTION-FUNCTIONS file of the toolbox %s is missing"),nom))
-    descFunct = ""
-  end
-  return descFunct
+function descriptionFunctions = atomsReadDescFunctions(name)
+       
+       rhs  = argn(2);
+       
+       if rhs <> 1 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"atomsReadDescFunctions",1));
+       end
+       
+       DESCRIPTIONFUNCTIONS  = "";
+       
+       // First case, name = absolute/relative path of the DESCRIPTION-FUNCTIONS file
+       if regexp(name,"/\/DESCRIPTION-FUNCTIONS$/") <> [] then
+               if fileinfo(name) <> [] then
+                       DESCRIPTIONFUNCTIONS = pathconvert(name,%f);
+               else
+                       error(msprintf(gettext("%s: The description file you''ve enterer as input argument (%s) doesn''t exist.\n"),"atomsReadDescFunctions",name));
+               end
+       
+       // Second Case, name = absolute/relative path of the toolbox 
+       elseif isdir(name) then
+               check_file = pathconvert(name)+"DESCRIPTION-FUNCTIONS";
+               if fileinfo(check_file) <> [] then
+                       DESCRIPTIONFUNCTIONS = check_file;
+               end
+               
+       // third case, name = Just the name of the toobox, we have to search in the 
+       // atoms standard directory
+       else
+               atoms_directories = atomsToolboxDirectory();
+               
+               for k=1:size(atoms_directories,"*")
+                       check_file      = pathconvert(atoms_directories(k)+"/"+name)+"DESCRIPTION-FUNCTIONS";
+                       if fileinfo(check_file) <> [] then
+                               DESCRIPTIONFUNCTIONS = check_file;
+                               break;
+                       end
+               end
+               
+       end
+       
+       descriptionFunctions = dfTohash(DESCRIPTIONFUNCTIONS);
+       
+endfunction
+
+// =============================================================================
+// description_out = dfTohash(file_in,description_in)
+// Easy filling of the hash table (DESCRIPTION-FUNCTIONS file)
+// 
+// Date : 20/03/2009
+// =============================================================================
+
+function description_out = dfTohash(file_in)
+       
+       tabDesc         = mgetl(file_in);
+       current_field   = "";
+       
+       for i=1:size(tabDesc,"*")
+               
+               // First case : new field
+               if regexp(tabDesc(i),"/^[a-zA-Z0-9_]*\s-\s/","o") == 1 then
+                       current_field_length    = regexp(tabDesc(i),"/\s-\s/","o")
+                       current_field           = part(tabDesc(i),1:current_field_length-1);
+                       current_value           = part(tabDesc(i),current_field_length+3:length(tabDesc(i)));
+                       description_out(current_field) = current_value;
+                       continue;
+               end
+               
+               // Second case : Current field continuation
+               if regexp(tabDesc(i),"/^\s/","o") == 1 then
+                       current_value = part(tabDesc(i),2:length(tabDesc(i)));
+                       description_out(current_field) = [ description_out(current_field) ; current_value ];
+                       continue;
+               end
+               
+               // Third case : Blank line
+               if length(tabDesc(i)) == 0 then
+                       continue;
+               end
+               
+               // Else Error
+               error(msprintf(gettext("%s: The DESCRIPTION-FUNCTIONS file is not well formated at line %d\n"),"atomsReadDescFunctions",i));
+               
+       end
+       
 endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsReadTOOLBOXES.sci b/scilab/modules/atoms/macros/atoms_internals/atomsReadTOOLBOXES.sci
new file mode 100644 (file)
index 0000000..2b53c1e
--- /dev/null
@@ -0,0 +1,96 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// Internal function
+
+// Return the full description of the TOOLBOXES present in the differents repositories
+
+function description_out = atomsReadTOOLBOXES(file_in,description_in)
+       
+       description_out = struct();
+       
+       rhs  = argn(2);
+       
+       if rhs < 1 | rhs > 2 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsReadTOOLBOXES",1,2));
+       end
+       
+       if regexp( file_in,"/TOOLBOXES/") == [] then
+               error(msprintf(gettext("%s: Wrong value for input argument #%d: A string that contain TOOLBOXES expected.\n"),"atomsReadTOOLBOXES",1));
+       end
+       
+       if rhs==2 & type(description_in)<>17 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: mlist expected.\n"),"atomsReadTOOLBOXES",2));
+       end
+       
+       if rhs==2 then
+               description_out = description_in;
+       end
+       
+       TOOLBOXES        = mgetl(file_in);
+       
+       current_toolbox  = struct();
+       current_field    = "";
+       
+       for i=1:size(TOOLBOXES,"*")
+               
+               // First case : new field
+               if regexp(TOOLBOXES(i),"/^[a-zA-Z0-9]*:\s/","o") == 1 then
+                       
+                       // Start new version of toolbox
+                       if regexp(TOOLBOXES(i),"/^Toolbox:\s/","o") == 1 then
+                               
+                               if and(isfield(current_toolbox,["Toolbox";"Version"])) then
+                                       
+                                       if  ~ isfield(description_out,current_toolbox("Toolbox")) then
+                                               // Il s'agit de la première version de la toolbox trouvée
+                                               this_toolbox = struct();
+                                       else
+                                               // On récupère la liste des versions de cette toolbox
+                                               this_toolbox = description_out(current_toolbox("Toolbox"));
+                                       end
+                                       
+                                       this_toolbox(current_toolbox("Version")) = current_toolbox;
+                                       description_out(current_toolbox("Toolbox")) = this_toolbox;
+                               end
+                               
+                               // Reset the current_toolbox struct
+                               current_toolbox  = struct();
+                       end
+                       
+                       // process field
+                       current_field_length           = regexp(TOOLBOXES(i),"/:\s/","o")
+                       current_field                  = part(TOOLBOXES(i),1:current_field_length-1);
+                       current_value                  = part(TOOLBOXES(i),current_field_length+2:length(TOOLBOXES(i)));
+                       current_toolbox(current_field) = current_value;
+                       continue;
+               end
+               
+               // Second case : Current field continuation
+               if regexp(TOOLBOXES(i),"/^\s/","o") == 1 then
+                       current_value = part(TOOLBOXES(i),2:length(TOOLBOXES(i)));
+                       current_toolbox(current_field) = [ current_toolbox(current_field) ; current_value ];
+                       continue;
+               end
+               
+               // Third case : Blank line
+               if length(TOOLBOXES(i)) == 0 then
+                       continue;
+               end
+               
+               // Fourth case : Delimiter
+               if regexp(TOOLBOXES(i),"/^\/\//","o") == 1 then
+                       continue;
+               end
+               
+               // Else Error
+               error(msprintf(gettext("%s: The TOOLBOXES file ("+file_in+") is not well formated at line %d\n"),"atomsReadTOOLBOXES",i));
+       end
+       
+endfunction