+ ##################################################################
+ def setInternals(self, opt=None, datadir=None):
+ """set the commands by calling the dedicated function etc..."""
+ options, remaindersArgs = parser.parse_args(opt)
+ self.arguments = opt
+ self.options = options # the generic options passed to salomeTools
+ self.remaindersArgs = remaindersArgs # the command and their options
+ self.datadir = datadir # default value will be <salomeTools root>/data
+ self._setCommands(cmdsdir)
+ DBG.write("Sat.options", self.options, self.options.debug_mode)
+
+ def getConfig(self):
+ return self.cfg
+
+ ##################################################################
+ def execute_cli(self, args):
+ """
+ assume launch command from args, pyconf config known yet
+ """
+ argList = self.assumeAsList(args)
+ # no arguments : print general help
+ if len(argList) == 0:
+ self.mainLogger.info(get_help())
+ return RCO.ReturnCode("OK", "no args as sat --help")
+
+ self.setInternals(opt=argList, datadir=None)
+
+ # print general help on -h
+ if self.options.help and len(self.remaindersArgs) == 0:
+ self.mainLogger.info(get_help())
+ return RCO.ReturnCode("OK", "help done")
+
+ DBG.write("options", self.options)
+ DBG.write("remaindersArgs", self.remaindersArgs)
+
+ if len(self.remaindersArgs) == 0:
+ return RCO.ReturnCode("KO", "Nothing to do")
+
+ # print command help on -h --help after name command
+ if "-h" in self.remaindersArgs or "--help" in self.remaindersArgs:
+ self.mainLogger.info(self.get_help(self.remaindersArgs))
+ return RCO.ReturnCode("OK", "sat --help command")
+
+ # print command help on -h and continue if something do do more
+ if self.options.help and len(self.remaindersArgs) >= 1:
+ self.mainLogger.info(self.get_help(self.remaindersArgs))
+
+ command = self.remaindersArgs[0]
+ # get dynamically the command function to call
+ fun_command = self.__getattr__(command)
+ # Run the command using the arguments
+ code = fun_command(self.remaindersArgs[1:])
+
+ if code is None: code = 0 # what?! do not know why so respect history
+
+ # return salomeTools command with the right message
+ # code (0 if no errors, else 1)
+ if code == _KOSYS:
+ return RCO.ReturnCode("KO", "problem on execute_cli 'sat %s'" % " ".join(argList))
+ else:
+ return RCO.ReturnCode("OK", "execute_cli 'sat %s' done" % " ".join(argList))
+
+ '''
+ # OBSOLETE... see file ../sat
+ # ###############################
+ # MAIN : terminal command usage #
+ # ###############################
+ if __name__ == "__main__":
+ # Initialize the code that will be returned by the terminal command
+ code = 0
+ (options, args) = parser.parse_args(sys.argv[1:])
+
+ # no arguments : print general help
+ if len(args) == 0:
+ print_help()
+ sys.exit(0)
+
+ # instantiate the salomeTools class with correct options
+ sat = Sat(sys.argv[1:])
+ # the command called
+ command = args[0]
+ # get dynamically the command function to call
+ fun_command = sat.__getattr__(command)
+ # Run the command using the arguments
+ code = fun_command(args[1:])
+
+ # exit salomeTools with the right code (0 if no errors, else 1)
+ if code is None: code = 0
+ sys.exit(code)
+
+ '''
+