Salome HOME
completion for info option and improve code
[tools/sat.git] / commands / config.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
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.
9 #
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.
14 #
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
18
19 import os
20 import platform
21 import datetime
22 import shutil
23 import gettext
24 import sys
25
26 import src
27
28 # internationalization
29 satdir  = os.path.dirname(os.path.realpath(__file__))
30 gettext.install('salomeTools', os.path.join(satdir, 'src', 'i18n'))
31
32 # Define all possible option for config command :  sat config <options>
33 parser = src.options.Options()
34 parser.add_option('v', 'value', 'string', 'value',
35     _("print the value of CONFIG_VARIABLE."))
36 parser.add_option('e', 'edit', 'boolean', 'edit',
37     _("edit the product configuration file."))
38 parser.add_option('i', 'info', 'string', 'info',
39     _("get information on a product."))
40 parser.add_option('l', 'list', 'boolean', 'list',
41     _("list all available applications."))
42 parser.add_option('c', 'copy', 'boolean', 'copy',
43     _("""copy a config file to the personnal config files directory.
44 \tWARNING the included files are not copied.
45 \tIf a name is given the new config file takes the given name."""))
46 parser.add_option('n', 'no_label', 'boolean', 'no_label',
47     _("do not print labels, Works only with --value and --list."))
48 parser.add_option('s', 'schema', 'boolean', 'schema',
49     _("Internal use."))
50
51 class ConfigOpener:
52     '''Class that helps to find an application pyconf 
53        in all the possible directories (pathList)
54     '''
55     def __init__(self, pathList):
56         '''Initialization
57         
58         :param pathList list: The list of paths where to serach a pyconf.
59         '''
60         self.pathList = pathList
61
62     def __call__(self, name):
63         if os.path.isabs(name):
64             return src.pyconf.ConfigInputStream(open(name, 'rb'))
65         else:
66             return src.pyconf.ConfigInputStream( 
67                         open(os.path.join( self.get_path(name), name ), 'rb') )
68         raise IOError(_("Configuration file '%s' not found") % name)
69
70     def get_path( self, name ):
71         '''The method that returns the entire path of the pyconf searched
72         :param name str: The name of the searched pyconf.
73         '''
74         for path in self.pathList:
75             if os.path.exists(os.path.join(path, name)):
76                 return path
77         raise IOError(_("Configuration file '%s' not found") % name)
78
79 class ConfigManager:
80     '''Class that manages the read of all the configuration files of salomeTools
81     '''
82     def __init__(self, datadir=None):
83         pass
84
85     def _create_vars(self, application=None, command=None, datadir=None):
86         '''Create a dictionary that stores all information about machine,
87            user, date, repositories, etc...
88         
89         :param application str: The application for which salomeTools is called.
90         :param command str: The command that is called.
91         :param datadir str: The repository that contain external data 
92                             for salomeTools.
93         :return: The dictionary that stores all information.
94         :rtype: dict
95         '''
96         var = {}      
97         var['user'] = src.architecture.get_user()
98         var['salometoolsway'] = os.path.dirname(
99                                     os.path.dirname(os.path.abspath(__file__)))
100         var['srcDir'] = os.path.join(var['salometoolsway'], 'src')
101         var['sep']= os.path.sep
102         
103         # datadir has a default location
104         var['datadir'] = os.path.join(var['salometoolsway'], 'data')
105         if datadir is not None:
106             var['datadir'] = datadir
107
108         var['personalDir'] = os.path.join(os.path.expanduser('~'),
109                                            '.salomeTools')
110
111         # read linux distributions dictionary
112         distrib_cfg = src.pyconf.Config(os.path.join(var['srcDir'],
113                                                       'internal_config',
114                                                       'distrib.pyconf'))
115         
116         # set platform parameters
117         dist_name = src.architecture.get_distribution(
118                                             codes=distrib_cfg.DISTRIBUTIONS)
119         dist_version = src.architecture.get_distrib_version(dist_name, 
120                                                     codes=distrib_cfg.VERSIONS)
121         dist = dist_name + dist_version
122         
123         var['dist_name'] = dist_name
124         var['dist_version'] = dist_version
125         var['dist'] = dist
126         var['python'] = src.architecture.get_python_version()
127
128         var['nb_proc'] = src.architecture.get_nb_proc()
129         node_name = platform.node()
130         var['node'] = node_name
131         var['hostname'] = node_name
132
133         # set date parameters
134         dt = datetime.datetime.now()
135         var['date'] = dt.strftime('%Y%m%d')
136         var['datehour'] = dt.strftime('%Y%m%d_%H%M%S')
137         var['hour'] = dt.strftime('%H%M%S')
138
139         var['command'] = str(command)
140         var['application'] = str(application)
141
142         # Root dir for temporary files 
143         var['tmp_root'] = os.sep + 'tmp' + os.sep + var['user']
144         # particular win case 
145         if src.architecture.is_windows() : 
146             var['tmp_root'] =  os.path.expanduser('~') + os.sep + 'tmp'
147         
148         return var
149
150     def get_command_line_overrides(self, options, sections):
151         '''get all the overwrites that are in the command line
152         
153         :param options: the options from salomeTools class 
154                         initialization (like -l5 or --overwrite)
155         :param sections str: The config section to overwrite.
156         :return: The list of all the overwrites to apply.
157         :rtype: list
158         '''
159         # when there are no options or not the overwrite option, 
160         # return an empty list
161         if options is None or options.overwrite is None:
162             return []
163         
164         over = []
165         for section in sections:
166             # only overwrite the sections that correspond to the option 
167             over.extend(filter(lambda l: l.startswith(section + "."), 
168                                options.overwrite))
169         return over
170
171     def get_config(self, application=None, options=None, command=None,
172                     datadir=None):
173         '''get the config from all the configuration files.
174         
175         :param application str: The application for which salomeTools is called.
176         :param options class Options: The general salomeToos
177                                       options (--overwrite or -l5, for example)
178         :param command str: The command that is called.
179         :param datadir str: The repository that contain 
180                             external data for salomeTools.
181         :return: The final config.
182         :rtype: class 'src.pyconf.Config'
183         '''        
184         
185         # create a ConfigMerger to handle merge
186         merger = src.pyconf.ConfigMerger()#MergeHandler())
187         
188         # create the configuration instance
189         cfg = src.pyconf.Config()
190         
191         # =====================================================================
192         # create VARS section
193         var = self._create_vars(application=application, command=command, 
194                                 datadir=datadir)
195         # add VARS to config
196         cfg.VARS = src.pyconf.Mapping(cfg)
197         for variable in var:
198             cfg.VARS[variable] = var[variable]
199         
200         # apply overwrite from command line if needed
201         for rule in self.get_command_line_overrides(options, ["VARS"]):
202             exec('cfg.' + rule) # this cannot be factorized because of the exec
203         
204         # =====================================================================
205         # Load INTERNAL config
206         # read src/internal_config/salomeTools.pyconf
207         src.pyconf.streamOpener = ConfigOpener([
208                             os.path.join(cfg.VARS.srcDir, 'internal_config')])
209         try:
210             internal_cfg = src.pyconf.Config(open(os.path.join(cfg.VARS.srcDir, 
211                                     'internal_config', 'salomeTools.pyconf')))
212         except src.pyconf.ConfigError as e:
213             raise src.SatException(_("Error in configuration file:"
214                                      " salomeTools.pyconf\n  %(error)s") % \
215                                    {'error': str(e) })
216         
217         merger.merge(cfg, internal_cfg)
218
219         # apply overwrite from command line if needed
220         for rule in self.get_command_line_overrides(options, ["INTERNAL"]):
221             exec('cfg.' + rule) # this cannot be factorized because of the exec        
222         
223         # =====================================================================
224         # Load SITE config file
225         # search only in the data directory
226         src.pyconf.streamOpener = ConfigOpener([cfg.VARS.datadir])
227         try:
228             site_cfg = src.pyconf.Config(open(os.path.join(cfg.VARS.datadir, 
229                                                            'site.pyconf')))
230         except src.pyconf.ConfigError as e:
231             raise src.SatException(_("Error in configuration file: "
232                                      "site.pyconf\n  %(error)s") % \
233                 {'error': str(e) })
234         except IOError as error:
235             e = str(error)
236             if "site.pyconf" in e :
237                 e += ("\nYou can copy data"
238                   + cfg.VARS.sep
239                   + "site.template.pyconf to data"
240                   + cfg.VARS.sep 
241                   + "site.pyconf and edit the file")
242             raise src.SatException( e );
243         
244         # add user local path for configPath
245         site_cfg.SITE.config.config_path.append(
246                         os.path.join(cfg.VARS.personalDir, 'Applications'), 
247                         "User applications path")
248         
249         merger.merge(cfg, site_cfg)
250
251         # apply overwrite from command line if needed
252         for rule in self.get_command_line_overrides(options, ["SITE"]):
253             exec('cfg.' + rule) # this cannot be factorized because of the exec
254   
255         
256         # =====================================================================
257         # Load APPLICATION config file
258         if application is not None:
259             # search APPLICATION file in all directories in configPath
260             cp = cfg.SITE.config.config_path
261             src.pyconf.streamOpener = ConfigOpener(cp)
262             try:
263                 application_cfg = src.pyconf.Config(application + '.pyconf')
264             except IOError as e:
265                 raise src.SatException(_("%s, use 'config --list' to get the"
266                                          " list of available applications.") %e)
267             except src.pyconf.ConfigError as e:
268                 raise src.SatException(_("Error in configuration file:"
269                                 " %(application)s.pyconf\n  %(error)s") % \
270                     { 'application': application, 'error': str(e) } )
271
272             merger.merge(cfg, application_cfg)
273
274             # apply overwrite from command line if needed
275             for rule in self.get_command_line_overrides(options,
276                                                          ["APPLICATION"]):
277                 # this cannot be factorized because of the exec
278                 exec('cfg.' + rule)
279                 
280             # default launcher name ('salome')
281             if ('profile' in cfg.APPLICATION and 
282                 'launcher_name' not in cfg.APPLICATION.profile):
283                 cfg.APPLICATION.profile.launcher_name = 'salome'
284         
285         # =====================================================================
286         # Load product config files in PRODUCTS section
287        
288         # The directory containing the softwares definition
289         products_dir = os.path.join(cfg.VARS.datadir, 'products')
290         
291         # Loop on all files that are in softsDir directory
292         # and read their config
293         for fName in os.listdir(products_dir):
294             if fName.endswith(".pyconf"):
295                 src.pyconf.streamOpener = ConfigOpener([products_dir])
296                 try:
297                     prod_cfg = src.pyconf.Config(open(
298                                                 os.path.join(products_dir, fName)))
299                 except src.pyconf.ConfigError as e:
300                     raise src.SatException(_(
301                         "Error in configuration file: %(prod)s\n  %(error)s") % \
302                         {'prod' :  fName, 'error': str(e) })
303                 except IOError as error:
304                     e = str(error)
305                     raise src.SatException( e );
306                 except Exception as e:
307                     raise src.SatException(_(
308                         "Error in configuration file: %(prod)s\n  %(error)s") % \
309                         {'prod' :  fName, 'error': str(e) })
310                 
311                 merger.merge(cfg.PRODUCTS, prod_cfg)
312
313         # apply overwrite from command line if needed
314         for rule in self.get_command_line_overrides(options, ["PRODUCTS"]):
315             exec('cfg.' + rule) # this cannot be factorized because of the exec
316
317         
318         # =====================================================================
319         # load USER config
320         self.set_user_config_file(cfg)
321         user_cfg_file = self.get_user_config_file()
322         user_cfg = src.pyconf.Config(open(user_cfg_file))
323         merger.merge(cfg, user_cfg)
324
325         # apply overwrite from command line if needed
326         for rule in self.get_command_line_overrides(options, ["USER"]):
327             exec('cfg.' + rule) # this cannot be factorize because of the exec
328         
329         return cfg
330
331     def set_user_config_file(self, config):
332         '''Set the user config file name and path.
333         If necessary, build it from another one or create it from scratch.
334         
335         :param config class 'src.pyconf.Config': The global config 
336                                                  (containing all pyconf).
337         '''
338         # get the expected name and path of the file
339         self.config_file_name = 'salomeTools.pyconf'
340         self.user_config_file_path = os.path.join(config.VARS.personalDir,
341                                                    self.config_file_name)
342         
343         # if pyconf does not exist, create it from scratch
344         if not os.path.isfile(self.user_config_file_path): 
345             self.create_config_file(config)
346     
347     def create_config_file(self, config):
348         '''This method is called when there are no user config file. 
349            It build it from scratch.
350         
351         :param config class 'src.pyconf.Config': The global config.
352         :return: the config corresponding to the file created.
353         :rtype: config class 'src.pyconf.Config'
354         '''
355         
356         cfg_name = self.get_user_config_file()
357
358         user_cfg = src.pyconf.Config()
359         #
360         user_cfg.addMapping('USER', src.pyconf.Mapping(user_cfg), "")
361
362         #
363         user_cfg.USER.addMapping('workdir', os.path.expanduser('~'),
364             "This is where salomeTools will work. "
365             "You may (and probably do) change it.\n")
366         user_cfg.USER.addMapping('cvs_user', config.VARS.user,
367             "This is the user name used to access salome cvs base.\n")
368         user_cfg.USER.addMapping('svn_user', config.VARS.user,
369             "This is the user name used to access salome svn base.\n")
370         user_cfg.USER.addMapping('output_verbose_level', 3,
371             "This is the default output_verbose_level you want."
372             " 0=>no output, 5=>debug.\n")
373         user_cfg.USER.addMapping('publish_dir', 
374                                  os.path.join(os.path.expanduser('~'),
375                                  'websupport', 
376                                  'satreport'), 
377                                  "")
378         user_cfg.USER.addMapping('editor',
379                                  'vi', 
380                                  "This is the editor used to "
381                                  "modify configuration files\n")
382         user_cfg.USER.addMapping('browser', 
383                                  'firefox', 
384                                  "This is the browser used to "
385                                  "read html documentation\n")
386         user_cfg.USER.addMapping('pdf_viewer', 
387                                  'evince', 
388                                  "This is the pdf_viewer used "
389                                  "to read pdf documentation\n")
390         user_cfg.USER.addMapping("bases",
391                                  src.pyconf.Mapping(user_cfg.USER),
392                                  "The products installation base(s)\n")
393         
394         user_cfg.USER.bases.base = src.pyconf.Reference(
395                                             user_cfg,
396                                             src.pyconf.DOLLAR,
397                                             'workdir  + $VARS.sep + "BASE"')
398         # 
399         src.ensure_path_exists(config.VARS.personalDir)
400         src.ensure_path_exists(os.path.join(config.VARS.personalDir, 
401                                             'Applications'))
402
403         f = open(cfg_name, 'w')
404         user_cfg.__save__(f)
405         f.close()
406         print(_("You can edit it to configure salomeTools "
407                 "(use: sat config --edit).\n"))
408
409         return user_cfg   
410
411     def get_user_config_file(self):
412         '''Get the user config file
413         :return: path to the user config file.
414         :rtype: str
415         '''
416         if not self.user_config_file_path:
417             raise src.SatException(_("Error in get_user_config_file: "
418                                      "missing user config file path"))
419         return self.user_config_file_path     
420
421 def check_path(path, ext=[]):
422     '''Construct a text with the input path and "not found" if it does not
423        exist.
424     
425     :param path Str: the path to check.
426     :param ext List: An extension. Verify that the path extension 
427                      is in the list
428     :return: The string of the path with information
429     :rtype: Str
430     '''
431     # check if file exists
432     if not os.path.exists(path):
433         return "'%s'" % path + " " + src.printcolors.printcError(_(
434                                                             "** not found"))
435
436     # check extension
437     if len(ext) > 0:
438         fe = os.path.splitext(path)[1].lower()
439         if fe not in ext:
440             return "'%s'" % path + " " + src.printcolors.printcError(_(
441                                                         "** bad extension"))
442
443     return path
444
445 def show_product_info(config, name, logger):
446     '''Display on the terminal and logger information about a product.
447     
448     :param config Config: the global configuration.
449     :param name Str: The name of the product
450     :param logger Logger: The logger instance to use for the display
451     '''
452     
453     logger.write(_("%s is a product\n") % src.printcolors.printcLabel(name), 2)
454     pinfo = src.product.get_product_config(config, name)
455     
456     # Type of the product
457     ptype = src.get_cfg_param(pinfo, "type", "")
458     src.printcolors.print_value(logger, "type", ptype, 2)
459     if "opt_depend" in pinfo:
460         src.printcolors.print_value(logger, 
461                                     "depends on", 
462                                     ', '.join(pinfo.depend), 2)
463
464     if "opt_depend" in pinfo:
465         src.printcolors.print_value(logger, 
466                                     "optional", 
467                                     ', '.join(pinfo.opt_depend), 2)
468
469     # information on prepare
470     logger.write("\n", 2)
471     logger.write(src.printcolors.printcLabel("prepare:") + "\n", 2)
472
473     is_dev = src.product.product_is_dev(pinfo)
474     method = pinfo.get_source
475     if is_dev:
476         method += " (dev)"
477     src.printcolors.print_value(logger, "get method", method, 2)
478
479     if method == 'cvs':
480         src.printcolors.print_value(logger, "server", pinfo.cvs_info.server, 2)
481         src.printcolors.print_value(logger, "base module",
482                                     pinfo.cvs_info.module_base, 2)
483         src.printcolors.print_value(logger, "source", pinfo.cvs_info.source, 2)
484         src.printcolors.print_value(logger, "tag", pinfo.cvs_info.tag, 2)
485
486     elif method == 'svn':
487         src.printcolors.print_value(logger, "repo", pinfo.svn_info.repo, 2)
488
489     elif method == 'git':
490         src.printcolors.print_value(logger, "repo", pinfo.git_info.repo, 2)
491         src.printcolors.print_value(logger, "tag", pinfo.git_info.tag, 2)
492
493     elif method == 'archive':
494         src.printcolors.print_value(logger, 
495                                     "get from", 
496                                     check_path(pinfo.archive_info.archive_name), 
497                                     2)
498
499     if 'patches' in pinfo:
500         for patch in pinfo.patches:
501             src.printcolors.print_value(logger, "patch", check_path(patch), 2)
502
503     if src.product.product_is_fixed(pinfo):
504         src.printcolors.print_value(logger, "install_dir", 
505                                     check_path(pinfo.install_dir), 2)
506
507     if src.product.product_is_native(pinfo) or src.product.product_is_fixed(pinfo):
508         return
509     
510     # information on compilation
511     logger.write("\n", 2)
512     logger.write(src.printcolors.printcLabel("compile:") + "\n", 2)
513     src.printcolors.print_value(logger, 
514                                 "compilation method", 
515                                 pinfo.build_source, 
516                                 2)
517     
518     if pinfo.build_source == "script" and "compil_script" in pinfo:
519         src.printcolors.print_value(logger, 
520                                     "Compilation script", 
521                                     pinfo.compil_script, 
522                                     2)
523     
524     if 'nb_proc' in pinfo:
525         src.printcolors.print_value(logger, "make -j", pinfo.nb_proc, 2)
526
527     src.printcolors.print_value(logger, 
528                                 "source dir", 
529                                 check_path(pinfo.source_dir), 
530                                 2)
531     if 'install_dir' in pinfo:
532         src.printcolors.print_value(logger, 
533                                     "build dir", 
534                                     check_path(pinfo.build_dir), 
535                                     2)
536         src.printcolors.print_value(logger, 
537                                     "install dir", 
538                                     check_path(pinfo.install_dir), 
539                                     2)
540     else:
541         logger.write("  " + 
542                      src.printcolors.printcWarning(_("no install dir")) + 
543                      "\n", 2)
544
545     # information on environment
546     logger.write("\n", 2)
547     logger.write(src.printcolors.printcLabel("environ :") + "\n", 2)
548     if "environ" in pinfo and "env_script" in pinfo.environ:
549         src.printcolors.print_value(logger, 
550                                     "script", 
551                                     check_path(pinfo.environ.env_script), 
552                                     2)
553
554     zz = src.environment.SalomeEnviron(config, 
555                                        src.fileEnviron.ScreenEnviron(logger), 
556                                        False)
557     zz.set_python_libdirs()
558     zz.set_a_product(name, logger)
559         
560     
561 def print_value(config, path, show_label, logger, level=0, show_full_path=False):
562     '''Prints a value from the configuration. Prints recursively the values 
563        under the initial path.
564     
565     :param config class 'src.pyconf.Config': The configuration 
566                                              from which the value is displayed.
567     :param path str : the path in the configuration of the value to print.
568     :param show_label boolean: if True, do a basic display. 
569                                (useful for bash completion)
570     :param logger Logger: the logger instance
571     :param level int: The number of spaces to add before display.
572     :param show_full_path :
573     '''            
574     
575     # Make sure that the path does not ends with a point
576     if path.endswith('.'):
577         path = path[:-1]
578     
579     # display all the path or not
580     if show_full_path:
581         vname = path
582     else:
583         vname = path.split('.')[-1]
584
585     # number of spaces before the display
586     tab_level = "  " * level
587     
588     # call to the function that gets the value of the path.
589     try:
590         val = config.getByPath(path)
591     except Exception as e:
592         logger.write(tab_level)
593         logger.write("%s: ERROR %s\n" % (src.printcolors.printcLabel(vname), 
594                                          src.printcolors.printcError(str(e))))
595         return
596
597     # in this case, display only the value
598     if show_label:
599         logger.write(tab_level)
600         logger.write("%s: " % src.printcolors.printcLabel(vname))
601
602     # The case where the value has under values, 
603     # do a recursive call to the function
604     if dir(val).__contains__('keys'):
605         if show_label: logger.write("\n")
606         for v in sorted(val.keys()):
607             print_value(config, path + '.' + v, show_label, logger, level + 1)
608     elif val.__class__ == src.pyconf.Sequence or isinstance(val, list): 
609         # in this case, value is a list (or a Sequence)
610         if show_label: logger.write("\n")
611         index = 0
612         for v in val:
613             print_value(config, path + "[" + str(index) + "]", 
614                         show_label, logger, level + 1)
615             index = index + 1
616     else: # case where val is just a str
617         logger.write("%s\n" % val)
618
619 def get_config_children(config, args):
620     '''Gets the names of the children of the given parameter.
621        Useful only for completion mechanism
622     
623     :param config Config: The configuration where to read the values
624     :param args: The path in the config from which get the keys
625     '''
626     vals = []
627     rootkeys = config.keys()
628     
629     if len(args) == 0:
630         # no parameter returns list of root keys
631         vals = rootkeys
632     else:
633         parent = args[0]
634         pos = parent.rfind('.')
635         if pos < 0:
636             # Case where there is only on key as parameter.
637             # For example VARS
638             vals = [m for m in rootkeys if m.startswith(parent)]
639         else:
640             # Case where there is a part from a key
641             # for example VARS.us  (for VARS.user)
642             head = parent[0:pos]
643             tail = parent[pos+1:]
644             try:
645                 a = config.getByPath(head)
646                 if dir(a).__contains__('keys'):
647                     vals = map(lambda x: head + '.' + x,
648                                [m for m in a.keys() if m.startswith(tail)])
649             except:
650                 pass
651
652     for v in sorted(vals):
653         sys.stdout.write("%s\n" % v)
654
655 def description():
656     '''method that is called when salomeTools is called with --help option.
657     
658     :return: The text to display for the config command description.
659     :rtype: str
660     '''
661     return _("The config command allows manipulation "
662              "and operation on config files.")
663     
664
665 def run(args, runner, logger):
666     '''method that is called when salomeTools is called with config parameter.
667     '''
668     # Parse the options
669     (options, args) = parser.parse_args(args)
670
671     # Only useful for completion mechanism : print the keys of the config
672     if options.schema:
673         get_config_children(runner.cfg, args)
674         return
675     
676     # case : print a value of the config
677     if options.value:
678         if options.value == ".":
679             # if argument is ".", print all the config
680             for val in sorted(runner.cfg.keys()):
681                 print_value(runner.cfg, val, not options.no_label, logger)
682         else:
683             print_value(runner.cfg, options.value, not options.no_label, logger, 
684                         level=0, show_full_path=False)
685     
686     # case : edit user pyconf file or application file
687     elif options.edit:
688         editor = runner.cfg.USER.editor
689         if 'APPLICATION' not in runner.cfg: # edit user pyconf
690             usercfg = os.path.join(runner.cfg.VARS.personalDir, 
691                                    'salomeTools.pyconf')
692             src.system.show_in_editor(editor, usercfg, logger)
693         else:
694             # search for file <application>.pyconf and open it
695             for path in runner.cfg.SITE.config.config_path:
696                 pyconf_path = os.path.join(path, 
697                                     runner.cfg.VARS.application + ".pyconf")
698                 if os.path.exists(pyconf_path):
699                     src.system.show_in_editor(editor, pyconf_path, logger)
700                     break
701     
702     # case : give information about the product in parameter
703     elif options.info:
704         src.check_config_has_application(runner.cfg)
705         if options.info in runner.cfg.APPLICATION.products:
706             show_product_info(runner.cfg, options.info, logger)
707             return
708         raise src.SatException(_("%(product_name)s is not a product "
709                                  "of %(application_name)s.") % 
710                                {'product_name' : options.info,
711                                 'application_name' : 
712                                 runner.cfg.VARS.application})
713     
714     # case : copy an existing <application>.pyconf 
715     # to ~/.salomeTools/Applications/LOCAL_<application>.pyconf
716     elif options.copy:
717         # product is required
718         src.check_config_has_application( runner.cfg )
719
720         # get application file path 
721         source = runner.cfg.VARS.application + '.pyconf'
722         source_full_path = ""
723         for path in runner.cfg.SITE.config.config_path:
724             # ignore personal directory
725             if path == runner.cfg.VARS.personalDir:
726                 continue
727             # loop on all directories that can have pyconf applications
728             zz = os.path.join(path, source)
729             if os.path.exists(zz):
730                 source_full_path = zz
731                 break
732
733         if len(source_full_path) == 0:
734             raise src.SatException(_(
735                         "Config file for product %s not found\n") % source)
736         else:
737             if len(args) > 0:
738                 # a name is given as parameter, use it
739                 dest = args[0]
740             elif 'copy_prefix' in runner.cfg.SITE.config:
741                 # use prefix
742                 dest = (runner.cfg.SITE.config.copy_prefix 
743                         + runner.cfg.VARS.application)
744             else:
745                 # use same name as source
746                 dest = runner.cfg.VARS.application
747                 
748             # the full path
749             dest_file = os.path.join(runner.cfg.VARS.personalDir, 
750                                      'Applications', dest + '.pyconf')
751             if os.path.exists(dest_file):
752                 raise src.SatException(_("A personal application"
753                                          " '%s' already exists") % dest)
754             
755             # perform the copy
756             shutil.copyfile(source_full_path, dest_file)
757             logger.write(_("%s has been created.\n") % dest_file)
758     
759     # case : display all the available pyconf applications
760     elif options.list:
761         lproduct = list()
762         # search in all directories that can have pyconf applications
763         for path in runner.cfg.SITE.config.config_path:
764             # print a header
765             if not options.no_label:
766                 logger.write("------ %s\n" % src.printcolors.printcHeader(path))
767
768             if not os.path.exists(path):
769                 logger.write(src.printcolors.printcError(_(
770                                             "Directory not found")) + "\n")
771             else:
772                 for f in sorted(os.listdir(path)):
773                     # ignore file that does not ends with .pyconf
774                     if not f.endswith('.pyconf'):
775                         continue
776
777                     appliname = f[:-len('.pyconf')]
778                     if appliname not in lproduct:
779                         lproduct.append(appliname)
780                         if path.startswith(runner.cfg.VARS.personalDir) \
781                                     and not options.no_label:
782                             logger.write("%s*\n" % appliname)
783                         else:
784                             logger.write("%s\n" % appliname)
785                             
786             logger.write("\n")
787     
788