Salome HOME
get_salome_version returns integer, TODO use MajorMinorPatch
[tools/sat.git] / sat
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 #  Copyright (C) 2010-2018  CEA/DEN
5 #
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.
10 #
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.
15 #
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
19
20 """
21 This file is the main entry file to use salomeTools,
22 in mode Command Line Argument(s) (CLI)
23 """
24
25 import os
26 import sys
27
28 # exit OKSYS and KOSYS seems equal on linux or windows
29 OKSYS = 0  # OK
30 KOSYS = 1  # KO
31
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')
36
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
41
42 import src.logger as LOG
43 import src.debug as DBG # Easy print stderr (for DEBUG only)
44
45 logger = LOG.getDefaultLogger()
46
47 #################################
48 # MAIN
49 #################################
50 if __name__ == "__main__":
51     from src.salomeTools import Sat # it is time to do import
52
53     _debug = False # Have to be False in production (for programmers DEBUG only)
54     DBG.push_debug(_debug) # as __main__ with sys.exit so no need pop_debug
55
56     args = sys.argv[1:] # skip useless "sat'
57     sat = Sat(logger) # instantiate the salomeTools class
58
59     try:
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
67       sys.exit(KOSYS)
68
69     # no Exception but may be known problem
70     DBG.write("execute_cli return code", returnCode)
71     if returnCode.isOk():
72       # OK no trace
73       logger.step("sat exit code: %s" % returnCode)
74     else:
75       # KO warning as known problem have to say why
76       logger.warning("sat exit code: %s" % returnCode)
77     logger.close() # important to close logger
78     sys.exit(returnCode.toSys())
79
80
81 else:
82     logger.critical("forbidden/unexpected mode for __name__ '%s'" % __name__)
83     logger.close() # important to close logger
84     sys.exit(KOSYS)
85
86
87