import nepi; nepi.version
[nepi.git] / nepi / __init__.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2013 INRIA
4 #
5 #    This program is free software: you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License version 2 as
7 #    published by the Free Software Foundation;
8 #
9 #    This program is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License
15 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
18
19 from __future__ import print_function
20
21 import logging
22 import os
23 import traceback
24
25 LOGLEVEL = os.environ.get("NEPI_LOGLEVEL", "INFO").upper()
26 LOGLEVEL = getattr(logging, LOGLEVEL)
27 FORMAT = "%(asctime)s %(name)s %(levelname)-4s %(message)s"
28
29 # NEPI_LOG variable contains space separated components 
30 # on which logging should be enabled
31 LOG = os.environ.get("NEPI_LOG", "ALL").upper()
32
33 if LOG != 'ALL':
34     # Set by default loglevel to error
35     logging.basicConfig(format = FORMAT, level = logging.ERROR)
36
37     # Set logging level to that defined by the user
38     # only for the enabled components
39     for component in LOG.split(" "):
40         try:
41            log = logging.getLogger(component)
42            log.setLevel(LOGLEVEL)
43         except:
44             err = traceback.format_exc()
45             print("ERROR ", err)
46 else:
47     # Set the logging level defined by the user for all
48     # components
49     logging.basicConfig(format = FORMAT, level = LOGLEVEL)
50
51
52 # Add RMs to ResourceFactory. Use NEPI_SEARCH_PATH to 
53 # override the default path to search for RMs
54 from nepi.execution.resource import populate_factory
55 populate_factory()
56
57 from nepi.util.version import version_tag 
58 version = version_tag
59