ATOMS: atomsRepositoryXXX: Better management of "allusers"/"user" sections
Pierre MARECHAL [Mon, 19 Oct 2009 16:33:27 +0000 (18:33 +0200)]
scilab/modules/atoms/help/en_US/atomsRepositoryAdd.xml
scilab/modules/atoms/help/en_US/atomsRepositoryDel.xml
scilab/modules/atoms/help/en_US/atomsRepositoryList.xml
scilab/modules/atoms/macros/atomsRepositoryAdd.sci
scilab/modules/atoms/macros/atomsRepositoryDel.sci
scilab/modules/atoms/macros/atomsRepositoryList.sci
scilab/modules/atoms/tests/unit_tests/atomsRepositoryAdd.dia.ref [new file with mode: 0644]
scilab/modules/atoms/tests/unit_tests/atomsRepositoryAdd.tst [new file with mode: 0644]

index 0b29d4a..4065a5d 100644 (file)
@@ -21,7 +21,7 @@
   <refsynopsisdiv>
     <title>Calling Sequence</title>
     <synopsis>
-         nbAdd = atomsRepositoryAdd(url[,allusers])
+         nbAdd = atomsRepositoryAdd(url[,section])
        </synopsis>
   </refsynopsisdiv>
   <!-- ===================================================================== -->
                                        </para>
         </listitem>
       </varlistentry>
-      <varlistentry>
-        <term>allusers</term>
+                       <varlistentry>
+        <term>section</term>
+                               
         <listitem>
           <para>
-                                               A boolean : if this parameter is equal to TRUE (%T), URLs are added
-                                               for all users of the computer. The list of available URL for all users
-                                               is defined in SCI/.atoms/repositories ("allusers zone").
-                                               
-                                               If allusers is set to TRUE (%T) and the directory SCI/.atoms/ is not
-                                               write accessible, atomsRepositoryAdd will produce an error.
-                                               
-                                               if this parameter is equal to FALSE (%T), the URL is only added
-                                               for the current user. The list of URL only available for the current
-                                               user is defined in SCIHOME/atoms/repositories ("user zone").
+                                               This argument controls where the repository is added.
+                                       </para>
+          <para>
+                                               <literal>section</literal> is a single-string and its value should be :
+                                       </para>
+          <itemizedlist>
+            <listitem>
+              <para>
+                                                               <literal>"allusers"</literal>: the repository is added to the
+                                                               "allusers" list and all user of scilab are affected.
+                                                       </para>
+            </listitem>
+            <listitem>
+              <para><literal>"user"</literal>: the repository is added to the
+                                                               "user" list and only the current user is affected.
+                                                       </para>
+            </listitem>
+          </itemizedlist>
+                                       <para>
+                                               If SCI/contrib is write accessible, "allusers" is the default value.
+                                               Otherwise, the default value is "user".
                                        </para>
         </listitem>
-      </varlistentry>
+                       </varlistentry>
       <varlistentry>
         <term>nbAdd</term>
         <listitem>
index d5e74fa..5c343f8 100644 (file)
@@ -21,7 +21,7 @@
   <refsynopsisdiv>
     <title>Calling Sequence</title>
     <synopsis>
-         nbDel = atomsRepositoryDel(url[,allusers])
+         nbDel = atomsRepositoryDel(url[,section])
        </synopsis>
   </refsynopsisdiv>
   <!-- ===================================================================== -->
         <term>url</term>
         <listitem>
           <para>
-                       Matrix of strings : list of the URLs to remove
-                 </para>
+                                               Matrix of strings : list of the URLs to remove
+                                       </para>
         </listitem>
       </varlistentry>
-      <varlistentry>
-        <term>allusers</term>
+                       
+                       <varlistentry>
+        <term>section</term>
         <listitem>
           <para>
-                                               A boolean : if this parameter is equal to TRUE (%T), URLs are removed
-                                               from both "allusers" and "user" list.
-                                               
-                                               If allusers is set to TRUE (%T) and the directory SCI/.atoms/ is not
-                                               write accessible, atomsRepositoryDel will produce an error.
-                                               
-                                               if this parameter is equal to FALSE (%T), URLs are only removed
-                                               from "user" list.
+                                               This argument controls the list of sections where search
+                                               URL(s) to remove.
+                                       </para>
+          <para>
+                                               <literal>section</literal> is a single-string and its value should be :
+                                       </para>
+          <itemizedlist>
+            <listitem>
+              <para>
+                                                               <literal>"all"</literal>: URL(s) to remove are searched in both
+                                                               "user" and "allusers" sections.
+                                                       </para>
+            </listitem>
+            <listitem>
+              <para>
+                                                               <literal>"allusers"</literal>: URL(s) to remove are only searched in
+                                                               the "allusers" section.
+                                                       </para>
+            </listitem>
+            <listitem>
+              <para>
+                                                               <literal>"user"</literal>: URL(s) to remove are only searched in
+                                                               the "user" section.
+                                                       </para>
+            </listitem>
+          </itemizedlist>
+                                       <para>
+                                               If SCI is write accessible, "all" is the default value.
+                                               Otherwise, the default value is "user".
                                        </para>
         </listitem>
-      </varlistentry>
+                       </varlistentry>
+                       
       <varlistentry>
         <term>nbDel</term>
         <listitem>
     <title>Examples</title>
     <programlisting role="example"><![CDATA[ 
 atomsRepositoryList()
-atomsRepositoryAdd(["http://scene1.test.atoms.scilab.org")
+atomsRepositoryAdd("http://scene1.test.atoms.scilab.org")
 atomsRepositoryList()
-atomsRepositoryDel(["http://scene1.test.atoms.scilab.org")
+atomsRepositoryDel("http://scene1.test.atoms.scilab.org")
 atomsRepositoryList()
  ]]></programlisting>
   </refsection>
index d624feb..944fe5a 100644 (file)
@@ -21,8 +21,7 @@
   <refsynopsisdiv>
     <title>Calling Sequence</title>
     <synopsis>
-                       repositories = atomsRepositoryList()
-                       repositories = atomsRepositoryList(level)
+                       repositories = atomsRepositoryList([section])
                </synopsis>
   </refsynopsisdiv>
   <!-- ===================================================================== -->
   <refsection>
     <title>Parameters</title>
     <variablelist>
-      <varlistentry>
-        <term>level</term>
+                       <varlistentry>
+        <term>section</term>
         <listitem>
           <para>
-                                               Character string : Filter the output matrix according to repositories
-                                               are officials, have been added for all users or have been added for the
-                                               current user.
+                                               This argument controls the list of section where search URL(s).
+                                       </para>
+          <para>
+                                               <literal>section</literal> is a single-string and its value should be :
+                                       </para>
+          <itemizedlist>
+            <listitem>
+              <para>
+                                                               <literal>"all"</literal>: URL(s) present in the "user", "allusers"
+                                                               and "official" section are listed.
+                                                       </para>
+            </listitem>
+            <listitem>
+              <para>
+                                                               <literal>"allusers"</literal>: only URL(s) present in the "allusers"
+                                                               section are listed.
+                                                       </para>
+            </listitem>
+            <listitem>
+              <para>
+                                                               <literal>"user"</literal>: only URL(s) present in the "user"
+                                                               section are listed.
+                                                       </para>
+            </listitem>
+            <listitem>
+              <para>
+                                                               <literal>"official"</literal>: only URL(s) present in the "official"
+                                                               section are listed.
+                                                       </para>
+            </listitem>
+          </itemizedlist>
+                                       <para>
+                                               The default value is "all".
                                        </para>
         </listitem>
-      </varlistentry>
+                       </varlistentry>
       <varlistentry>
         <term>repositories</term>
         <listitem>
   <!-- ===================================================================== -->
   <refsection>
     <title>Examples</title>
-    <programlisting role="example"><![CDATA[ 
+    <programlisting role="example"><![CDATA[
+atomsRepositoryAdd('http://scene1.atoms.scilab.org');
 atomsRepositoryList()
+atomsRepositoryList('all')
 atomsRepositoryList('official')
 atomsRepositoryList('allusers')
 atomsRepositoryList('user')
+atomsRepositoryDel('http://scene1.atoms.scilab.org');
  ]]></programlisting>
   </refsection>
   <!-- ===================================================================== -->
index df0f326..707d309 100644 (file)
@@ -9,7 +9,7 @@
 
 // Add an URL to the list of repositories, and returns
 
-function nbAdd = atomsRepositoryAdd(url,allusers)
+function nbAdd = atomsRepositoryAdd(url,section)
        
        // Load Atoms Internals lib if it's not already loaded
        // =========================================================================
@@ -44,35 +44,45 @@ function nbAdd = atomsRepositoryAdd(url,allusers)
                end
        end
        
-       // Apply changes for all users or just for me ?
+       // Allusers/user management
+       //   - If section is equal to "allusers", The repository will added for all users
+       //       → SCI/.atoms  : ATOMS system files
+       //   -  If section is equal to "user", The repository will added only for the current user
+       //       → SCIHOME/atoms : location of the modules & ATOMS system files
        // =========================================================================
        
-       if rhs == 1 then
-               // By default, add the repository for all users (if we have write access
-               // of course !)
+       if rhs <= 1 then
                if atomsAUWriteAccess() then
-                       allusers = %T; 
+                       section = "allusers"; 
                else
-                       allusers = %F;
+                       section = "user";
                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"),"atomsRepositoryDel",2));
+               
+               // Process the 2nd input argument : section
+               // Allusers can be equal to "user" or "allusers"
+               
+               if type(section) <> 10 then
+                       error(msprintf(gettext("%s: Wrong type for input argument #%d: A single-string expected.\n"),"atomsRepositoryAdd",2));
+               end
+               
+               if and(section<>["user","allusers"]) then
+                       error(msprintf(gettext("%s: Wrong value for input argument #%d: ''user'' or ''allusers'' expected.\n"),"atomsRepositoryAdd",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"),"atomsRepositoryDel",2,pathconvert(SCI+"/.atoms")));
+               if (section=="allusers") & ~atomsAUWriteAccess() then
+                       error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsRepositoryAdd",2,pathconvert(SCI+"/.atoms")));
                end
+               
        end
        
        // Define the path of the file that will record the change according to
-       // the "allusers" value
+       // the "section" value
        // =========================================================================
        
-       if allusers then
+       if section=="allusers" then
                atoms_directory = pathconvert(SCI+"/.atoms");
        else
                atoms_directory = pathconvert(SCIHOME+"/atoms");
index db8ea93..4bdbf61 100644 (file)
@@ -9,7 +9,7 @@
 
 // Remove an URL to the list of repositories, and returns
 
-function nbDel = atomsRepositoryDel(url,allusers)
+function nbDel = atomsRepositoryDel(url,section)
        
        // Load Atoms Internals lib if it's not already loaded
        // =========================================================================
@@ -34,42 +34,62 @@ function nbDel = atomsRepositoryDel(url,allusers)
                error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsRepositoryDel",1));
        end
        
-       // Apply changes for all users or just for me ?
+       // Allusers/user management
+       //
+       //   - If section is equal to "all", The repository to remove is searched in 
+       //     both "user" and "allusers" sections
+       //       → SCI/.atoms
+       //       → SCIHOME/atoms
+       //
+       //   - If section is equal to "allusers", The repository to remove is searched
+       //     only in the "allusers" section
+       //       → SCI/.atoms
+       //
+       //   - If section is equal to "user", The repository to remove is searched
+       //     only in the "user" section
+       //        → SCIHOME/atoms
        // =========================================================================
        
        if rhs == 1 then
                // By default, add the repository for all users (if we have write access
                // of course !)
                if atomsAUWriteAccess() then
-                       allusers = %T; 
+                       section = "all"; 
                else
-                       allusers = %F;
+                       section = "user";
                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"),"atomsRepositoryDel",2));
+               if type(section) <> 10 then
+                       error(msprintf(gettext("%s: Wrong type for input argument #%d: A single-string expected.\n"),"atomsRepositoryDel",2));
+               end
+               
+               if and(section<>["user","allusers","all"]) then
+                       error(msprintf(gettext("%s: Wrong value for input argument #%d: ''user'' or ''allusers'' or ''all'' expected.\n"),"atomsRepositoryDel",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"),"atomsRepositoryDel",2,pathconvert(SCI+"/.atoms")));
+               if or(section==["all","allusers"]) & ~ atomsAUWriteAccess() then
+                       error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsRepositoryDel",pathconvert(SCI+"/.atoms")));
                end
+               
        end
        
        // Define the path of the files that will record the change according to
-       // the "allusers" value and the existence of the latter
+       // the "section" value and the existence of the latter
        // =========================================================================
        
-       atoms_files = [];
+       if section=="all" then
+               atoms_files = [ pathconvert(SCIHOME+"/atoms/repositories",%F) ; pathconvert(SCI+"/.atoms/repositories",%F) ];
        
-       if fileinfo( pathconvert(SCIHOME+"/atoms/repositories",%F) )<> [] then
-               atoms_files = [ atoms_files ; pathconvert(SCIHOME+"/atoms/repositories",%F) ];
-       end
+       elseif section=="allusers" then
+               atoms_files = [ pathconvert(SCI+"/.atoms/repositories",%F) ];
+               
+       elseif section=="user" then
+               atoms_files = [ pathconvert(SCIHOME+"/atoms/repositories",%F)  ];
        
-       if allusers & (fileinfo( pathconvert(SCI+"/.atoms/repositories",%F) )<>[]) then
-               atoms_files = [ atoms_files ; pathconvert(SCI+"/.atoms/repositories",%F) ];
+       else
+               atoms_files = [];
        end
        
        // Loop on each repositories file specified as first input argument
@@ -77,6 +97,10 @@ function nbDel = atomsRepositoryDel(url,allusers)
        
        for i=1:size(atoms_files,"*")
                
+               if fileinfo(atoms_files(i)) == [] then
+                       continue;
+               end
+               
                // Get the URLs list in this file
                repositories = mgetl(atoms_files(i));
                
index 83a97a9..ee3d9b4 100644 (file)
@@ -9,7 +9,7 @@
 
 // get the list of repositories
 
-function repositories = atomsRepositoryList(level)
+function repositories = atomsRepositoryList(section)
        
        // Load Atoms Internals lib if it's not already loaded
        // =========================================================================
@@ -30,22 +30,29 @@ function repositories = atomsRepositoryList(level)
        // Check input argument type (if any)
        // =========================================================================
        
-       if (rhs==1) & (type(level) <> 10) then
+       if (rhs==1) & (type(section) <> 10) then
                error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsRepositoryList",1));
        end
        
        // Check input argument dimension (if any)
        // =========================================================================
        
-       if (rhs==1) & (size(level,"*")<>1) then
+       if (rhs==1) & (size(section,"*")<>1) then
                error(msprintf(gettext("%s: Wrong size for input argument #%d: Single string expected.\n"),"atomsRepositoryList",1));
        end
        
        // Check input argument values (if any)
        // =========================================================================
        
-       if (rhs==1) & (and(level<>["user","allusers","official"])) then
-               error(msprintf(gettext("%s: Wrong value for input argument #%d: ''user'',''allusers'' or ''official'' expected.\n"),"atomsRepositoryList",1));
+       if (rhs==1) & (and(section<>["all","user","allusers","official"])) then
+               error(msprintf(gettext("%s: Wrong value for input argument #%d: ''all'',''user'',''allusers'' or ''official'' expected.\n"),"atomsRepositoryList",1));
+       end
+       
+       // Default value of section
+       // =========================================================================
+       
+       if rhs==0 then
+               section = "all";
        end
        
        // Define the needed paths
@@ -58,7 +65,7 @@ function repositories = atomsRepositoryList(level)
        // official repositories
        // =========================================================================
        
-       if (rhs == 0) | ((rhs == 1) & (level == "official")) then
+       if or(section == ["all";"official"]) then
                if fileinfo(official_repositories) <> [] then
                        url_list = mgetl(official_repositories);
                        for i=1:size(url_list,"*")
@@ -70,7 +77,7 @@ function repositories = atomsRepositoryList(level)
        // All users repositories
        // =========================================================================
        
-       if (rhs == 0) | ((rhs == 1) & (level == "allusers")) then
+       if or(section == ["all";"allusers"]) then
                if fileinfo(allusers_repositories) <> [] then
                        url_list = mgetl(allusers_repositories);
                        for i=1:size(url_list,"*")
@@ -82,7 +89,7 @@ function repositories = atomsRepositoryList(level)
        // User repositories
        // =========================================================================
        
-       if (rhs == 0) | ((rhs == 1) & (level == "user")) then
+       if or(section == ["all";"user"]) then
                if fileinfo(user_repositories) <> [] then
                        url_list = mgetl(user_repositories);
                        for i=1:size(url_list,"*")
diff --git a/scilab/modules/atoms/tests/unit_tests/atomsRepositoryAdd.dia.ref b/scilab/modules/atoms/tests/unit_tests/atomsRepositoryAdd.dia.ref
new file mode 100644 (file)
index 0000000..273b01e
--- /dev/null
@@ -0,0 +1,30 @@
+// =============================================================================
+// 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 isempty([ atomsRepositoryList("user") ; atomsRepositoryList("allusers")]) then
+       
+       rep1 = "http://scene1.test.atoms.scilab.org";
+       rep2 = "http://scene2.test.atoms.scilab.org";
+       
+       if atomsRepositoryAdd(rep1,"user")     <> 1 then bugmes();quit;end
+       if atomsRepositoryAdd(rep2,"allusers") <> 1 then bugmes();quit;end
+       
+       if or(atomsRepositoryList("user")     <> [rep1,"user"]) then bugmes();quit;end
+       if or(atomsRepositoryList("allusers") <> [rep2,"allusers"]) then bugmes();quit;end
+       
+       if find( atomsRepositoryList("all") == [rep1]) == [] then bugmes();quit;end
+       if find( atomsRepositoryList("all") == [rep2]) == [] then bugmes();quit;end
+       
+       if atomsRepositoryDel(rep1,"user") <> 1 then bugmes();quit;end
+       if atomsRepositoryDel(rep2,"allusers") <> 1 then bugmes();quit;end
+       
+       if atomsRepositoryAdd( [rep1;rep2],"user") <> 2 then bugmes();quit;end
+       if or(atomsRepositoryList("user")     <> [rep1 "user";rep2 "user"]) then bugmes();quit;end
+       if or(atomsRepositoryList("allusers") <> []) then bugmes();quit;end
+       if atomsRepositoryDel([rep1;rep2],"user") <> 2 then bugmes();quit;end
+       
+end
diff --git a/scilab/modules/atoms/tests/unit_tests/atomsRepositoryAdd.tst b/scilab/modules/atoms/tests/unit_tests/atomsRepositoryAdd.tst
new file mode 100644 (file)
index 0000000..e372f69
--- /dev/null
@@ -0,0 +1,32 @@
+// =============================================================================
+// 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 isempty([ atomsRepositoryList("user") ; atomsRepositoryList("allusers")]) then
+       
+       rep1 = "http://scene1.test.atoms.scilab.org";
+       rep2 = "http://scene2.test.atoms.scilab.org";
+       
+       if atomsRepositoryAdd(rep1,"user")     <> 1 then pause, end
+       if atomsRepositoryAdd(rep2,"allusers") <> 1 then pause, end
+       
+       if or(atomsRepositoryList("user")     <> [rep1,"user"]) then pause, end
+       if or(atomsRepositoryList("allusers") <> [rep2,"allusers"]) then pause, end
+       
+       if find( atomsRepositoryList("all") == [rep1]) == [] then pause, end
+       if find( atomsRepositoryList("all") == [rep2]) == [] then pause, end
+       
+       if atomsRepositoryDel(rep1,"user") <> 1 then pause, end
+       if atomsRepositoryDel(rep2,"allusers") <> 1 then pause, end
+       
+       if atomsRepositoryAdd( [rep1;rep2],"user") <> 2 then pause, end
+       if or(atomsRepositoryList("user")     <> [rep1 "user";rep2 "user"]) then pause, end
+       if or(atomsRepositoryList("allusers") <> []) then pause, end
+       if atomsRepositoryDel([rep1;rep2],"user") <> 2 then pause, end
+       
+end