Atoms 0.2
Pierre MARECHAL [Sat, 6 Jun 2009 15:21:29 +0000 (17:21 +0200)]
21 files changed:
scilab/modules/atoms/macros/atomsDependencyTree.sci [deleted file]
scilab/modules/atoms/macros/atomsGetInstalled.sci
scilab/modules/atoms/macros/atomsInstall.sci
scilab/modules/atoms/macros/atomsIsInstalled.sci
scilab/modules/atoms/macros/atomsUninstall.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsAUWriteAccess.sci
scilab/modules/atoms/macros/atoms_internals/atomsCatTree.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsCompatibleVersions.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsDependencyTree.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsGetDepChilds.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsGetDepParents.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsGetInstalledDetails.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsGetInstalledStatus.sci [new file with mode: 0644]
scilab/modules/atoms/macros/atoms_internals/atomsGetInstalledVers.sci
scilab/modules/atoms/macros/atoms_internals/atomsGetTOOLBOXES.sci
scilab/modules/atoms/macros/atoms_internals/atomsInstallRegister.sci
scilab/modules/atoms/macros/atoms_internals/atomsInstallUnregister.sci
scilab/modules/atoms/macros/atoms_internals/atomsIsPackage.sci
scilab/modules/atoms/macros/atoms_internals/atomsToolboxDetails.sci
scilab/modules/atoms/tests/unit_tests/atomsIsInstalled.tst [new file with mode: 0644]
scilab/modules/atoms/tests/unit_tests/atomsVersionCompare.tst [new file with mode: 0644]

diff --git a/scilab/modules/atoms/macros/atomsDependencyTree.sci b/scilab/modules/atoms/macros/atomsDependencyTree.sci
deleted file mode 100644 (file)
index ce69654..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-// 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
-
-function tree_out = atomsDependencyTree(name,version,tree_in)
-       
-       rhs = argn(2);
-       
-       // Check number of input arguments
-       // =========================================================================
-       
-       if (rhs < 2) | (rhs > 3) then
-               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsDependencyTree",2,3));
-       end
-       
-       // Check input parameters type
-       // =========================================================================
-       
-       if type(name) <> 10 then
-               error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsDependencyTree",1));
-       end
-       
-       if type(version) <> 10 then
-               error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsDependencyTree",2));
-       end
-       
-       if (rhs==3) & (type(tree_in) <> 17) then
-               error(msprintf(gettext("%s: Wrong type for input argument #%d: matrix oriented typed list expected.\n"),"atomsDependencyTree",3));
-       end
-       
-       // Check input parameters dimensions
-       // =========================================================================
-       
-       if size(name) <> 1 then
-               error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsDependencyTree",1));
-       end
-       
-       if size(version) <> 1 then
-               error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsDependencyTree",2));
-       end
-       
-       // Define tree_in if not defined as input argument
-       // =========================================================================
-       
-       if rhs<3 then
-               tree_in = struct();
-       end
-       
-       // Get dependencies of this toolbox
-       // =========================================================================
-       
-       this_package_details = atomsToolboxDetails(name,version);
-       
-       // Check if the wanted version is compatible with the current scilab version.
-       // =========================================================================
-       
-       this_package_details = atomsToolboxDetails(name,version);
-       
-       if ~ atomsIsCompatible(this_package_details("ScilabVersion")) then
-               tree_out = %F;
-               return tree_out;
-       end
-       
-       tree_out(name) = version;
-       
-       // Now, loop on dependencies
-       // =========================================================================
-       
-       if isfield(this_package_details,"Depends") & (this_package_details("Depends") ~= "") then
-               dependencies = this_package_details("Depends");
-       else
-               dependencies = [];
-       end
-       
-       for i=1:size(dependencies,"*")
-               
-               this_dependency_success = %F;
-               
-               // Split dependencies to get 
-               //  - direction ("=", ">=", "<=", "~")
-               //  - dependence name
-               //  - dependence version (optional)
-               
-               this_dependency_tab     = stripblanks(strsplit(dependencies(i),regexp(stripblanks(dependencies(i)),"/\s/")));
-               
-               this_dependency_dir     = this_dependency_tab(1);
-               this_dependency_name    = this_dependency_tab(2);
-               this_dependency_version = this_dependency_tab(3);
-               
-               // List versions of the dependency we can test
-               
-               if this_dependency_dir     == "="  then
-                       this_dependency_list = this_dependency_version;
-               
-               elseif this_dependency_dir == "~"  then
-                       this_dependency_list = atomsGetVersions(this_dependency_name);
-               
-               elseif this_dependency_dir == ">=" then
-                       this_dependency_list = atomsGetVersions(this_dependency_name,this_dependency_version);
-                       
-               elseif this_dependency_dir == "<=" then
-                       this_dependency_list = atomsGetVersions(this_dependency_name,"",this_dependency_version);
-                       
-               end
-               
-               for j=1:size(this_dependency_list,"*")
-                       
-                       tree = atomsDependencyTree(this_dependency_name,this_dependency_list(j),tree_out);
-                       
-                       // Dependency Tree fails
-                       
-                       if (type(tree) == 4) & (~ tree) then
-                               continue;
-                       end
-                       
-                       // Dependency Tree OK
-                       
-                       if type(tree) == 17 then
-                               tree_out = atomsCatTree(tree_out,tree);
-                               this_dependency_success = %T;
-                               break;
-                       end
-                       
-               end
-               
-               if ~  this_dependency_success then
-                       tree_out = %F;
-                       return;
-               end
-               
-       end
-       
-endfunction
-
-// =============================================================================
-// tree_out = atomsCatTree( tree_in_1 , tree_in_2 )
-//
-// Date : 19/05/2009
-// =============================================================================
-
-function tree_out = atomsCatTree( tree_in_1 , tree_in_2 )
-       
-       rhs = argn(2);
-       
-       // Check number of input arguments
-       // =========================================================================
-       
-       if rhs <> 2 then
-               error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"atomsMergeTree",1));
-       end
-       
-       // Check input arguments type
-       // =========================================================================
-       
-       if type(tree_in_1) <> 17 then
-               error(msprintf(gettext("%s: Wrong type for input argument #%d: matrix oriented typed list expected.\n"),"atomsMergeTree",1));
-       end
-       
-       if type(tree_in_2) <> 17 then
-               error(msprintf(gettext("%s: Wrong type for input argument #%d: matrix oriented typed list expected.\n"),"atomsMergeTree",2));
-       end
-       
-       // tree_in_1 is the master tree :
-       // =========================================================================
-       
-       tree_out  = tree_in_1;
-       
-       // Loop on tree_in_2 fields
-       // =========================================================================
-       
-       fields = getfield(1,tree_in_2);
-       fields(1:2) = [];
-       
-       for i=1:size(fields,"*")
-               if ~ isfield(tree_out,fields(i)) then
-                       tree_out(fields(i)) = tree_in_2(fields(i));
-               end
-       end
-       
-endfunction
index f003086..0ca5884 100644 (file)
@@ -9,6 +9,14 @@
 
 // End user function
 
+// Return a 4xn string matrix :
+// 
+// !toolbox2          0.1  user     /home/pmarecha/.Scilab/scilab-branch-atoms/atoms/contrib/toolbox2/0.1  A  !
+// !                                                                                                          !
+// !toolbox2          0.2  user     /home/pmarecha/.Scilab/scilab-branch-atoms/atoms/contrib/toolbox2/0.2  A  !
+// !                                                                                                          !
+// !toolbox_skeleton  1.3  alluser  /home/pmarecha/work/atoms/scilab/contrib/toolbox_skeleton/1.3          I  !
+
 function packages = atomsGetInstalled(allusers)
        
        rhs      = argn(2);
@@ -58,19 +66,21 @@ function packages = atomsGetInstalled(allusers)
                
                // Loop on each URL specified as first input argument
                for j=1:size(installed,"*")
+            current_status       = part(installed(j),1:1);
+            installed(j)         = part(installed(j),5:length(installed(j)));
                        current_name_length  = regexp(installed(j),"/\s-\s/","o");
                        current_name         = part(installed(j),1:current_name_length-1);
                        current_version      = part(installed(j),current_name_length+3:length(installed(j)));
                        
                        if installed_files(i,2) == "user" then
                                // user
-                               current_path  = pathconvert(SCIHOME+"/atoms/contrib/"+current_name+"/"+current_version,%F); 
+                               current_path  = pathconvert(SCIHOME+"/atoms/"+current_name+"/"+current_version,%F); 
                        else
                                // all users
                                current_path = pathconvert(SCI+"/contrib/"+current_name+"/"+current_version,%F);
                        end
                        
-                       packages = [ packages ; current_name current_version installed_files(i,2) current_path];
+                       packages = [ packages ; current_name current_version installed_files(i,2) current_path current_status];
                end
        end
        
index f6b35d6..249ba8f 100644 (file)
@@ -34,6 +34,26 @@ function result = atomsInstall(packages,allusers)
        
        packages = stripblanks(packages);
        
+       // Operating system detection
+       // =========================================================================
+       
+       if ~MSDOS then
+               OSNAME = unix_g('uname');
+               MACOSX = (strcmpi(OSNAME,"darwin") == 0);
+               LINUX  = (strcmpi(OSNAME,"linux") == 0);
+       else
+               MACOSX = %F;
+               LINUX  = %F;
+       end
+       
+       if MSDOS then
+               OSNAME = "windows";
+       elseif LINUX then
+               OSNAME = "linux";
+       elseif MACOSX then
+               OSNAME = "macosx";
+       end
+       
        // Install for all users or just for me ?
        // =========================================================================
        
@@ -63,15 +83,11 @@ function result = atomsInstall(packages,allusers)
        
        atomsGetTOOLBOXES(%T);
        
-       // Loop on packages and get the following informations :
-       // - package name
-       // - package version
-       // - status
-       //  + Update
-       //  + New Installation
-       //  + The most recent version is already installed
+       // Loop on packages and to build the dependency tree
        // =========================================================================
        
+       dependency_tree = struct();
+       
        for i=1:size(packages,"*")
                
                package = packages(i);
@@ -82,22 +98,18 @@ function result = atomsInstall(packages,allusers)
                
                if size(regexp(package,"/\s/") ,"*" ) == 0 then
                        // install the most recent version of the package
-                       name    = package;
-                       version = "0";
+                       package_names(i)    = package;
+                       package_versions(i) = "";
                else
                        // A version is specified
-                       space   = regexp(package,"/\s/");
-                       name    = part(package,[1:space-1]);
-                       version = part(package,[space+1:length(package)]);
+                       space               = regexp(package,"/\s/");
+                       package_names(i)    = part(package,[1:space-1]);
+                       package_versions(i) = 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
+                       if isempty(package_versions(i)) then
                                package_full_name = package_names(i);
                        else
                                package_full_name = package_names(i)+" - "+package_versions(i);
@@ -105,102 +117,204 @@ function result = atomsInstall(packages,allusers)
                        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));
+               // Build the depencency tree
+               tree = atomsDependencyTree(package_names(i),package_versions(i));
+               
+               if (type(dependency_tree) == 4) & (~ dependency_tree) then
+                       error(msprintf(gettext("%s: The dependency tree cannot be resolved.\n"),"atomsInstall",1));
+               end
+               
+               // Concatenate the tree with the existing one
+               dependency_tree = atomsCatTree( dependency_tree , tree );
+               
+       end
+       
+       // Now we have the list of package that have to be installed
+       // We have to check if
+       //  - each package is already installed
+       //  - If yes, Is it the most recent version
+       // =========================================================================
+       
+       mandatory_packages      = getfield(1,dependency_tree);
+       mandatory_packages(1:2) = [];
+       
+       for i=1:size(mandatory_packages,"*")
+               
+               this_package_details = dependency_tree(mandatory_packages(i));
+               
+               this_package_name    = this_package_details("Toolbox");
+               this_package_version = this_package_details("Version");
+               
+               this_package_details("to_install") = %F; 
+               
+               if atomsIsInstalled(this_package_name) then
+                       vers = atomsGetInstalledVers(mandatory_packages(i));
+                       if atomsVersionCompare( vers(1) , this_package_version ) < 0 then
+                               this_package_details("to_install") = %T;
+                       end
+               else
+                       this_package_details("to_install") = %T;
+               end
+               
+               dependency_tree(mandatory_packages(i)) = this_package_details;
+               
+       end
+       
+       // Now really install the packages
+       // =========================================================================
+       
+       for i=1:size(mandatory_packages,"*")
+               
+               if ~ this_package_details("to_install") then
+                       continue;
+               end
+               
+               this_package_details = dependency_tree(mandatory_packages(i));
+               this_package_name    = this_package_details("Toolbox");
+               this_package_version = this_package_details("Version");
+               
+               // Define the path of the directory where will be installed this toolbox
+               // =====================================================================
+               
+               if allusers then
+                       atoms_directory = pathconvert(SCI+"/contrib/"+this_package_name);
+               else
+                       atoms_directory = pathconvert(SCIHOME+"/atoms/"+this_package_name);
+               end
+               
+               // Create the parent directory of this toolbox if it's not already exist
+               // =====================================================================
+               
+               if ~ isdir( atoms_directory ) then
+                       status = mkdir( atoms_directory );
+                       if status <> 1 then
+                               error(msprintf( ..
+                                       gettext("%s: The directory ""%s"" cannot been created, please check if you have write access on this directory.\n"),..
+                                       atoms_directory));
+                       end
                end
                
-               // Check if the package is already installed
-               if atomsIsInstalled(package_names(i),package_versions(i),%T) then
-                       error(msprintf(gettext("%s: The package %s is already installed.\n"),"atomsInstall",package_full_name));
+               // Define the path of the downloaded file
+               // =====================================================================
+               
+               fileout = pathconvert(atoms_directory+this_package_details(OSNAME+"Name"),%F);
+               filein  = this_package_details(OSNAME+"Url");
+               
+               // Get the package
+               // =====================================================================
+               
+               [rep,stat,err] = unix_g("wget "+filein + " -O " + fileout)
+               
+               if stat ~= 0 then
+                       disp("wget "+ filein + " -O " + fileout);
+                       disp(err);
                end
                
-               // Check if the wanted version is compatible with the current scilab version.
-               this_package_details = atomsToolboxDetails(package_names(i),package_versions(i));
-               if ~ atomsIsCompatible(this_package_details("ScilabVersion")) then
-                       error(msprintf(gettext("%s: The package %s is not compatible with the current scilab version.\n"),"atomsInstall",package_full_name));
+               // Check the md5sum
+               // =====================================================================
+               
+               filemd5 = getmd5(fileout);
+               
+               if filemd5 <> this_package_details(OSNAME+"Md5") then
+                       error(msprintf(gettext("%s: The downloaded binary file (%s) doesn''t check the MD5SUM.\n"),"atomsInstall",fileout));
                end
                
+               // unarchive it
+               // =====================================================================
                
+               chdir( atoms_directory );
                
+               // get the list of directories before unarchive
+               dir_list_before = atomsListDir();
                
+               if regexp(fileout,"/\.tar\.gz$/","o") <> [] then
+                       
+                       [rep,stat,err] = unix_g("tar xzf "+ fileout + " -C "+ atoms_directory );
+                       
+                       if stat ~= 0 then
+                               disp("tar xzf "+ fileout + " -C "+ atoms_directory);
+                               disp(err);
+                       end
+                       
+               elseif regexp(fileout,"/\.zip$/","o") <> [] then
+                       
+                       [rep,stat,err] = unix_g("unzip "+ fileout);
+                       
+                       if stat ~= 0 then
+                               disp("unzip "+ fileout);
+                               disp(err);
+                       end
+                       
+               end
+               
+               // get the list of directories after unarchive
+               dir_list_after = atomsListDir();
                
+               // Get the name of the created directory
+               // =====================================================================
                
+               unarchive_dir = "";
+               
+               for i=1:size(dir_list_after,"*")
+                       if find(dir_list_after(i) == dir_list_before) == [] then
+                               unarchive_dir = dir_list_after(i);
+                               break;
+                       end
+               end
                
+               // Rename the created directory
+               // =====================================================================
                
+               if MSDOS then
+                       rename_cmd = "rename";
+               else
+                       rename_cmd = "mv";
+               end
                
+               rename_cmd = rename_cmd+" """+unarchive_dir+""" """+this_package_version+"""";
                
+               [rep,stat]=unix_g(rename_cmd)
                
+               if stat <> 0 then
+                       disp(rename_cmd);
+                       error(msprintf(gettext("%s: Error while creating the directory ''%s''.\n"),"atomsInstall",pathconvert(atoms_directory+this_package_version)));
+               end
                
                // Register the successfully installed package
-               atomsInstallRegister(package_names(i),package_versions(i));
+               // =====================================================================
+               
+               if find(package_names == this_package_name) == [] then
+                       // Automaticaly installed
+                       this_package_status = "A";
+               else
+                       // Volontary Installed
+                       this_package_status = "I";
+               end
+               
+               atomsInstallRegister(this_package_name,this_package_version,this_package_status,allusers);
+               
        end
        
+       result = dependency_tree;
        
-       
-
-//     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
 
 
+// =============================================================================
+// Just get the list of the directories present in the current directory
+// =============================================================================
 
+function result = atomsListDir()
+       
+       result = [];
+       
+       items  = listfiles();
+       
+       // Loop on items
+       for i=1:size(items,"*")
+               if isdir(items(i)) then
+                       result = [ result ; items(i) ];
+               end
+       end
+       
 endfunction
index 35d3084..9a81a55 100644 (file)
@@ -29,7 +29,7 @@ function res = atomsIsInstalled(name,version,allusers)
                error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsIsInstalled",1));
        end
        
-       if rhs>1 & version<>[] & type(version)<>10  then
+       if rhs>1 &  (~isempty(version)) & type(version)<>10  then
                error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsIsInstalled",2));
        end
        
@@ -64,9 +64,9 @@ function res = atomsIsInstalled(name,version,allusers)
        
        for i=1:size(name,"*")
                
-               if version == [] then
+               if isempty(version) then
                        // Just check the name
-                       res(i) = or(packages == name(i));
+                       res(i) = or(packages(:,1) == name(i));
                
                else
                        // Filter on names
diff --git a/scilab/modules/atoms/macros/atomsUninstall.sci b/scilab/modules/atoms/macros/atomsUninstall.sci
new file mode 100644 (file)
index 0000000..a98a1f3
--- /dev/null
@@ -0,0 +1,208 @@
+// 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
+
+// Uninstallation of a toolbox
+
+function result = atomsUninstall(packages,allusers)
+       
+       result = %F;
+       
+       // Get scilab version (needed for later)
+       // =========================================================================
+       sciversion = strcat(string(getversion('scilab')) + ".");
+       
+       // 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"),"atomsUninstall",1,2))
+       end
+       
+       if type(packages) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsUninstall",1));
+       end
+       
+       packages = stripblanks(packages);
+       
+       // Operating system detection
+       // =========================================================================
+       
+       if ~MSDOS then
+               OSNAME = unix_g('uname');
+               MACOSX = (strcmpi(OSNAME,"darwin") == 0);
+               LINUX  = (strcmpi(OSNAME,"linux") == 0);
+       else
+               MACOSX = %F;
+               LINUX  = %F;
+       end
+       
+       if MSDOS then
+               OSNAME = "windows";
+       elseif LINUX then
+               OSNAME = "linux";
+       elseif MACOSX then
+               OSNAME = "macosx";
+       end
+       
+       // Apply changes for all users or just for me ?
+       // =========================================================================
+       
+       if rhs == 1 then
+               // By default, uninstall the package (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"),"atomsUninstall",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"),"atomsUninstall",2,pathconvert(SCI+"/.atoms")));
+               end
+       end 
+       
+       // Loop on packages and to build the list of package to uninstall
+       // =========================================================================
+       
+       packagesToUninstall_W = []; // Wanted packages
+       packagesToUninstall_D = []; // Dependency packages
+       packagesToUninstall_B = []; // Broken 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
+                       // Just the toolbox name is specified
+                       package_names(i)    = package;
+                       package_versions(i) = "";
+               else
+                       // A version is specified
+                       space               = regexp(package,"/\s/");
+                       package_names(i)    = part(package,[1:space-1]);
+                       package_versions(i) = part(package,[space+1:length(package)]);
+               end
+               
+               // Ok, The syntax is correct, Now check if the package is really installed
+               if ~ atomsIsInstalled(package_names(i),package_versions(i)) then
+                       continue;
+               end
+               
+               // get the list of the versions of this package to uninstall
+               
+               if isempty(package_versions(i)) then
+                       // uninstall all version of this toolbox
+                       this_package_versions = atomsGetInstalledVers(package_names(i));
+               else
+                       // Just uninstall the specified version
+                       this_package_versions = package_versions(i);
+               end
+               
+               // Loop on this version list
+               
+               for j=1:size(this_package_versions,"*")
+                       
+                       packagesToUninstall_W = [ packagesToUninstall_W ; atomsGetInstalledDetails( package_names(i),this_package_versions(j)) ];
+                       
+                       // Establish the dependency list to uninstall
+                       // =================================================================
+                       
+                       // Get the dependencies of this package
+                       this_package_child_deps = atomsGetDepChilds(package_names(i),this_package_versions(j));
+                       
+                       // Loop on dependency childs
+                       for k=1:size(this_package_child_deps(:,1),"*")
+                               
+                               // If this dependence is automatically installed, add it to the
+                               // list of package to uninstall
+                               
+                               if atomsGetInstalledStatus( this_package_child_deps(k,1) , this_package_child_deps(k,2) ) == "A" then
+                                       packagesToUninstall_D = [ packagesToUninstall_D ; atomsGetInstalledDetails(this_package_child_deps(k,1),this_package_child_deps(k,2)) ];
+                               end
+                               
+                       end
+                       
+                       // Establish the broken list to uninstall
+                       // =================================================================
+                       
+                       // Get the dependencies of this package
+                       this_package_parent_deps = atomsGetDepParents(package_names(i),this_package_versions(j));
+                       
+                       // Loop on dependency parents
+                       for k=1:size(this_package_parent_deps(:,1),"*")
+                               
+                               // If this dependence is automatically installed, add it to the
+                               // list of package to uninstall
+                               packagesToUninstall_B = [ packagesToUninstall_B ; atomsGetInstalledDetails(this_package_deps(k,1) , this_package_deps(k,2)) ];
+                               
+                       end
+                       
+               end
+               
+       end
+       
+       // Loop on packages to filter the list of package to uninstall
+       // =========================================================================
+       
+       // All wanted packages must be uninstalled
+       packagesToUninstall = packagesToUninstall_W;
+       
+       // For the moment, All dependency packages must be uninstalled
+       packagesToUninstall = [ packagesToUninstall ; packagesToUninstall_D ];
+       
+       // Now we have the list of package that have to be uninstalled
+       // =========================================================================
+       
+       for i=1:size(packagesToUninstall(:,1),"*")
+               
+               this_package_name      = packagesToUninstall(i,1);
+               this_package_version   = packagesToUninstall(i,2);
+               this_package_directory = packagesToUninstall(i,4);
+               
+               // Check if this_package_directory start with SCI or SCIHOME
+               
+               if (grep(this_package_directory,pathconvert(SCI)) == []) & ..
+                       (grep(this_package_directory,pathconvert(SCIHOME)) == []) then
+                       
+                       error(msprintf(gettext("%s: The directory of this package (%s-%s) is located neither in SCI nor in SCIHOME. For security resaon, ATOMS refuse to delete this directory.\n"),"atomsUninstall",packagesToUninstall(1,1),packagesToUninstall(1,2)));
+               end
+               
+               uninstall_status = rmdir(this_package_directory,"s");
+               
+               if uninstall_status<>1 then
+                       error(msprintf( ..
+                               gettext("%s: The directory of this package (%s-%s) cannot been deleted, please check if you have write access on this directory : %s.\n"),..
+                               "atomsUninstall", ..
+                               this_package_name, ..
+                               this_package_version, ..
+                               this_package_directory));
+               end
+               
+               atomsInstallUnregister(this_package_name,this_package_version,allusers);
+               
+       end
+       
+       result = %T;
+       
+endfunction
index 0d3389d..cc11d3a 100644 (file)
@@ -14,8 +14,8 @@ function res = atomsAUWriteAccess()
        res = %F;
        
        try
-               mputl("dummy",pathconvert(SCI+"/.atoms/dummy",%F));
-               mdelete(pathconvert(SCI+"/.atoms/dummy",%F));
+               mputl("dummy",pathconvert(SCI+"/contrib/dummy",%F));
+               mdelete(pathconvert(SCI+"/contrib/dummy",%F));
                res = %T;
        catch
        end
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsCatTree.sci b/scilab/modules/atoms/macros/atoms_internals/atomsCatTree.sci
new file mode 100644 (file)
index 0000000..d33d92c
--- /dev/null
@@ -0,0 +1,57 @@
+// 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
+
+// =============================================================================
+// tree_out = atomsCatTree( tree_in_1 , tree_in_2 )
+//
+// Date : 19/05/2009
+// =============================================================================
+
+function tree_out = atomsCatTree( tree_in_1 , tree_in_2 )
+       
+       rhs = argn(2);
+       
+       // Check number of input arguments
+       // =========================================================================
+       
+       if rhs <> 2 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"atomsMergeTree",1));
+       end
+       
+       // Check input arguments type
+       // =========================================================================
+       
+       if type(tree_in_1) <> 17 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: matrix oriented typed list expected.\n"),"atomsMergeTree",1));
+       end
+       
+       if type(tree_in_2) <> 17 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: matrix oriented typed list expected.\n"),"atomsMergeTree",2));
+       end
+       
+       // tree_in_1 is the master tree :
+       // =========================================================================
+       
+       tree_out  = tree_in_1;
+       
+       // Loop on tree_in_2 fields
+       // =========================================================================
+       
+       fields = getfield(1,tree_in_2);
+       fields(1:2) = [];
+       
+       for i=1:size(fields,"*")
+               if ~ isfield(tree_out,fields(i)) then
+                       tree_out(fields(i)) = tree_in_2(fields(i));
+               end
+       end
+       
+endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsCompatibleVersions.sci b/scilab/modules/atoms/macros/atoms_internals/atomsCompatibleVersions.sci
new file mode 100644 (file)
index 0000000..f213cf2
--- /dev/null
@@ -0,0 +1,62 @@
+// 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 sorted list of the versions compatible with this version of Scilab
+
+function versions = atomsCompatibleVersions(name)
+       
+       // Initialize
+       versions = [];
+       
+       // Check input parameters
+       // =========================================================================
+       
+       rhs  = argn(2);
+       
+       if rhs <> 1  then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsCompatibleVersions",1));
+       end
+       
+       if type(name) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"atomsCompatibleVersions",1));
+       end
+       
+       // Get all package description
+       // =========================================================================
+       allpackages = atomsGetTOOLBOXES();
+       
+       // Check if it's a Atoms package
+       // =========================================================================
+       if ~ isfield(allpackages,name) then
+               error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be a atoms package name.\n"),"atomsCompatibleVersions",1));
+       end
+       
+       // Get versions
+       // =========================================================================
+       package_versions          = allpackages(name);
+       package_versions_tab      = getfield(1,package_versions);
+       package_versions_tab(1:2) = [];
+       
+       // Loop on package_versions_tab
+       // =========================================================================
+       
+       for i=1:size(package_versions_tab,"*")
+               this_version = package_versions(package_versions_tab(i));
+               if atomsIsCompatible(this_version("ScilabVersion")) then
+                       versions = [ versions ; package_versions_tab(i) ];
+               end
+       end
+       
+       // Sort the version matrix
+       // =========================================================================
+       versions = atomsVersionSort(versions,"DESC");
+       
+endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsDependencyTree.sci b/scilab/modules/atoms/macros/atoms_internals/atomsDependencyTree.sci
new file mode 100644 (file)
index 0000000..4d9ca5b
--- /dev/null
@@ -0,0 +1,155 @@
+// 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
+
+function tree_out = atomsDependencyTree(name,version,tree_in)
+       
+       rhs = argn(2);
+       
+       // Check number of input arguments
+       // =========================================================================
+       
+       if (rhs < 1) | (rhs > 3) then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsDependencyTree",1,3));
+       end
+       
+       // Check input parameters type
+       // =========================================================================
+       
+       if type(name) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsDependencyTree",1));
+       end
+       
+       if (rhs>=2) & (type(version) <> 10) then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsDependencyTree",2));
+       end
+       
+       if (rhs==3) & (type(tree_in) <> 17) then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: matrix oriented typed list expected.\n"),"atomsDependencyTree",3));
+       end
+       
+       // Check input parameters dimensions
+       // =========================================================================
+       
+       if size(name) <> 1 then
+               error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsDependencyTree",1));
+       end
+       
+       // If version not define, version is the list of version compatible with
+       // the current version of Scilab
+       // =========================================================================
+       
+       if (rhs<2) | ((rhs>=2) & (version=="")) then
+               version = atomsCompatibleVersions(name);
+       end
+       
+       // Define tree_in if not defined as input argument
+       // =========================================================================
+       
+       if rhs<3 then
+               tree_in = struct();
+       end
+       
+       // Loop on versions
+       // =========================================================================
+       
+       for i=1:size(version,"*")
+               
+               // Get dependencies of this toolbox
+               // =========================================================================
+               this_package_details = atomsToolboxDetails(name,version(i));
+               
+               // Check if the wanted version is compatible with the current scilab version.
+               // =========================================================================
+               
+               this_package_details = atomsToolboxDetails(name,version(i));
+               
+               if ~ atomsIsCompatible(this_package_details("ScilabVersion")) then
+                       tree_out = %F;
+                       return tree_out;
+               end
+               
+               tree_out(name) = this_package_details;
+               
+               // Now, loop on dependencies
+               // =========================================================================
+               
+               if isfield(this_package_details,"Depends") & (this_package_details("Depends") ~= "") then
+                       dependencies = this_package_details("Depends");
+               else
+                       dependencies = [];
+               end
+               
+               for i=1:size(dependencies,"*")
+                       
+                       this_dependency_success = %F;
+                       
+                       // Split dependencies to get 
+                       //  - direction ("=", ">=", "<=", "~")
+                       //  - dependence name
+                       //  - dependence version (optional)
+                       
+                       this_dependency_tab     = stripblanks(strsplit(dependencies(i),regexp(stripblanks(dependencies(i)),"/\s/")));
+                       
+                       this_dependency_dir     = this_dependency_tab(1);
+                       this_dependency_name    = this_dependency_tab(2);
+                       this_dependency_version = this_dependency_tab(3);
+                       
+                       // List versions of the dependency we can test
+                       
+                       if this_dependency_dir     == "="  then
+                               this_dependency_list = this_dependency_version;
+                       
+                       elseif this_dependency_dir == "~"  then
+                               this_dependency_list = atomsGetVersions(this_dependency_name);
+                       
+                       elseif this_dependency_dir == ">=" then
+                               this_dependency_list = atomsGetVersions(this_dependency_name,this_dependency_version);
+                               
+                       elseif this_dependency_dir == "<=" then
+                               this_dependency_list = atomsGetVersions(this_dependency_name,"",this_dependency_version);
+                               
+                       end
+                       
+                       for j=1:size(this_dependency_list,"*")
+                               
+                               tree = atomsDependencyTree(this_dependency_name,this_dependency_list(j),tree_out);
+                               
+                               // Dependency Tree fails
+                               
+                               if (type(tree) == 4) & (~ tree) then
+                                       continue;
+                               end
+                               
+                               // Dependency Tree OK
+                               
+                               if type(tree) == 17 then
+                                       tree_out = atomsCatTree(tree_out,tree);
+                                       this_dependency_success = %T;
+                                       break;
+                               end
+                               
+                       end
+                       
+                       if ~  this_dependency_success then
+                               tree_out = %F;
+                               break;
+                       end
+                       
+               end
+               
+               
+               if type(tree_out)==17 then
+                       return;
+               end
+               
+       end
+       
+endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsGetDepChilds.sci b/scilab/modules/atoms/macros/atoms_internals/atomsGetDepChilds.sci
new file mode 100644 (file)
index 0000000..4c0af00
--- /dev/null
@@ -0,0 +1,117 @@
+// 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
+
+// Returns true if a package is installed, false otherwise
+
+function packages = atomsGetDepChilds(name,version,allusers)
+       
+       rhs      = argn(2);
+       packages = [];
+       
+       // Check number of input arguments
+       // =========================================================================
+       
+       if rhs < 2 | rhs > 3 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsGetDepChilds",2,3));
+       end
+       
+       // Check input parameters type
+       // =========================================================================
+       
+       if type(name) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsGetDepChilds",1));
+       end
+       
+       if type(version)<>10  then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsGetDepChilds",2));
+       end
+       
+       // Check input parameters dimensions
+       // =========================================================================
+       
+       if size(name,"*") <> 1 then
+               error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsGetDepChilds",1));
+       end
+       
+       if size(version,"*")<>1  then
+               error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsGetDepChilds",2));
+       end
+       
+       // All user management
+       // =========================================================================
+       
+       if rhs == 2 then
+               allusers = %T;
+       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"),"atomsGetDepChilds",3));
+               end
+       end
+       
+       // Define the differents path of the file where are installed
+       // =========================================================================
+       
+       installed_deps_files = [];
+       user_file            = pathconvert(SCIHOME+"/atoms/installed_deps",%F);
+       alluser_file         = pathconvert(SCI+"/.atoms/installed_deps",%F);
+       
+       if fileinfo(user_file)<>[] then
+               installed_deps_files = [ installed_deps_files ; user_file "user" ];
+       end
+       
+       if allusers & (fileinfo(alluser_file)<>[]) then
+               installed_deps_files = [ installed_deps_files ; alluser_file "alluser"];
+       end
+       
+       // Loop on each "installed_deps" file specified as first input argument
+       // =========================================================================
+       
+       found = 0;
+       
+       for i=1:size(installed_deps_files(:,1),"*")
+               
+               if found == 1 then
+                       break;
+               end
+               
+               // Get the installed package list in this file
+               installed_deps_lines = mgetl(installed_deps_files(i,1));
+               
+               // Loop on each lines
+               for j=1:size(installed_deps_lines,"*")
+                       
+                       // If this line is a "parent toolbox" or a blank line and the wanted toolbox is already found
+                       // Break the loop
+                       
+                       if (found == 1) & ..
+                               ( (regexp(installed_deps_lines(j),"/^\[(.)*\]$/","o") <> []) | isempty(installed_deps_lines(j)) ) then
+                               break;
+                       end
+                       
+                       // Yeah, the wanted toolbox has been found
+                       
+                       if installed_deps_lines(j) == "["+name+" - "+version+"]" then
+                               found = 1;
+                               continue;
+                       end
+                       
+                       // This line is a inevitably a toolbox
+                       if found == 1 then
+                               this_line           = stripblanks(installed_deps_lines(j));
+                               current_name_length = regexp(this_line,"/\s-\s/","o");
+                               current_name        = part(this_line,1:current_name_length-1);
+                               current_version     = part(this_line,current_name_length+3:length(this_line));
+                               packages            = [ packages ; current_name current_version];
+                       end
+                       
+               end
+       end
+       
+endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsGetDepParents.sci b/scilab/modules/atoms/macros/atoms_internals/atomsGetDepParents.sci
new file mode 100644 (file)
index 0000000..57aae19
--- /dev/null
@@ -0,0 +1,109 @@
+// 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
+
+// Renvoie la liste des packages dont celui passé en argument est une dépendance
+
+function packages = atomsGetDepParents(name,version,allusers)
+       
+       rhs      = argn(2);
+       packages = [];
+       
+       // Check number of input arguments
+       // =========================================================================
+       
+       if rhs < 2 | rhs > 3 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsGetDepChilds",2,3));
+       end
+       
+       // Check input parameters type
+       // =========================================================================
+       
+       if type(name) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsGetDepChilds",1));
+       end
+       
+       if type(version)<>10  then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsGetDepChilds",2));
+       end
+       
+       // Check input parameters dimensions
+       // =========================================================================
+       
+       if size(name,"*") <> 1 then
+               error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsGetDepChilds",1));
+       end
+       
+       if size(version,"*")<>1  then
+               error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsGetDepChilds",2));
+       end
+       
+       // All user management
+       // =========================================================================
+       
+       if rhs == 2 then
+               allusers = %T;
+       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"),"atomsGetDepChilds",3));
+               end
+       end
+       
+       // Define the differents path of the file where are installed
+       // =========================================================================
+       
+       installed_deps_files = [];
+       user_file            = pathconvert(SCIHOME+"/atoms/installed_deps",%F);
+       alluser_file         = pathconvert(SCI+"/.atoms/installed_deps",%F);
+       
+       if fileinfo(user_file)<>[] then
+               installed_deps_files = [ installed_deps_files ; user_file "user" ];
+       end
+       
+       if allusers & (fileinfo(alluser_file)<>[]) then
+               installed_deps_files = [ installed_deps_files ; alluser_file "alluser"];
+       end
+       
+       // Loop on each "installed_deps" file specified as first input argument
+       // =========================================================================
+       
+       for i=1:size(installed_deps_files(:,1),"*")
+               
+               // Get the installed package list in this file
+               installed_deps_lines = mgetl(installed_deps_files(i,1));
+               
+               // Loop on each lines
+               for j=1:size(installed_deps_lines,"*")
+                       
+                       if regexp(installed_deps_lines(j),"/^\[(.)*\]$/","o") <> [] then
+                               
+                               // Remove leading and trailing whitespaces.
+                               this_line = stripblanks(installed_deps_lines(j));
+                               
+                               // Remove leading and trailing [ ]
+                               this_line = part(this_line,2:length(this_line)-1);
+                               
+                               current_name_length = regexp(this_line,"/\s-\s/","o");
+                               current_name        = part(this_line,1:current_name_length-1);
+                               current_version     = part(this_line,current_name_length+3:length(this_line));
+                               current_parent      = [current_name current_version];
+                               
+                               continue;
+                       end
+                       
+                       if stripblanks(installed_deps_lines(j)) == name+" - "+version then
+                               if ~ isempty(current_parent) then
+                                       packages = [ packages ; current_parent ];
+                               end
+                       end
+               end
+               
+       end
+       
+endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsGetInstalledDetails.sci b/scilab/modules/atoms/macros/atoms_internals/atomsGetInstalledDetails.sci
new file mode 100644 (file)
index 0000000..2c95618
--- /dev/null
@@ -0,0 +1,65 @@
+// 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
+
+// Renvoie les détails sur l'installation d'un package.
+
+function res = atomsGetInstalledDetails(name,version)
+       
+       rhs = argn(2);
+       res = [];
+       
+       // Check number of input arguments
+       // =========================================================================
+       
+       if rhs < 1 | rhs > 3 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsGetInstalledStatus",2,3));
+       end
+       
+       // Check input parameters type
+       // =========================================================================
+       
+       if type(name) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsGetInstalledStatus",1));
+       end
+       
+       if type(version)<>10  then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsGetInstalledStatus",2));
+       end
+       
+       // Check input parameters dimensions
+       // =========================================================================
+       
+       if or( size(name,"*") <> size(version,"*"))  then
+               error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"atomsGetInstalledStatus",1,2));
+       end
+       
+       // Get the list of installed packages
+       // =========================================================================
+       packages = atomsGetInstalled();
+       
+       // Loop on name
+       // =========================================================================
+       
+       for i=1:size(name,"*")
+               
+               // Filter on names
+               packages_filtered = packages( find(packages(:,1) == name(i)) , : );
+               
+               // Filter on versions
+               packages_filtered = packages_filtered( find(packages_filtered(:,2) == version(i)) , : );
+               
+               if ~ isempty(packages_filtered) then
+                       res = [ res ; packages_filtered ];
+               else
+                       res = [ res ; "" "" "" "" "" ];
+               end
+               
+       end
+       
+endfunction
diff --git a/scilab/modules/atoms/macros/atoms_internals/atomsGetInstalledStatus.sci b/scilab/modules/atoms/macros/atoms_internals/atomsGetInstalledStatus.sci
new file mode 100644 (file)
index 0000000..7e7455c
--- /dev/null
@@ -0,0 +1,64 @@
+// 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
+
+// Liste des versions installée de la toolbox "name"
+
+function res = atomsGetInstalledStatus(name,version)
+       
+       rhs = argn(2);
+       
+       // Check number of input arguments
+       // =========================================================================
+       
+       if rhs < 1 | rhs > 3 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsGetInstalledStatus",2,3));
+       end
+       
+       // Check input parameters type
+       // =========================================================================
+       
+       if type(name) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsGetInstalledStatus",1));
+       end
+       
+       if type(version)<>10  then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsGetInstalledStatus",2));
+       end
+       
+       // Check input parameters dimensions
+       // =========================================================================
+       
+       if or( size(name,"*") <> size(version,"*"))  then
+               error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"atomsGetInstalledStatus",1,2));
+       end
+       
+       // Get the list of installed packages
+       // =========================================================================
+       packages = atomsGetInstalled();
+       
+       // Loop on name
+       // =========================================================================
+       
+       for i=1:size(name,"*")
+               
+               // Filter on names
+               packages_filtered = packages( find(packages(:,1) == name(i)) , : );
+               
+               // Filter on versions
+               packages_filtered = packages( find(packages(:,2) == version(i)) , 5 );
+               
+               if ~ isempty(packages_filtered) then
+                       res(i) = packages_filtered(1);
+               else
+                       res(i) = "";
+               end
+               
+       end
+       
+endfunction
index 802a3c0..0a4a80e 100644 (file)
@@ -44,6 +44,10 @@ function res = atomsGetInstalledVers(name,allusers)
        
        // Filter on names
        // =========================================================================
-       res = gsort(packages(find(packages(:,1) == name),2));
+       res = packages(find(packages(:,1) == name),2);
+       
+       // Descending Sort 
+       // =========================================================================
+       res = atomsVersionSort( res , "DESC" );
        
 endfunction
index 8906a19..002bd70 100644 (file)
@@ -16,6 +16,26 @@ function packages = atomsGetTOOLBOXES(update)
        // Initialize
        packages = struct();
        
+       // Operating system detection
+       // =========================================================================
+       
+       if ~MSDOS then
+               OSNAME = unix_g('uname');
+               MACOSX = (strcmpi(OSNAME,"darwin") == 0);
+               LINUX  = (strcmpi(OSNAME,"linux") == 0);
+       else
+               MACOSX = %F;
+               LINUX  = %F;
+       end
+       
+       if MSDOS then
+               OSNAME = "windows";
+       elseif LINUX then
+               OSNAME = "linux";
+       elseif MACOSX then
+               OSNAME = "macosx";
+       end
+       
        // Check input parameters
        // =========================================================================
        
@@ -44,7 +64,7 @@ function packages = atomsGetTOOLBOXES(update)
                
                for i=1:size(mirrors,"*")
                        
-                       url            = mirrors(i)+"/TOOLBOXES";
+                       url            = mirrors(i)+"/TOOLBOXES/"+OSNAME;
                        file_out       = pathconvert(TMPDIR+"/atoms/"+sprintf("TOOLBOXES_%d",nb_TOOLBOXES),%f);
                        
                        if( fileinfo(file_out) <> [] ) then
index 625e8bd..cf9cd7c 100644 (file)
@@ -7,19 +7,23 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-// Add an URL to the list of repositories, and returns
+// Add toolboxes to the list of installed packages
+// This function has an impact on the following files :
+//  -> ATOMSDIR/installed
+//  -> ATOMSDIR/installed_deps
 
-function nbAdd = atomsInstallRegister(name,version,allusers)
+function nbAdd = atomsInstallRegister(name,version,status,allusers)
        
-       rhs           = argn(2);
-       nbAdd         = 0;
-       installed     = []; // Column vector that contain user repositories
+       rhs            = argn(2);
+       nbAdd          = 0;
+       installed      = []; // Column vector that contain installed packages
+       installed_deps = []; // Column vector that contain installed dependencies
        
        // Check number of input arguments
        // =========================================================================
        
-       if rhs < 2 | rhs > 3 then
-               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsInstallRegister",2,3));
+       if rhs < 3 | rhs > 4 then
+               error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsInstallRegister",3,4));
        end
        
        // Check input parameters type
@@ -33,17 +37,32 @@ function nbAdd = atomsInstallRegister(name,version,allusers)
                error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstallRegister",2));
        end
        
-       // name and version must have the same size
+       if type(status) <> 10 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsInstallRegister",3));
+       end
+       
+       // status is a letter
+       // =========================================================================
+       
+       if ~ and((status == "A") | (status == "I"))  then
+               error(msprintf(gettext("%s: Wrong value for input argument #%d: Letters ''A'' or ''I'' expected.\n"),"atomsInstallRegister",3));
+       end
+       
+       // name,version and status must have the same size
        // =========================================================================
        
        if or( size(name) <> size(version) ) then
                error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"atomsInstallRegister",1,2));
        end
        
+       if or( size(name) <> size(status) ) then
+               error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"atomsInstallRegister",1,3));
+       end
+       
        // Apply changes for all users or just for me ?
        // =========================================================================
        
-       if rhs == 2 then
+       if rhs == 3 then
                // By default, The toolbox is installed for all users (if we have write access of course !)
                if atomsAUWriteAccess() then
                        allusers = %T; 
@@ -87,22 +106,68 @@ function nbAdd = atomsInstallRegister(name,version,allusers)
                installed = mgetl(atoms_directory+"installed");
        end
        
+       // Does the SCIHOME/atoms/installed_deps exist, if yes load it
+       // =========================================================================
+       
+       if fileinfo(atoms_directory+"installed_deps") <> [] then
+               installed_deps = mgetl(atoms_directory+"installed_deps");
+       end
+       
        // Loop on each URL specified as input argument
        // =========================================================================
        
        for i=1:size(name,"*")
+               
                // Add the URL only if it doesn't already exist
-               if find( installed == name(i)+" - "+version(i) ) == [] then
-                       installed = [ installed ; name(i)+" - "+version(i) ];
+               if grep( installed ,"/^[AI]\s-\s"+name(i)+"\s-\s"+version(i)+"$/","r") == [] then
+                       
                        nbAdd = nbAdd + 1;
+                       
+                       // installed file
+                       // =================================================================
+                       installed = [ installed ; status(i)+" - "+name(i)+" - "+version(i) ];
+                       
+                       // installed_deps file
+                       // =================================================================
+                       
+                       // Parent package
+                       // --------------
+                       this_package_str = ["["+name(i)+" - "+version(i)+"]"];
+                       
+                       // Get the depencency tree & and child package
+                       // -------------------------------------------
+                       tree              = atomsDependencyTree(name(i),version(i));
+                       dep_packages      = getfield(1,tree);
+                       dep_packages(1:2) = [];
+                       dep_packages(find(dep_packages == name(i))) = [];
+                       
+                       // loop on childs
+                       // -------------------------------------------
+                       for j=1:size(dep_packages,"*")
+                               this_dep_package_details = tree(dep_packages(j));
+                               this_package_str = [this_package_str;"    "+this_dep_package_details("Toolbox")+" - "+this_dep_package_details("Version")];
+                       end
+                       
+                       // Finalize the current packages string
+                       // ------------------------------------
+                       this_package_str  = [this_package_str;""];
+                       
+                       // Cat the current packages deps with all others
+                       // ---------------------------------------------
+                       installed_deps    = [installed_deps;this_package_str];
+                       
                end
+               
        end
        
        // Apply changes
        // =========================================================================
        
        if nbAdd > 0 then
-               mputl(installed, atoms_directory+"installed");
+               
+               mputl(installed     , atoms_directory+"installed");
+               mputl(installed_deps, atoms_directory+"installed_deps");
+               
        end
        
 endfunction
index c26f12c..8823c16 100644 (file)
@@ -8,6 +8,9 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 // Delete an atoms package from the list of available package
+// This function has an impact on the following files :
+//  -> ATOMSDIR/installed
+//  -> ATOMSDIR/installed_deps
 
 function nbDel = atomsInstallUnregister(name,version,allusers)
        
@@ -67,6 +70,8 @@ function nbDel = atomsInstallUnregister(name,version,allusers)
        // the "allusers" value and the existence of the latter
        // =========================================================================
        
+       // installed files
+       
        atoms_files = [];
        
        if fileinfo( pathconvert(SCIHOME+"/atoms/installed",%F) )<> [] then
@@ -77,6 +82,18 @@ function nbDel = atomsInstallUnregister(name,version,allusers)
                atoms_files = [ atoms_files ; pathconvert(SCI+"/.atoms/installed",%F) ];
        end
        
+       // installed_deps files
+       
+       atoms_files_deps = [];
+       
+       if fileinfo( pathconvert(SCIHOME+"/atoms/installed_deps",%F) )<> [] then
+               atoms_files_deps = [ atoms_files_deps ; pathconvert(SCIHOME+"/atoms/installed_deps",%F) ];
+       end
+       
+       if allusers & (fileinfo( pathconvert(SCI+"/.atoms/installed_deps",%F) )<>[]) then
+               atoms_files_deps = [ atoms_files_deps ; pathconvert(SCI+"/.atoms/installed_deps",%F) ];
+       end
+       
        // Loop on each installed file specified as first input argument
        // =========================================================================
        
@@ -87,10 +104,11 @@ function nbDel = atomsInstallUnregister(name,version,allusers)
                
                // Loop on each URL specified as first input argument
                for j=1:size(name,"*")
-                       indice = find( installed == name(j)+" - "+version(j) );
+                       indice = grep(installed,"/^[AI]\s-\s"+name(j)+"\s-\s"+version(j)+"$/","r");
+                       
                        if indice <> [] then
-                               installed(indice) = [];
                                nbDel = nbDel + 1;
+                               installed(indice) = [];
                        end
                end
                
@@ -102,4 +120,48 @@ function nbDel = atomsInstallUnregister(name,version,allusers)
                end
        end
        
+       // Loop on each installed file specified as first input argument
+       // =========================================================================
+       
+       for i=1:size(atoms_files_deps,"*")
+               
+               found = 0;
+               
+               // Get the installed package list in this file
+               installed_deps_in  = mgetl(atoms_files_deps(i));
+               installed_deps_out = [];
+               
+               // Loop on each URL specified as first input argument
+               for j=1:size(name,"*")
+                       
+                       // Loop on each lines of the installed_deps file
+                       for k=1:size(installed_deps_in,"*")
+                               
+                               if installed_deps_in(k) == "["+name(j)+" - "+version(j)+"]" then
+                                       found = 1;
+                               end
+                               
+                               if found == 1 then
+                                       continue;
+                               end
+                               
+                               if regexp(installed_deps_in(k),"/^\[(.)*\]$/","o") <> [] then
+                                       found = 0;
+                               end
+                               
+                               if found == 0 then
+                                       installed_deps_out = [ installed_deps_out , installed_deps_in(k) ];
+                               end
+                       end
+                       
+               end
+               
+               if installed_deps_out == [] then
+                       mdelete(atoms_files_deps(i));
+               else
+                       // Apply changes on this file
+                       mputl(installed_deps_out,atoms_files_deps(i));
+               end
+       end
+       
 endfunction
index 122b2cf..42b4d95 100644 (file)
@@ -49,24 +49,20 @@ function result = atomsIsPackage(package_names,package_versions)
                result(i) = %F;
                
                if rhs == 1 then
-                       version = "0";
+                       version = "";
                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
+               if isempty(version) & isfield(allpackages,package_names(i)) then
+                       result(i) = %T;
                
                // 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
+               elseif isfield(allpackages,package_names(i)) then
+                       this_package = allpackages(package_names(i));
+                       if isfield(this_package,version) then
+                               result(i) = %T;
                        end
                end
                
index 6aa1c9b..1defe70 100644 (file)
@@ -53,4 +53,16 @@ function details = atomsToolboxDetails(name,version)
        package_versions = packages(name);
        details          = package_versions(version);
        
+       // Check if this version is installed
+       // =========================================================================
+       
+       if atomsIsInstalled(name,version) then
+               
+               installedDetails = atomsGetInstalledDetails(name,version);
+               details("installAlluser") = installedDetails(3);
+               details("installPath")    = installedDetails(4);
+               details("installStatus")  = installedDetails(5);
+               
+       end
+       
 endfunction
diff --git a/scilab/modules/atoms/tests/unit_tests/atomsIsInstalled.tst b/scilab/modules/atoms/tests/unit_tests/atomsIsInstalled.tst
new file mode 100644 (file)
index 0000000..77a9dd0
--- /dev/null
@@ -0,0 +1,38 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- JVM NOT MANDATORY -->
+
+// Install toolbox N°1 for all users (SCI/.atoms)
+atomsInstallRegister("toolbox1","1.0",%T);
+atomsInstallRegister("toolbox1","1.1",%T);
+atomsInstallRegister("toolbox1","1.2",%T);
+
+// Install toolbox N°2 for current user only (SCIHOME/atoms)
+atomsInstallRegister("toolbox2","0.1",%F);
+atomsInstallRegister("toolbox2","0.2",%F);
+
+// Check input parameters
+if execstr("atomsIsInstalled()","errcatch") == 0 then pause; end
+if execstr("atomsIsInstalled([""toolbox1"" ""toolbox2""],[""1.0"";""0.1""]  )","errcatch") == 0 then pause, end
+if execstr("atomsIsInstalled([""toolbox1"" ""toolbox1""],[""1.0""]  )","errcatch") == 0 then pause, end
+
+// Check output results
+
+if ~ atomsIsInstalled("toolbox1") then pause, end
+if atomsIsInstalled("toolbox1",[],%F) then pause, end
+
+if ~ atomsIsInstalled("toolbox2") then pause, end
+if ~ atomsIsInstalled("toolbox2",[],%F) then pause, end
+
+if ~ atomsIsInstalled("toolbox1","1.0") then pause, end
+if ~ atomsIsInstalled("toolbox1","1.1") then pause, end
+if ~ atomsIsInstalled("toolbox1","1.2") then pause, end
+
+if or( atomsIsInstalled(["toolbox1" "toolbox2" "toolbox1" "toolbox1"],["1.0" "1.1" "1.2" "1.3"] ) <> [%T %F %T %F] )  then pause, end
+if or( atomsIsInstalled(["toolbox1" "toolbox2";"toolbox1" "toolbox1"],["1.0" "1.1";"1.2" "1.3"] ) <> [%T %F;%T %F] )  then pause, end
+if or( atomsIsInstalled(["toolbox1";"toolbox2";"toolbox1";"toolbox1"],["1.0";"1.1";"1.2";"1.3"] ) <> [%T;%F;%T;%F] )  then pause, end
diff --git a/scilab/modules/atoms/tests/unit_tests/atomsVersionCompare.tst b/scilab/modules/atoms/tests/unit_tests/atomsVersionCompare.tst
new file mode 100644 (file)
index 0000000..5a06586
--- /dev/null
@@ -0,0 +1,18 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- JVM NOT MANDATORY -->
+
+if atomsVersionCompare("5.1"        ,"5.1.0")     <> 0 then pause, end
+if atomsVersionCompare("5.1.0"      ,"5.1")       <> 0 then pause, end
+if atomsVersionCompare("5.1.00000"  ,"5.1.0.0")   <> 0 then pause, end
+if atomsVersionCompare("5.1.0.0"    ,"5.1.00000") <> 0 then pause, end
+
+if atomsVersionCompare("5.1.0","5.1.2") <> -1 then pause, end
+if atomsVersionCompare("5.1.2","5.1.0") <>  1 then pause, end
+
+if atomsVersionCompare("10.0","2.6.9") <> 1 then pause, end