1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution. The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 // Add an URL to the list of repositories, and returns
14 function nbAdd = atomsRepositoryAdd(url,section)
16 // Load Atoms Internals lib if it's not already loaded
17 // =========================================================================
18 if ~ exists("atomsinternalslib") then
19 load("SCI/modules/atoms/macros/atoms_internals/lib");
22 // Check write access on allusers zone
23 // =========================================================================
24 ATOMSALLUSERSWRITEACCESS = atomsAUWriteAccess();
28 repositories = []; // Column vector that contains user repositories
29 currentRepositories = atomsRepositoryList();
30 currentRepositories = currentRepositories(:,1);
31 valid_url_pattern = "/^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\:\/\/)?([a-zA-Z0-9]+)([\.][a-zA-Z0-9\-]+)*(\:[0-9]{1,5})*(\/($|[a-zA-Z0-9\.\,\;\?\''\\\+&%\$#\=~_\-]+))*$/";
33 // Check number of input arguments
34 // =========================================================================
36 if rhs < 1 | rhs > 2 then
37 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsRepositoryAdd",1,2));
40 // Check URLs specified as first input argument
41 // =========================================================================
43 if type(url) <> 10 then
44 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsRepositoryAdd",1));
48 if (part(url(i),1:7) <> "file://") & (~ regexp(url(i),valid_url_pattern,"o") == 1) then
49 error(msprintf(gettext("%s: Wrong value for input argument #%d: This ("+url(i)+") is not a valid URL.\n"),"atomsRepositoryAdd",1));
53 // Allusers/user management
54 // - If section is equal to "allusers", The repository will added for all users
55 // → SCI/.atoms : ATOMS system files
56 // - If section is equal to "user", The repository will added only for the current user
57 // → SCIHOME/atoms : location of the modules & ATOMS system files
58 // =========================================================================
61 if ATOMSALLUSERSWRITEACCESS then
69 // Process the 2nd input argument : section
70 // Allusers can be equal to "user" or "allusers"
72 if type(section) <> 10 then
73 error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsRepositoryAdd",2));
76 if and(section<>["user","allusers"]) then
77 error(msprintf(gettext("%s: Wrong value for input argument #%d: ''user'' or ''allusers'' expected.\n"),"atomsRepositoryAdd",2));
80 // Check if we have the write access
81 if (section=="allusers") & ~ATOMSALLUSERSWRITEACCESS then
82 error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsRepositoryAdd",2,pathconvert(SCI+"/.atoms")));
87 // Define the path of the file that will record the change according to
88 // the "section" value
89 // =========================================================================
91 atoms_directory = atomsPath("system",section);
93 // Does the atoms_directory exist, if not create it
94 // =========================================================================
96 if ~ isdir(atoms_directory) then
97 mkdir(atoms_directory);
100 // Does the SCIHOME/atoms/repositories exist, if yes load it
101 // =========================================================================
103 if fileinfo(atoms_directory+"repositories") <> [] then
104 repositories = mgetl(atoms_directory+"repositories");
107 // Loop on each URL specified as input argument
108 // =========================================================================
110 for i=1:size(url,"*")
111 // Add the URL only if it doesn't already exist
112 if find( currentRepositories == url(i) ) == [] then
113 repositories = [ repositories ; url(i) ];
119 // =========================================================================
123 mputl(repositories, atoms_directory+"repositories");
125 // Force reload the different distant TOOLBOXES files
126 atomsDESCRIPTIONget(%T);