import getopt
import sys
+import re
import pprint as PP
from . import printcolors
"""
# 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 = {}
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 <property>:<value>'))
+
+
def getDetailOption(self, option):
"""
"""
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 ''
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
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
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])
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 <property>:<value>')
+ 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)