# check for product
src.check_config_has_application( runner.cfg )
- application = src.printcolors.printcLabel(runner.cfg.VARS.application)
- logger.write(_("Building application for %s\n") % application, 1)
+ application = runner.cfg.VARS.application
+ logger.info(_("Building application for <header>%s<reset>\n") % application)
# if section APPLICATION.virtual_app does not exists create one
if "virtual_app" not in runner.cfg.APPLICATION:
msg = _("The section APPLICATION.virtual_app is not defined in the product.")
- logger.write(src.printcolors.printcError(msg), 1)
- logger.write("\n", 1)
- return 1
+ logger.info("red>" + msg + "<reset>" )
+ return RCO.ReturnCode("KO", msg)
# get application dir
target_dir = runner.cfg.APPLICATION.workdir
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import os
import src.debug as DBG
import src.returnCode as RCO
from src.salomeTools import _BaseCommand
+import src.configManager as CFGMGR
########################################################################
parser.add_option('p', 'show_patchs', 'boolean', 'show_patchs',
_("Optional: synthetic view of all patches used in the application"))
parser.add_option('c', 'copy', 'boolean', 'copy',
- _("""Optional: copy a config file (.pyconf) to the personal config files directory.
- Warning: the included files are not copied.
- If a name is given the new config file takes the given name."""))
+ _("""\
+Optional: copy a config file (.pyconf) to the personal config files directory.
+Warning: the included files are not copied.
+If a name is given the new config file takes the given name."""))
parser.add_option('n', 'no_label', 'boolean', 'no_label',
_("Internal use: do not print labels, Works only with --value and --list."))
parser.add_option('o', 'completion', 'boolean', 'completion',
if options.value == ".":
# if argument is ".", print all the config
for val in sorted(config.keys()):
- print_value(config, val, not options.no_label, logger)
+ CFGMGR.print_value(config, val, logger, not options.no_label)
else:
- print_value(config, options.value, not options.no_label, logger,
+ CFGMGR.print_value(config, options.value, logger, not options.no_label,
level=0, show_full_path=False)
if options.debug:
for path in config.PATHS.APPLICATIONPATH:
# print a header
if not options.no_label:
- logger.write("------ %s\n" % src.printcolors.printcHeader(path))
-
+ logger.info("<header>------ %s<reset>" % path)
+ msg = "" # only one multiline info
if not os.path.exists(path):
- logger.write(src.printcolors.printcError(
- _("Directory not found")) + "\n" )
+ msg += ("<red>" + _("Directory not found") + "<reset>\n" )
else:
for f in sorted(os.listdir(path)):
# ignore file that does not ends with .pyconf
lproduct.append(appliname)
if path.startswith(config.VARS.personalDir) \
and not options.no_label:
- logger.write("%s*\n" % appliname)
+ msg += "%s*\n" % appliname
else:
- logger.write("%s\n" % appliname)
+ msg += "%s\n" % appliname
- logger.write("\n")
+ logger.info(msg)
# case : give a synthetic view of all patches used in the application
elif options.show_patchs:
import src.returnCode as RCO
from src.salomeTools import _BaseCommand
import src.pyconf as PYCONF
+import src.utilsSat as UTS
BINARY = "binary"
SOURCE = "Source"
'''
# read the pyconf of the product
- product_pyconf_path = src.find_file_in_lpath(p_name + ".pyconf",
+ product_pyconf_path = UTS.find_file_in_lpath(p_name + ".pyconf",
config.PATHS.PRODUCTPATH)
product_pyconf_cfg = PYCONF.Config(product_pyconf_path)
'''
# read the pyconf of the application
application_name = config.VARS.application
- application_pyconf_path = src.find_file_in_lpath(
+ application_pyconf_path = UTS.find_file_in_lpath(
application_name + ".pyconf",
config.PATHS.APPLICATIONPATH)
application_pyconf_cfg = PYCONF.Config(application_pyconf_path)
sys.exit(returnCode.toSys())
except Exception as e:
- msg = "Exception raised for execute_cli('%s'):\n\n<yellow>%s<reset>"
if (_debug) or (DBG._user in DBG._developpers):
# verbose debug message with traceback
+ msg = "Exception raised for execute_cli(%s):\n\n<yellow>%s<reset>"
import traceback
logger.critical( msg % (args, traceback.format_exc()) )
else:
# short production message
+ msg = "Exception raised for execute_cli(%s):\n\n<red>%s<reset>\n"
logger.critical( msg % (args, e) )
sys.exit(KOSYS)
try:
application_cfg = PYCONF.Config(application + '.pyconf')
except IOError as e:
- raise Exception(_("%s, use 'config --list' to get the"
- " list of available applications.") % e)
+ raise Exception(_("%s\n(use 'config --list' to get the"
+ " list of available applications)") % e)
except PYCONF.ConfigError as e:
if (not ('-e' in parser.parse_args()[1])
or ('--edit' in parser.parse_args()[1])
# Loop on all files that are in softsDir directory
# and read their config
product_file_name = product_name + ".pyconf"
- product_file_path = src.find_file_in_lpath(product_file_name, cfg.PATHS.PRODUCTPATH)
+ product_file_path = UTS.find_file_in_lpath(product_file_name, cfg.PATHS.PRODUCTPATH)
if product_file_path:
products_dir = os.path.dirname(product_file_path)
try:
try:
val = config.getByPath(path)
except Exception as e:
- stream.write(tab_level)
- stream.write("<header>%s: <red>ERROR %s<reset>\n" % (vname, str(e)))
+ stream.write(tab_level + "<header>%s: <red>ERROR %s<reset>\n" % (vname, str(e)))
return
# in this case, display only the value
if show_label:
- stream.write(tab_level)
- stream.write("<header%s: <reset>" % vname)
+ stream.write(tab_level + "<header>%s: <reset>" % vname)
# The case where the value has under values,
# do a recursive call to the function
if dir(val).__contains__('keys'):
- if show_label: strean.write("\n")
+ if show_label: stream.write("\n")
for v in sorted(val.keys()):
- print_value(config, path + '.' + v, stream, show_label, level + 1)
+ getConfigColored(config, path + '.' + v, stream, show_label, level + 1)
elif val.__class__ == PYCONF.Sequence or isinstance(val, list):
# in this case, value is a list (or a Sequence)
if show_label: stream.write("\n")
index = 0
for v in val:
p = path + "[" + str(index) + "]"
- print_value(config, p, stream, show_label, level + 1)
+ getConfigColored(config, p, stream, show_label, level + 1)
index += 1
else: # case where val is just a str
stream.write("%s\n" % val)
used recursively from the initial path.
:param see getConfigColored
- """
+ """
outStream = DBG.OutStream()
getConfigColored(config, path, outStream, show_label, level, show_full_path)
- res = outStream.value
+ res = outStream.getvalue() # stream not closed
logger.info(res)
return
:param name str: The attribute to get the value.
:return: the value corresponding to the attribute.
- :rtype: str,int,list,boolean
+ :rtype: str,int,list,boolean,level
'''
if name in self.__dict__:
return self.__dict__[name]
# in a list that contains dicts
self.options = []
# The list of available option type
- self.availableOptions = "boolean string int float long list list2".split()
+ self.availableOptions = "boolean string int float long list list2, level".split()
self.default = None
self.results = {}
option['result'] = default
self.options.append(option)
+
+ def getDetailOption(self, option):
+ """for convenience
+ returns (shortName, longName, optionType, helpString')
+ """
+ oos = option['shortName']
+ ool = option['longName']
+ oot = option['optionType']
+ ooh = option['helpString']
+ return (oos, ool, oot, ooh)
+
def get_help(self):
'''Method that returns all options stored in self.options
return _("No available options.")
# for all options, gets its values.
- # "shortname" is an optional field of the options
- msg += "<header>" + _("Available options are:") + "<reset>\n"
+ # "shortname" is an mandatory field of the options, could be ''
+ msg += "<header>" + _("Available options are:") + "<reset>"
for option in self.options:
- if 'shortName' in option and len(option['shortName']) > 0:
- msg += "\n -%(shortName)1s, --%(longName)s" \
- " (%(optionType)s)\n\t%(helpString)s\n" % option
+ oos, ool, oot, ooh = self.getDetailOption(option)
+ if len(oos) > 0:
+ msg += "\n -%1s, --%s (%s)\n" % (oos, ool, oot)
else:
- msg += "\n --%(longName)s (%(optionType)s)\n\t%(helpString)s\n" \
- % option
+ msg += "\n --%s (%s)\n" % (ool, oot)
+
+ msg += "%s\n" % self.indent(ooh, 10)
return msg
-
+
+ def indent(self, text, amount, car=" "):
+ """indent multi lines message"""
+ padding = amount * car
+ return ''.join(padding + line for line in text.splitlines(True))
+
def parse_args(self, argList=None):
'''Method that instantiates the class OptResult
if option['result'] is None:
option['result'] = list()
option['result'].append(opt[1])
+ elif optionType == "level": #logger logging levels
+ option['result'] = opt[1]
+ # TODO test in (lowercase) debug info warning error critical
elif optionType == "list2":
if option['result'] is None:
option['result'] = list()
import re
import src.pyconf as PYCONF
+import src.utilsSat as UTS
AVAILABLE_VCS = ['git', 'svn', 'cvs']
config_expression = "^config-\d+$"
# If prod_info is still None, it means that there is no product definition
# in the config. The user has to provide it.
if prod_info is None:
- prod_pyconf_path = src.find_file_in_lpath(product_name + ".pyconf",
+ prod_pyconf_path = UTS.find_file_in_lpath(product_name + ".pyconf",
config.PATHS.PRODUCTPATH)
if not prod_pyconf_path:
msg = _("""\
"")
if "archive_name" not in prod_info.archive_info:
arch_name = product_name + "-" + version + ".tar.gz"
- arch_path = src.find_file_in_lpath(arch_name,
+ arch_path = UTS.find_file_in_lpath(arch_name,
config.PATHS.ARCHIVEPATH)
if not arch_path:
msg = _("Archive %(1)s for %(2)s not found.\n") % \
if (os.path.basename(prod_info.archive_info.archive_name) ==
prod_info.archive_info.archive_name):
arch_name = prod_info.archive_info.archive_name
- arch_path = src.find_file_in_lpath(
+ arch_path = UTS.find_file_in_lpath(
arch_name,
config.PATHS.ARCHIVEPATH)
if not arch_path:
script_name = os.path.basename(script)
if script == script_name:
# Only a name is given. Search in the default directory
- script_path = src.find_file_in_lpath(script_name,
+ script_path = UTS.find_file_in_lpath(script_name,
config.PATHS.PRODUCTPATH,
"compil_scripts")
if not script_path:
# If only a filename, then search for the patch in the PRODUCTPATH
if os.path.basename(patch_path) == patch_path:
# Search in the PRODUCTPATH/patches
- patch_path = src.find_file_in_lpath(patch,
+ patch_path = UTS.find_file_in_lpath(patch,
config.PATHS.PRODUCTPATH,
"patches")
if not patch_path:
# in the PRODUCTPATH/env_scripts
if os.path.basename(env_script_path) == env_script_path:
# Search in the PRODUCTPATH/env_scripts
- env_script_path = src.find_file_in_lpath(
+ env_script_path = UTS.find_file_in_lpath(
prod_info.environ.env_script,
config.PATHS.PRODUCTPATH,
"env_scripts")