3 # Copyright (C) 2010-2012 CEA/DEN
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 # Define all possible option for the shell command : sat base <options>
24 parser = src.options.Options()
25 parser.add_option('s', 'set', 'string', 'base_path',
26 _('The path directory to use as base.'), None)
28 def set_base(config, path, site_file_path, logger):
29 # Update the site.pyconf file
31 site_pyconf_cfg = src.pyconf.Config(site_file_path)
32 site_pyconf_cfg.SITE.base = str(path)
33 ff = open(site_file_path, 'w')
34 site_pyconf_cfg.__save__(ff, 1)
36 config.SITE.base = str(path)
37 except Exception as e:
39 msg = _("Unable to update the site.pyconf file: %s\n" % err)
43 display_base_path(config, logger)
48 def display_base_path(config, logger):
49 info = [(_("Base path"), config.SITE.base)]
50 src.print_info(logger, info)
53 '''method that is called when salomeTools is called with --help option.
55 :return: The text to display for the base command description.
58 return _("Display or set the base where to put installations of base "
61 def run(args, runner, logger):
62 '''method that is called when salomeTools is called with base parameter.
66 (options, args) = parser.parse_args(args)
68 # Get the path to the site.pyconf file that contain the base path
69 site_file_path = os.path.join(runner.cfg.VARS.salometoolsway,
73 # If the option set is passed
76 path = src.Path(options.base_path)
78 # If it is a file, do nothing and return error
80 msg = _("Error: The given path is a file. Please provide a path to "
82 logger.write(src.printcolors.printcError(msg), 1)
85 # If it is an existing directory, set the base to it
86 if path.exists() and path.isdir():
87 # Set the base in the site.pyconf file
88 res = set_base(runner.cfg, path, site_file_path, logger)
91 # Try to create the given path
93 src.ensure_path_exists(str(path))
94 except Exception as e:
95 err = src.printcolors.printcError(str(e))
96 msg = _("Unable to create the directory %s: %s\n" % (str(path),
101 # Set the base in the site.pyconf file
102 res = set_base(runner.cfg, path, site_file_path, logger)
105 # Display the base that is in the site.pyconf file
106 display_base_path(runner.cfg, logger)
107 if not options.base_path:
108 logger.write(_("To change the value of the base path, use the --set"