except NameError:
pass
+# Python 2/3 compatibility for execfile function
+try:
+ execfile
+except:
+ def execfile(somefile, global_vars, local_vars):
+ with open(somefile) as f:
+ code = compile(f.read(), somefile, 'exec')
+ exec(code, global_vars, local_vars)
+
parser = src.options.Options()
parser.add_option('n', 'name', 'string', 'name',
- _("""REQUIRED the name of the module to create.
+ _("""REQUIRED: the name of the module to create.
\tThe name must be a single word in upper case with only alphanumeric characters.
\tWhen generating a c++ component the module's """
"""name must be suffixed with 'CPP'."""))
parser.add_option('t', 'template', 'string', 'template',
- _('REQUIRED the template to use.'))
+ _('REQUIRED: the template to use.'))
parser.add_option('', 'target', 'string', 'target',
- _('REQUIRED where to create the module.'))
+ _('REQUIRED: where to create the module.'))
parser.add_option('', 'param', 'string', 'param',
- _('''dictionary to generate the configuration for salomeTools.
+ _('''Optional: dictionary to generate the configuration for salomeTools.
\tFormat is: --param param1=value1,param2=value2... without spaces
\tNote that when using this option you must supply all the '''
'''values otherwise an error will be raised.'''))
parser.add_option('', 'info', 'boolean', 'info',
- _('Get information on the template.'), False)
+ _('Optional: Get information on the template.'), False)
class TParam:
def __init__(self, param_def, compo_name, dico=None):
return len(val) > 0 and self.check_method(val)
def get_dico_param(dico, key, default):
- if dico.has_key(key):
+ if key in dico:
return dico[key]
return default
# check required parameters in template.info
missing = []
for pp in ["file_subst", "parameters"]:
- if not ldic.has_key(pp): missing.append("'%s'" % pp)
+ if not (pp in ldic): missing.append("'%s'" % pp)
if len(missing) > 0:
raise src.SatException(_(
"Bad format in settings file! %s not defined.") % ", ".join(
# ask user for values
for p in self.parameters:
tp = TParam(p, self.compo_name, dico)
- if dico.has_key(tp.name):
+ if tp.name in dico:
continue
val = ""
while not tp.check_value(val):
- val = raw_input(tp.prompt)
+ val = input(tp.prompt)
if len(val) == 0 and len(tp.default) > 0:
val = tp.default
dico[tp.name] = val
# ask for missing value for pyconf
pyconfparam = self.get_pyconf_parameters()
- for p in filter(lambda l: not dico.has_key(l), pyconfparam):
+ for p in filter(lambda l: not (l in dico), pyconfparam):
rep = ""
while len(rep) == 0:
- rep = raw_input("%s? " % p)
+ rep = input("%s? " % p)
dico[p] = rep
self.dico = dico
##
# Describes the command
def description():
- return _("""The template command creates the sources for a SALOME """
- """module from a template.""")
+ return _("The template command creates the sources for a SALOME "
+ "module from a template.\n\nexample\nsat template "
+ "--name my_product_name --template PythonComponent --target /tmp")
def run(args, runner, logger):
'''method that is called when salomeTools is called with template parameter.
logger.write("\n", 1)
return 1
+ # CNC inutile
# Ask user confirmation if a module of the same name already exists
- if options.name in runner.cfg.PRODUCTS and not runner.options.batch:
- logger.write(src.printcolors.printcWarning(
- _("A module named '%s' already exists." % options.name)), 1)
- logger.write("\n", 1)
- rep = input(_("Are you sure you want to continue? [Yes/No] "))
- if rep.upper() != _("YES"):
- return 1
+ #if options.name in runner.cfg.PRODUCTS and not runner.options.batch:
+ # logger.write(src.printcolors.printcWarning(
+ # _("A module named '%s' already exists." % options.name)), 1)
+ # logger.write("\n", 1)
+ # rep = input(_("Are you sure you want to continue? [Yes/No] "))
+ # if rep.upper() != _("YES"):
+ # return 1
if options.target is None:
msg = _("Error: the --%s argument is required\n") % "target"
logger.write("\n", 1)
return 1
- if options.template == "Application":
- if "_APPLI" not in options.name and not runner.options.batch:
- msg = _("An Application module named '..._APPLI' "
- "is usually recommended.")
- logger.write(src.printcolors.printcWarning(msg), 1)
- logger.write("\n", 1)
- rep = input(_("Are you sure you want to continue? [Yes/No] "))
- if rep.upper() != _("YES"):
- return 1
+ # CNC inutile
+ #if options.template == "Application":
+ # if "_APPLI" not in options.name and not runner.options.batch:
+ # msg = _("An Application module named '..._APPLI' "
+ # "is usually recommended.")
+ # logger.write(src.printcolors.printcWarning(msg), 1)
+ # logger.write("\n", 1)
+ # rep = input(_("Are you sure you want to continue? [Yes/No] "))
+ # if rep.upper() != _("YES"):
+ # return 1
logger.write(_('Create sources from template\n'), 1)
src.printcolors.print_value(logger, 'destination', target_dir, 2)