import sys
import src
+import src.debug as DBG
# internationalization
-satdir = os.path.dirname(os.path.realpath(__file__))
+satdir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
gettext.install('salomeTools', os.path.join(satdir, 'src', 'i18n'))
# Define all possible option for config command : sat config <options>
parser = src.options.Options()
parser.add_option('v', 'value', 'string', 'value',
_("Optional: print the value of CONFIG_VARIABLE."))
+parser.add_option('g', 'debug', 'string', 'debug',
+ _("Optional: print the debugging mode value of CONFIG_VARIABLE."))
parser.add_option('e', 'edit', 'boolean', 'edit',
_("Optional: edit the product configuration file."))
parser.add_option('i', 'info', 'string', 'info',
parser.add_option('l', 'list', 'boolean', 'list',
_("Optional: list all available applications."))
parser.add_option('', 'show_patchs', 'boolean', 'show_patchs',
- _("Optional: synthetic view of all patches used in the application"))
+ _("Optional: synthetic list of all patches used in the application"))
+parser.add_option('', 'show_properties', 'boolean', 'show_properties',
+ _("Optional: synthetic list of all properties used in the application"))
parser.add_option('c', 'copy', 'boolean', 'copy',
_("""Optional: copy a config file to the personal config files directory.
\tWARNING the included files are not copied.
exec('cfg.' + rule) # this cannot be factorized because of the exec
# =====================================================================
- # Load SITE config file
+ # Load LOCAL config file
# search only in the data directory
src.pyconf.streamOpener = ConfigOpener([cfg.VARS.datadir])
try:
- site_cfg = src.pyconf.Config(open(os.path.join(cfg.VARS.datadir,
- 'site.pyconf')),
- PWD = ('SITE', cfg.VARS.datadir) )
+ local_cfg = src.pyconf.Config(open(os.path.join(cfg.VARS.datadir,
+ 'local.pyconf')),
+ PWD = ('LOCAL', cfg.VARS.datadir) )
except src.pyconf.ConfigError as e:
raise src.SatException(_("Error in configuration file: "
- "site.pyconf\n %(error)s") % \
+ "local.pyconf\n %(error)s") % \
{'error': str(e) })
except IOError as error:
e = str(error)
- if "site.pyconf" in e :
- e += ("\nYou can copy data"
- + cfg.VARS.sep
- + "site.template.pyconf to data"
- + cfg.VARS.sep
- + "site.pyconf and edit the file")
raise src.SatException( e );
- merger.merge(cfg, site_cfg)
+ merger.merge(cfg, local_cfg)
+
+ # When the key is "default", put the default value
+ if cfg.LOCAL.base == "default":
+ cfg.LOCAL.base = os.path.abspath(
+ os.path.join(cfg.VARS.salometoolsway,
+ "..",
+ "BASE"))
+ if cfg.LOCAL.workdir == "default":
+ cfg.LOCAL.workdir = os.path.abspath(
+ os.path.join(cfg.VARS.salometoolsway,
+ ".."))
+ if cfg.LOCAL.log_dir == "default":
+ cfg.LOCAL.log_dir = os.path.abspath(
+ os.path.join(cfg.VARS.salometoolsway,
+ "..",
+ "LOGS"))
+
+ if cfg.LOCAL.archive_dir == "default":
+ cfg.LOCAL.archive_dir = os.path.abspath(
+ os.path.join(cfg.VARS.salometoolsway,
+ "..",
+ "ARCHIVES"))
# apply overwrite from command line if needed
- for rule in self.get_command_line_overrides(options, ["SITE"]):
+ for rule in self.get_command_line_overrides(options, ["LOCAL"]):
exec('cfg.' + rule) # this cannot be factorized because of the exec
# =====================================================================
cfg.addMapping("PATHS", src.pyconf.Mapping(cfg), "The paths\n")
cfg.PATHS["APPLICATIONPATH"] = src.pyconf.Sequence(cfg.PATHS)
cfg.PATHS.APPLICATIONPATH.append(cfg.VARS.personal_applications_dir, "")
+
cfg.PATHS["PRODUCTPATH"] = src.pyconf.Sequence(cfg.PATHS)
cfg.PATHS.PRODUCTPATH.append(cfg.VARS.personal_products_dir, "")
cfg.PATHS.JOBPATH.append(cfg.VARS.personal_jobs_dir, "")
cfg.PATHS["MACHINEPATH"] = src.pyconf.Sequence(cfg.PATHS)
cfg.PATHS.MACHINEPATH.append(cfg.VARS.personal_machines_dir, "")
+
+ # initialise the path with local directory
+ cfg.PATHS["ARCHIVEPATH"].append(cfg.LOCAL.archive_dir, "")
+
# Loop over the projects in order to complete the PATHS variables
+ # as /data/tmpsalome/salome/prerequis/archives for example ARCHIVEPATH
for project in cfg.PROJECTS.projects:
for PATH in ["APPLICATIONPATH",
"PRODUCTPATH",
- "ARCHIVEPATH",
+ "ARCHIVEPATH", #comment this for default archive #8646
"JOBPATH",
"MACHINEPATH"]:
if PATH not in cfg.PROJECTS.projects[project]:
for rule in self.get_command_line_overrides(options, ["PATHS"]):
exec('cfg.' + rule) # this cannot be factorized because of the exec
+ # AT END append APPLI_TEST directory in APPLICATIONPATH, for unittest
+ appli_test_dir = os.path.join(satdir, "test", "APPLI_TEST")
+ if appli_test_dir not in cfg.PATHS.APPLICATIONPATH:
+ cfg.PATHS.APPLICATIONPATH.append(appli_test_dir, "unittest APPLI_TEST path")
+
# =====================================================================
# Load APPLICATION config file
if application is not None:
try:
application_cfg = src.pyconf.Config(application + '.pyconf')
except IOError as e:
- raise src.SatException(_("%s, use 'config --list' to get the"
- " list of available applications.") %e)
+ raise src.SatException(
+ _("%s, use 'config --list' to get the list of available applications.") % e)
except src.pyconf.ConfigError as e:
if (not ('-e' in parser.parse_args()[1])
or ('--edit' in parser.parse_args()[1])
if product_file_path:
products_dir = os.path.dirname(product_file_path)
try:
- prod_cfg = src.pyconf.Config(open(
- os.path.join(products_dir,
- product_file_name)),
+ prod_cfg = src.pyconf.Config(open(product_file_path),
PWD=("", products_dir))
+ prod_cfg.from_file = product_file_path
products_cfg.PRODUCTS[product_name] = prod_cfg
except Exception as e:
msg = _(
(containing all pyconf).
'''
# get the expected name and path of the file
- self.config_file_name = 'salomeTools.pyconf'
+ self.config_file_name = 'SAT.pyconf'
self.user_config_file_path = os.path.join(config.VARS.personalDir,
self.config_file_name)
#
user_cfg.addMapping('USER', src.pyconf.Mapping(user_cfg), "")
- #
- user_cfg.USER.addMapping('workdir', os.path.expanduser('~'),
- "This is where salomeTools will work. "
- "You may (and probably do) change it.\n")
user_cfg.USER.addMapping('cvs_user', config.VARS.user,
"This is the user name used to access salome cvs base.\n")
user_cfg.USER.addMapping('svn_user', config.VARS.user,
'evince',
"This is the pdf_viewer used "
"to read pdf documentation\n")
- user_cfg.USER.addMapping("base",
- src.pyconf.Reference(
- user_cfg,
- src.pyconf.DOLLAR,
- 'workdir + $VARS.sep + "BASE"'),
- "The products installation base (could be "
- "ignored if this key exists in the site.pyconf"
- " file of salomTools).\n")
-
- user_cfg.USER.addMapping("log_dir",
- src.pyconf.Reference(
- user_cfg,
- src.pyconf.DOLLAR,
- 'workdir + $VARS.sep + "LOGS"'),
- "The log repository\n")
-
+# CNC 25/10/17 : plus nécessaire a priori
+# user_cfg.USER.addMapping("base",
+# src.pyconf.Reference(
+# user_cfg,
+# src.pyconf.DOLLAR,
+# 'workdir + $VARS.sep + "BASE"'),
+# "The products installation base (could be "
+# "ignored if this key exists in the local.pyconf"
+# " file of salomTools).\n")
+
#
src.ensure_path_exists(config.VARS.personalDir)
src.ensure_path_exists(os.path.join(config.VARS.personalDir,
logger.write(_("%s is a product\n") % src.printcolors.printcLabel(name), 2)
pinfo = src.product.get_product_config(config, name)
- # Type of the product
- ptype = src.get_cfg_param(pinfo, "type", "")
- src.printcolors.print_value(logger, "type", ptype, 2)
if "depend" in pinfo:
src.printcolors.print_value(logger,
"depends on",
"optional",
', '.join(pinfo.opt_depend), 2)
+ # information on pyconf
+ logger.write("\n", 2)
+ logger.write(src.printcolors.printcLabel("configuration:") + "\n", 2)
+ if "from_file" in pinfo:
+ src.printcolors.print_value(logger,
+ "pyconf file path",
+ pinfo.from_file,
+ 2)
+ if "section" in pinfo:
+ src.printcolors.print_value(logger,
+ "section",
+ pinfo.section,
+ 2)
+
# information on prepare
logger.write("\n", 2)
logger.write(src.printcolors.printcLabel("prepare:") + "\n", 2)
False)
zz.set_python_libdirs()
zz.set_a_product(name, logger)
-
+ logger.write("\n", 2)
+
+
def show_patchs(config, logger):
- '''Prints all the used patchs in the application.
-
- :param config Config: the global configuration.
- :param logger Logger: The logger instance to use for the display
- '''
- len_max = max([len(p) for p in config.APPLICATION.products]) + 2
- for product in config.APPLICATION.products:
- product_info = src.product.get_product_config(config, product)
- if src.product.product_has_patches(product_info):
- logger.write("%s: " % product, 1)
- logger.write(src.printcolors.printcInfo(
- " " * (len_max - len(product) -2) +
- "%s\n" % product_info.patches[0]),
- 1)
- if len(product_info.patches) > 1:
- for patch in product_info.patches[1:]:
- logger.write(src.printcolors.printcInfo(len_max*" " +
- "%s\n" % patch), 1)
- logger.write("\n", 1)
+ '''Prints all the used patchs in the application.
+
+ :param config Config: the global configuration.
+ :param logger Logger: The logger instance to use for the display
+ '''
+ oneOrMore = False
+ for product in sorted(config.APPLICATION.products):
+ product_info = src.product.get_product_config(config, product)
+ if src.product.product_has_patches(product_info):
+ oneOrMore = True
+ logger.write("%s:\n" % product, 1)
+ for i in product_info.patches:
+ logger.write(src.printcolors.printcInfo(" %s\n" % i), 1)
+ if oneOrMore:
+ logger.write("\n", 1)
+ else:
+ logger.write("No patchs found\n", 1)
+
+
+def show_properties(config, logger):
+ '''Prints all the used properties in the application.
+
+ :param config Config: the global configuration.
+ :param logger Logger: The logger instance to use for the display
+ '''
+ oneOrMore = False
+ for product in sorted(config.APPLICATION.products):
+ product_info = src.product.get_product_config(config, product)
+ done = False
+ try:
+ for i in product_info.properties:
+ if not done:
+ logger.write("%s:\n" % product, 1)
+ done = True
+ oneOrMore = True
+ logger.write(src.printcolors.printcInfo(" %s\n" % i), 1)
+ except:
+ # logger.write(src.printcolors.printcInfo(" %s\n" % "no properties"), 1)
+ pass
+ if oneOrMore:
+ logger.write("\n", 1)
+ else:
+ logger.write("No properties found\n", 1)
def print_value(config, path, show_label, logger, level=0, show_full_path=False):
'''Prints a value from the configuration. Prints recursively the values
if options.schema:
get_config_children(runner.cfg, args)
return
-
+
# case : print a value of the config
if options.value:
if options.value == ".":
print_value(runner.cfg, options.value, not options.no_label, logger,
level=0, show_full_path=False)
+ # case : print a debug value of the config
+ if options.debug:
+ if options.debug == ".":
+ # if argument is ".", print all the config
+ res = DBG.indent(DBG.getStrConfigDbg(runner.cfg))
+ logger.write("\nConfig of application %s:\n\n%s\n" % (runner.cfg.VARS.application, res))
+ else:
+ exec("a = runner.cfg.%s" % options.debug)
+ res = DBG.indent(DBG.getStrConfigDbg(a))
+ logger.write("\nConfig.%s of application %s:\n\n%s\n" % (options.debug, runner.cfg.VARS.application, res))
+
+
# case : edit user pyconf file or application file
- elif options.edit:
+ if options.edit:
editor = runner.cfg.USER.editor
if ('APPLICATION' not in runner.cfg and
'open_application' not in runner.cfg): # edit user pyconf
usercfg = os.path.join(runner.cfg.VARS.personalDir,
- 'salomeTools.pyconf')
- logger.write(_("Openning %s\n" % usercfg), 3)
+ 'SAT.pyconf')
+ logger.write(_("Opening %s\n" % usercfg), 3)
src.system.show_in_editor(editor, usercfg, logger)
else:
# search for file <application>.pyconf and open it
pyconf_path = os.path.join(path,
runner.cfg.VARS.application + ".pyconf")
if os.path.exists(pyconf_path):
- logger.write(_("Openning %s\n" % pyconf_path), 3)
+ logger.write(_("Opening %s\n" % pyconf_path), 3)
src.system.show_in_editor(editor, pyconf_path, logger)
break
# case : give information about the product in parameter
- elif options.info:
+ if options.info:
src.check_config_has_application(runner.cfg)
if options.info in runner.cfg.APPLICATION.products:
show_product_info(runner.cfg, options.info, logger)
- return
- raise src.SatException(_("%(product_name)s is not a product "
- "of %(application_name)s.") %
- {'product_name' : options.info,
- 'application_name' :
- runner.cfg.VARS.application})
+ # return
+ else:
+ msg = _("%s is not a product of %s.") % \
+ (options.info, runner.cfg.VARS.application)
+ raise Exception(msg)
# case : copy an existing <application>.pyconf
# to ~/.salomeTools/Applications/LOCAL_<application>.pyconf
- elif options.copy:
+ if options.copy:
# product is required
src.check_config_has_application( runner.cfg )
logger.write(_("%s has been created.\n") % dest_file)
# case : display all the available pyconf applications
- elif options.list:
+ if options.list:
lproduct = list()
# search in all directories that can have pyconf applications
for path in runner.cfg.PATHS.APPLICATIONPATH:
logger.write("%s\n" % appliname)
logger.write("\n")
+
+ # case: print all the products name of the application (internal use for completion)
+ if options.completion:
+ for product_name in runner.cfg.APPLICATION.products.keys():
+ logger.write("%s\n" % product_name)
+
# case : give a synthetic view of all patches used in the application
- elif options.show_patchs:
+ if options.show_patchs:
src.check_config_has_application(runner.cfg)
# Print some informations
- logger.write(_('Show the patchs of application %s\n') %
+ logger.write(_('Patchs of application %s\n') %
src.printcolors.printcLabel(runner.cfg.VARS.application), 3)
logger.write("\n", 2, False)
show_patchs(runner.cfg, logger)
-
- # case: print all the products name of the application (internal use for completion)
- elif options.completion:
- for product_name in runner.cfg.APPLICATION.products.keys():
- logger.write("%s\n" % product_name)
-
-
+
+ # case : give a synthetic view of all patches used in the application
+ if options.show_properties:
+ src.check_config_has_application(runner.cfg)
+ # Print some informations
+ logger.write(_('Properties of application %s\n') %
+ src.printcolors.printcLabel(runner.cfg.VARS.application), 3)
+ logger.write("\n", 2, False)
+ show_properties(runner.cfg, logger)
+