#!/usr/bin/env python
-#-*- coding:utf-8 -*-
+# -*- coding:utf-8 -*-
# Copyright (C) 2010-2013 CEA/DEN
#
# This library is free software; you can redistribute it and/or
import subprocess
import src
-from src.versionMinorMajorPatch import MinorMajorPatch as MMP
+from src.versionMinorMajorPatch import MinorMajorPatch as MMP
import src.debug as DBG
parser = src.options.Options()
-parser.add_option('p', 'products', 'list2', 'products',
- _("Optional: the list of products to generate"))
-parser.add_option('', 'yacsgen', 'string', 'yacsgen',
- _("Optional: path to YACSGEN's module_generator package"))
+parser.add_option(
+ "p",
+ "products",
+ "list2",
+ "products",
+ _("Optional: the list of products to generate"),
+)
+parser.add_option(
+ "",
+ "yacsgen",
+ "string",
+ "yacsgen",
+ _("Optional: path to YACSGEN's module_generator package"),
+)
+
def generate_component_list(config, product_name, product_info, context, logger):
res = "?"
logger.write("\n", 3)
for compo in src.product.get_product_components(product_info):
- header = " %s %s " % (src.printcolors.printcLabel(compo),
- "." * (20 - len(compo)))
- res = generate_component(config,
- compo,
- product_name,
- product_info,
- context,
- header,
- logger)
+ header = " %s %s " % (
+ src.printcolors.printcLabel(compo),
+ "." * (20 - len(compo)),
+ )
+ res = generate_component(
+ config, compo, product_name, product_info, context, header, logger
+ )
if config.USER.output_verbose_level == 3:
logger.write("\r%s%s\r%s" % (header, " " * 20, header), 3)
logger.write(src.printcolors.printc(res), 3, False)
logger.write("\n", 3, False)
return res
-def generate_component(config, compo, product_name, product_info, context, header, logger):
-# get from config include file name and librairy name, or take default value
+
+def generate_component(
+ config, compo, product_name, product_info, context, header, logger
+):
+ # get from config include file name and librairy name, or take default value
if "hxxfile" in product_info:
hxxfile = product_info.hxxfile
else:
compo_info.install_dir = os.path.join(install_dir, compo)
compo_info.build_dir = os.path.join(build_dir, compo)
compo_info.depend = product_info.depend
- compo_info.depend.append(product_info.name, "") # add cpp module
+ compo_info.depend.append(product_info.name, "") # add cpp module
compo_info.opt_depend = product_info.opt_depend
config.PRODUCTS.addMapping(compo, src.pyconf.Mapping(config), "")
config.PRODUCTS[compo].default = compo_info
- builder = src.compilation.Builder(config, logger, product_name, compo_info, check_src=False)
+ builder = src.compilation.Builder(
+ config, logger, product_name, compo_info, check_src=False
+ )
builder.header = header
# generate the component
# inline class to override bootstrap method
import module_generator
+
class sat_generator(module_generator.Generator):
# old bootstrap for automake (used if salome version <= 7.4)
def bootstrap(self, source_dir, log_file):
# replace call to default bootstrap() by using subprocess call (cleaner)
command = "sh autogen.sh"
- ier = subprocess.call(command, shell=True, cwd=source_dir,
- stdout=log_file, stderr=subprocess.STDOUT)
+ ier = subprocess.call(
+ command,
+ shell=True,
+ cwd=source_dir,
+ stdout=log_file,
+ stderr=subprocess.STDOUT,
+ )
if ier != 0:
raise src.SatException("bootstrap has ended in error")
-
# determine salome version
VersionSalome = src.get_salome_version(config)
- if VersionSalome >= MMP([7,5,0]) :
- use_autotools=False
- builder.log('USE CMAKE', 3)
+ if VersionSalome >= MMP([7, 5, 0]):
+ use_autotools = False
+ builder.log("USE CMAKE", 3)
else:
- use_autotools=True
- builder.log('USE AUTOTOOLS', 3)
+ use_autotools = True
+ builder.log("USE AUTOTOOLS", 3)
result = "GENERATE"
- builder.log('GENERATE', 3)
+ builder.log("GENERATE", 3)
prevstdout = sys.stdout
prevstderr = sys.stderr
sys.stderr = logger.logTxtFile
if src.product.product_is_mpi(product_info):
- salome_compo = module_generator.HXX2SALOMEParaComponent(hxxfile,
- cpplib,
- cpp_path)
+ salome_compo = module_generator.HXX2SALOMEParaComponent(
+ hxxfile, cpplib, cpp_path
+ )
else:
- salome_compo = module_generator.HXX2SALOMEComponent(hxxfile,
- cpplib,
- cpp_path)
+ salome_compo = module_generator.HXX2SALOMEComponent(
+ hxxfile, cpplib, cpp_path
+ )
if src.product.product_has_salome_gui(product_info):
# get files to build a template GUI
- try: # try new yacsgen api
+ try: # try new yacsgen api
gui_files = salome_compo.getGUIfilesTemplate(compo)
except: # use old yacsgen api
gui_files = salome_compo.getGUIfilesTemplate()
else:
gui_files = None
- mg = module_generator.Module(compo, components=[salome_compo],
- prefix=generate_dir, gui=gui_files)
+ mg = module_generator.Module(
+ compo, components=[salome_compo], prefix=generate_dir, gui=gui_files
+ )
g = sat_generator(mg, context)
g.generate()
if use_autotools:
result = "BUID_CONFIGURE"
- builder.log('BUID_CONFIGURE (no bootstrap)', 3)
+ builder.log("BUID_CONFIGURE (no bootstrap)", 3)
g.bootstrap(compo_info.source_dir, logger.logTxtFile)
result = src.OK_STATUS
os.chdir(curdir)
# do the compilation using the builder object
- if builder.prepare()!= 0: return "Error in prepare"
+ if builder.prepare() != 0:
+ return "Error in prepare"
if use_autotools:
- if builder.configure()!= 0: return "Error in configure"
+ if builder.configure() != 0:
+ return "Error in configure"
else:
- if builder.cmake()!= 0: return "Error in cmake"
+ if builder.cmake() != 0:
+ return "Error in cmake"
- if builder.make(config.VARS.nb_proc, "")!=0: return "Error in make"
- if builder.install()!=0: return "Error in make install"
+ if builder.make(config.VARS.nb_proc, "") != 0:
+ return "Error in make"
+ if builder.install() != 0:
+ return "Error in make install"
# copy specified logo in generated component install directory
# rem : logo is not copied in source dir because this would require
# to modify the generated makefile
logo_path = src.product.product_has_logo(product_info)
if logo_path:
- destlogo = os.path.join(compo_info.install_dir, "share", "salome",
- "resources", compo.lower(), compo + ".png")
+ destlogo = os.path.join(
+ compo_info.install_dir,
+ "share",
+ "salome",
+ "resources",
+ compo.lower(),
+ compo + ".png",
+ )
src.Path(logo_path).copyfile(destlogo)
return result
+
def build_context(config, logger):
- products_list = [ 'KERNEL', 'GUI' ]
- ctxenv = src.environment.SalomeEnviron(config,
- src.environment.Environ(dict(
- os.environ)),
- True)
+ products_list = ["KERNEL", "GUI"]
+ ctxenv = src.environment.SalomeEnviron(
+ config, src.environment.Environ(dict(os.environ)), True
+ )
ctxenv.silent = True
ctxenv.set_full_environ(logger, config.APPLICATION.products.keys())
val = os.getenv(prod_env)
if os.getenv(prod_env) is None:
if p not in config.APPLICATION.products:
- warn = _("product %(product)s is not defined. Include it in the"
- " application or define $%(env)s.") % \
- { "product": p, "env": prod_env}
+ warn = _(
+ "product %(product)s is not defined. Include it in the"
+ " application or define $%(env)s."
+ ) % {"product": p, "env": prod_env}
logger.write(src.printcolors.printcWarning(warn), 1)
logger.write("\n", 3, False)
val = ""
"update": 1,
"makeflags": "-j2",
"kernel": dicdir["KERNEL"],
- "gui": dicdir["GUI"],
- "yacs": "",
- "med": "",
- "mesh": "",
- "visu": "",
- "geom": "",
+ "gui": dicdir["GUI"],
+ "yacs": "",
+ "med": "",
+ "mesh": "",
+ "visu": "",
+ "geom": "",
}
return context
+
def check_module_generator(directory=None):
"""Check if module_generator is available.
res = None
try:
- #import module_generator
+ # import module_generator
info = imp.find_module("module_generator")
res = info[1]
except ImportError:
return res
+
def check_yacsgen(config, directory, logger):
"""Check if YACSGEN is available.
if directory is not None:
yacsgen_dir = directory
yacs_src = _("Using YACSGEN from command line")
- elif 'YACSGEN' in config.APPLICATION.products:
- yacsgen_info = src.product.get_product_config(config, 'YACSGEN')
+ elif "YACSGEN" in config.APPLICATION.products:
+ yacsgen_info = src.product.get_product_config(config, "YACSGEN")
yacsgen_dir = yacsgen_info.install_dir
yacs_src = _("Using YACSGEN from application")
elif "YACSGEN_ROOT_DIR" in os.environ:
pv = os.getenv("PYTHON_VERSION")
if pv is None:
python_info = src.product.get_product_config(config, "Python")
- pv = '.'.join(python_info.version.split('.')[:2])
+ pv = ".".join(python_info.version.split(".")[:2])
assert pv is not None, "$PYTHON_VERSION not defined"
- yacsgen_dir = os.path.join(yacsgen_dir, "lib", "python%s" % pv,
- "site-packages")
+ yacsgen_dir = os.path.join(yacsgen_dir, "lib", "python%s" % pv, "site-packages")
c = check_module_generator(yacsgen_dir)
if c is not None:
return c
- return (False,
- _("The python module module_generator was not found in YACSGEN"))
+ return (False, _("The python module module_generator was not found in YACSGEN"))
def description():
- '''method that is called when salomeTools is called with --help option.
+ """method that is called when salomeTools is called with --help option.
:return: The text to display for the generate command description.
:rtype: str
- '''
- return _("The generate command generates SALOME modules from 'pure cpp' "
- "products.\nWARNING this command NEEDS YACSGEN to run!\n\nexample:"
- "\nsat generate SALOME-master --products FLICACPP")
+ """
+ return _(
+ "The generate command generates SALOME modules from 'pure cpp' "
+ "products.\nWARNING this command NEEDS YACSGEN to run!\n\nexample:"
+ "\nsat generate SALOME-master --products FLICACPP"
+ )
def run(args, runner, logger):
- '''method that is called when salomeTools is called with generate parameter.
- '''
+ """method that is called when salomeTools is called with generate parameter."""
# Check that the command has been called with an application
src.check_config_has_application(runner.cfg)
- logger.write(_('Generation of SALOME modules for application %s\n') % \
- src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
+ logger.write(
+ _("Generation of SALOME modules for application %s\n")
+ % src.printcolors.printcLabel(runner.cfg.VARS.application),
+ 1,
+ )
(options, args) = parser.parse_args(args)
logger.write(_("\nCleaning generated directories\n"), 3, False)
# clean source, build and install directories of the generated product
# no verbosity to avoid warning at the first generation, for which dirs don't exist
- runner.clean(runner.cfg.VARS.application +
- " --products " + pi.name +
- " --generated",
- batch=True,
- verbose=0,
- logger_add_link = logger)
+ runner.clean(
+ runner.cfg.VARS.application + " --products " + pi.name + " --generated",
+ batch=True,
+ verbose=0,
+ logger_add_link=logger,
+ )
nbgen += 1
try:
- result = generate_component_list(runner.cfg,
- product,
- pi,
- context,
- logger)
+ result = generate_component_list(runner.cfg, product, pi, context, logger)
except Exception as exc:
result = str(exc)
if len(details) == 0:
status = src.OK_STATUS
- else: #if config.USER.output_level != 3:
+ else: # if config.USER.output_level != 3:
logger.write("\n", 2, False)
logger.write(_("The following modules were not generated correctly:\n"), 2)
for d in details: