4 # Copyright (C) 2010-2018 CEA/DEN
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 This file is the main entry file to use salomeTools,
22 in mode Command Line Argument(s) (CLI)
29 # exit OKSYS and KOSYS seems equal on linux or windows
33 # get path to salomeTools sources
34 satdir = os.path.dirname(os.path.realpath(__file__))
35 srcdir = os.path.join(satdir, 'src')
36 cmdsdir = os.path.join(satdir, 'commands')
38 # Make the src & commands package accessible from all code
39 sys.path.insert(0, satdir)
40 sys.path.insert(0, srcdir) # TODO remove that
41 sys.path.insert(0, cmdsdir) # TODO remove that
43 import src.logger as LOG
44 import src.debug as DBG # Easy print stderr (for DEBUG only)
46 logger = LOG.getDefaultLogger()
48 DBG.write("Python version", sys.version, DBG.isDeveloper())
50 #################################
52 #################################
53 if __name__ == "__main__":
54 from src.salomeTools import Sat # it is time to do import
56 args = sys.argv[1:] # skip useless "sat'
57 sat = Sat(logger) # instantiate the salomeTools class
60 returnCode = sat.execute_cli(args)
61 except Exception as e:
62 # error as may be unknown problem
63 # verbose debug message with traceback if developers
64 msg = "Exception raised for execute_cli('%s'):\n" % " ".join(args)
65 logger.critical(DBG.format_exception(msg))
66 logger.close() # important to close logger
69 # no Exception but may be known problem
70 DBG.write("execute_cli return code", returnCode)
71 logger.step("sat exit code: %s" % returnCode)
72 logger.close() # important to close logger
73 sys.exit(returnCode.toSys())
77 logger.critical("forbidden/unexpected mode for __name__ '%s'" % __name__)
78 logger.close() # important to close logger