X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Foptions.py;h=bbcf8936866588aa8290797ac2df6176f11546d5;hb=28cebd157f9d39920d0480232e7c361716ca45bb;hp=f4674b56be763e2c4ef39ed00697c96c157429a3;hpb=ecfb9ee332b06b0a99cf0be4ec36fd115b87fc3c;p=tools%2Fsat.git diff --git a/src/options.py b/src/options.py old mode 100644 new mode 100755 index f4674b5..bbcf893 --- a/src/options.py +++ b/src/options.py @@ -23,6 +23,7 @@ parameters in salomeTools command lines import getopt import sys +import re import pprint as PP from . import printcolors @@ -85,9 +86,10 @@ class Options(object): """ # The options field stocks all options of a command # in a list that contains dicts + self.PROPERTY_EXPRESSION = "^.+:.+$" self.options = [] # The list of available option type - self.availableOptions = "noboolean boolean string int float long list list2 level".split() + self.availableOptions = "noboolean boolean string int float long list list2 level properties".split() self.noArgOptions = "noboolean boolean".split() self.default = None self.results = {} @@ -127,6 +129,14 @@ class Options(object): option['result'] = default self.options.append(option) + + # add option properties unconditionaly if 'products' option added + if [shortName, longName] == ["p", "products"]: + self.add_option('', 'properties', 'properties', 'properties', + _('Optional: Filter the products by their properties.\n\tSyntax: ' + '--properties :')) + + def getDetailOption(self, option): """ @@ -149,8 +159,10 @@ class Options(object): """ msg = "" # Do nothing if there are no options - if len(self.options) == 0: - return _("No available options.") + + #there is -h option, always + #if len(self.options) == 0: + # return _("No available options.") # for all options, gets its values. # "shortname" is an mandatory field of the options, could be '' @@ -165,15 +177,6 @@ class Options(object): msg += "%s\n" % self.indent(ooh, 10) return msg - def print_help(self): - """ - Method that display all options stored in self.options and there help - - :return: None - """ - print(self.get_help()) - return - def indent(self, text, amount, car=" "): """indent multi lines message""" padding = amount * car @@ -248,6 +251,8 @@ class Options(object): if option['result'] is None: option['result'] = list() option['result'] = self.filterList2(opt[1]) + elif optionType == "properties": + option['result'] = self.filterProperties(opt[1]) optResult.__setattr__(option['destName'], option['result']) # free the option in order to be able to make @@ -260,7 +265,7 @@ class Options(object): def filterLevel(self, aLevel): """filter level logging values""" - import src.loggingSat as LOG + import src.loggingSimple as LOG aLev = aLevel.upper() knownLevels = LOG._knownLevels maxLen = max([len(i) for i in knownLevels]) @@ -275,32 +280,49 @@ class Options(object): def filterList2(self, aStr): """filter a list as 'KERNEL,YACS,etc.'""" aList = aStr.strip().split(",") + # fix list leading ',' as ',KERNEL,...' + aList = [i for i in aList if i != ""] # split old list leadin "," as ",KERNEL,ETC..." return aList + def filterProperties(self, aStr): + """ + filter properties values + + example: + >> sat -v 9 prepare $TRG -p KERNEL --properties is_SALOME_module:yes + """ + msg = _('The "--properties" option must have the following syntax:\n--properties :') + oExpr = re.compile(self.PROPERTY_EXPRESSION) + if not oExpr.search(aStr): + raise Exception(msg) + res = aStr.split(":") + if len(res) != 2: + raise Exception(msg) + return res def __repr__(self): - """ - repr for only self.options and self.results (if present) - """ - aDict = {'options': self.options, 'results': self.results} - aStr = PP.pformat(aDict) - res = "%s(\n %s\n)" % (self.__class__.__name__, aStr[1:-1]) - return res + """ + repr for only self.options and self.results (if present) + """ + aDict = {'options': self.options, 'results': self.results} + aStr = PP.pformat(aDict) + res = "%s(\n %s\n)" % (self.__class__.__name__, aStr[1:-1]) + return res def __str__(self): - """ - str for only resume expected self.options - """ - #aDict = [(k["longName"], k["shortName", k["helpString"]) for k in self.options} - #aList = [(k, self.options[k]) for k in sorted(self.options.keys())] - aDict = {} - for o in self.options: - aDict[o["longName"]] = (o["shortName"], o["helpString"]) - aStr = PP.pformat(aDict) - res = "%s(\n %s)" % (self.__class__.__name__, aStr[1:-1]) - return res + """ + str for only resume expected self.options + """ + #aDict = [(k["longName"], k["shortName", k["helpString"]) for k in self.options} + #aList = [(k, self.options[k]) for k in sorted(self.options.keys())] + aDict = {} + for o in self.options: + aDict[o["longName"]] = (o["shortName"], o["helpString"]) + aStr = PP.pformat(aDict) + res = "%s(\n %s)" % (self.__class__.__name__, aStr[1:-1]) + return res def debug_write(self): - DBG.write("options and results", self, True) + DBG.write("options and results", self, True)