Salome HOME
[FORUM 505] prepare command fix on windows
[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 import platform
28
29 # exit OKSYS and KOSYS seems equal on linux or windows
30 OKSYS = 0  # OK
31 KOSYS = 1  # KO
32
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')
37
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
42
43 import src.logger as LOG
44 import src.debug as DBG # Easy print stderr (for DEBUG only)
45
46 logger = LOG.getDefaultLogger()
47
48 DBG.write("Python version", sys.version, DBG.isDeveloper())
49
50 #################################
51 # MAIN
52 #################################
53 if __name__ == "__main__":
54     from src.salomeTools import Sat # it is time to do import
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     logger.step("sat exit code: %s" % returnCode)
72     logger.close() # important to close logger
73     sys.exit(returnCode.toSys())
74
75
76 else:
77     logger.critical("forbidden/unexpected mode for __name__ '%s'" % __name__)
78     logger.close() # important to close logger
79     sys.exit(KOSYS)
80
81
82