X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Foptions.py;h=a6bca2a1944bd49bd227109c8a9204d2b21d918d;hb=cb60f487ec7dec10283d6524dd0f288f8d34452e;hp=b54b190b7f73be612b2db2c37e4814158f5a47bf;hpb=5a9e408cd6b747b9c3ad245083fd2a91739d33ca;p=tools%2Fsat.git diff --git a/src/options.py b/src/options.py index b54b190..a6bca2a 100644 --- a/src/options.py +++ b/src/options.py @@ -15,18 +15,21 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -'''The Options class that manages the access to all options passed as parameters in salomeTools command lines +'''The Options class that manages the access to all options passed as + parameters in salomeTools command lines ''' import getopt import sys from . import printcolors class OptResult(object): - '''An instance of this class will be the object manipulated in code of all salomeTools commands - The aim of this class is to have an elegant syntax to manipulate the options. - ex: - print(options.level) - 5 + '''An instance of this class will be the object manipulated + in code of all salomeTools commands + The aim of this class is to have an elegant syntax + to manipulate the options. + ex: + print(options.level) + 5 ''' def __init__(self): '''Initialization @@ -34,7 +37,8 @@ class OptResult(object): self.__dict__ = dict() def __getattr__(self, name): - '''Overwrite of the __getattr__ function to customize it for option usage + '''Overwrite of the __getattr__ function + to customize it for option usage :param name str: The attribute to get the value. :return: the value corresponding to the attribute. @@ -46,7 +50,8 @@ class OptResult(object): raise AttributeError(name + _(u" is not a valid option")) def __setattr__(self, name, value): - '''Overwrite of the __setattr__ function to customize it for option usage + '''Overwrite of the __setattr__ function + to customize it for option usage :param name str: The attribute to set. :param value str: The value corresponding to the attribute. @@ -61,19 +66,26 @@ class Options: def __init__(self): '''Initialization ''' - # The options field stocks all options of a command in a list that contains dicts + # The options field stocks all options of a command + # in a list that contains dicts self.options = [] # The list of available option type - self.availableOptions = ["boolean", "string", "int", "float", "long", "list", "list2"] + self.availableOptions = ["boolean", "string", "int", "float", + "long", "list", "list2"] - def add_option(self, shortName, longName, optionType, destName, helpString=""): - '''Method to add an option to a command. It gets all attributes of an option and append it in the options field + def add_option(self, shortName, longName, + optionType, destName, helpString=""): + '''Method to add an option to a command. It gets all attributes + of an option and append it in the options field - :param shortName str: The short name of the option (ex "l" for level option). - :param longName str: The long name of the option (ex "level" for level option). + :param shortName str: The short name of the option + (ex "l" for level option). + :param longName str: The long name of the option + (ex "level" for level option). :param optionType str: The type of the option (ex "int"). :param destName str: The name that will be used in the code. - :param helpString str: The text to display when user ask for help on a command. + :param helpString str: The text to display + when user ask for help on a command. :return: Nothing. :rtype: N\A ''' @@ -101,25 +113,32 @@ class Options: if len(self.options) == 0: return - # for all options, print its values. "shortname" is an optional field of the options + # for all options, print its values. + # "shortname" is an optional field of the options print(printcolors.printcHeader(_("Available options are:"))) for option in self.options: if 'shortName' in option and len(option['shortName']) > 0: - print(" -%(shortName)1s, --%(longName)s (%(optionType)s)\n\t%(helpString)s\n" % option) + print(" -%(shortName)1s, --%(longName)s" + " (%(optionType)s)\n\t%(helpString)s\n" % option) else: - print(" --%(longName)s (%(optionType)s)\n\t%(helpString)s\n" % option) + print(" --%(longName)s (%(optionType)s)\n\t%(helpString)s\n" + % option) def parse_args(self, argList=None): - '''Method that instantiates the class OptResult that gives access to all options in the code + '''Method that instantiates the class OptResult + that gives access to all options in the code :param argList list: the raw list of arguments that were passed - :return: optResult, args : optResult is the option instance to manipulate in the code. args is the full raw list of passed options + :return: optResult, args : optResult is the option instance + to manipulate in the code. args + is the full raw list of passed options :rtype: (class 'common.options.OptResult',list) ''' if argList is None: argList = sys.argv[1:] - # format shortNameOption and longNameOption to make right arguments to getopt.getopt function + # format shortNameOption and longNameOption + # to make right arguments to getopt.getopt function shortNameOption = "" longNameOption = [] for option in self.options: @@ -133,7 +152,8 @@ class Options: else: longNameOption.append(option['longName']) - # call to getopt.getopt function to get the option passed in the command regarding the available options + # call to getopt.getopt function to get the option + # passed in the command regarding the available options optlist, args = getopt.getopt(argList, shortNameOption, longNameOption) # instantiate and completing the optResult that will be returned @@ -168,7 +188,8 @@ class Options: option['result'].extend(elts) optResult.__setattr__(option['destName'], option['result']) - # free the option in order to be able to make a new free call of options (API case) + # free the option in order to be able to make + # a new free call of options (API case) option['result'] = None return optResult, args