Salome HOME
6d20dbf12ac75bd03c79ae2362b0701eed3d77b4
[tools/sat.git] / src / __init__.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2013  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 import os
20
21 from . import pyconf
22 from . import architecture
23 from . import printcolors
24 from . import options
25 from . import system
26 from . import ElementTree
27 from . import logger
28
29 class SatException(Exception):
30     '''rename Exception Class
31     '''
32     pass
33
34 def ensure_path_exists(p):
35     '''Create a path if not existing
36     
37     :param p str: The path.
38     '''
39     if not os.path.exists(p):
40         os.makedirs(p)
41         
42 def check_config_has_application( config, details = None ):
43     '''check that the config has the key APPLICATION. Else raise an exception.
44     
45     :param config class 'common.pyconf.Config': The config.
46     '''
47     if 'APPLICATION' not in config:
48         message = _("An APPLICATION is required. Use 'config --list' to get the list of available applications.\n")
49         if details :
50             details.append(message)
51         raise SatException( message )
52     
53 def print_info(logger, info):
54     '''Prints the tuples that are in info variable in a formatted way.
55     
56     :param logger Logger: The logging instance to use for the prints.
57     :param info list: The list of tuples to display
58     '''
59     # find the maximum length of the first value of the tuples in info
60     smax = max(map(lambda l: len(l[0]), info))
61     # Print each item of info with good indentation
62     for i in info:
63         sp = " " * (smax - len(i[0]))
64         printcolors.print_value(logger, sp + i[0], i[1], 2)
65     logger.write("\n", 2)