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)
28 # exit OKSYS and KOSYS seems equal on linux or windows
32 # get path to salomeTools sources
33 satdir = os.path.dirname(os.path.realpath(__file__))
34 srcdir = os.path.join(satdir, 'src')
35 cmdsdir = os.path.join(satdir, 'commands')
37 # Make the src & commands package accessible from all code
38 sys.path.insert(0, satdir)
39 sys.path.insert(0, srcdir) # TODO remove that
40 sys.path.insert(0, cmdsdir) # TODO remove that
42 import src.logger as LOG
43 import src.debug as DBG # Easy print stderr (for DEBUG only)
45 logger = LOG.getDefaultLogger()
47 DBG.write("Python version", sys.version, DBG.isDeveloper())
49 #################################
51 #################################
52 if __name__ == "__main__":
53 from src.salomeTools import Sat # it is time to do import
55 _debug = False # Have to be False in production (for programmers DEBUG only)
56 DBG.push_debug(_debug) # as __main__ with sys.exit so no need pop_debug
58 args = sys.argv[1:] # skip useless "sat'
59 sat = Sat(logger) # instantiate the salomeTools class
62 returnCode = sat.execute_cli(args)
63 except Exception as e:
64 # error as may be unknown problem
65 # verbose debug message with traceback if developers
66 msg = "Exception raised for execute_cli('%s'):\n" % " ".join(args)
67 logger.critical(DBG.format_exception(msg))
68 logger.close() # important to close logger
71 # no Exception but may be known problem
72 DBG.write("execute_cli return code", returnCode)
75 logger.step("sat exit code: %s" % returnCode)
77 # KO warning as known problem have to say why
78 logger.warning("sat exit code: %s" % returnCode)
79 logger.close() # important to close logger
80 sys.exit(returnCode.toSys())
84 logger.critical("forbidden/unexpected mode for __name__ '%s'" % __name__)
85 logger.close() # important to close logger