Enable black and pylint in tox, and update code accordingly
[osm/osmclient.git] / osmclient / client.py
1 # Copyright 2017-2018 Sandvine
2 # Copyright 2018 Telefonica
3 #
4 # All Rights Reserved.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
16 # under the License.
17
18 """
19 OSM client entry point
20 """
21
22 from osmclient.v1 import client as client
23 from osmclient.sol005 import client as sol005client
24 import logging
25 import verboselogs
26
27 # pylint: disable=E1101
28 verboselogs.install()
29
30
31 def Client(version=1, host=None, sol005=True, *args, **kwargs):
32 log_format_simple = "%(levelname)s %(message)s"
33 log_format_complete = "%(asctime)s %(levelname)s %(name)s %(filename)s:%(lineno)s %(funcName)s(): %(message)s"
34 log_formatter_simple = logging.Formatter(
35 log_format_simple, datefmt="%Y-%m-%dT%H:%M:%S"
36 )
37 handler = logging.StreamHandler()
38 handler.setFormatter(log_formatter_simple)
39 logger = logging.getLogger("osmclient")
40 logger.setLevel(level=logging.WARNING)
41 logger.addHandler(handler)
42 verbose = kwargs.get("verbose", 0)
43 if verbose > 0:
44 log_formatter = logging.Formatter(
45 log_format_complete, datefmt="%Y-%m-%dT%H:%M:%S"
46 )
47 # handler = logging.StreamHandler()
48 handler.setFormatter(log_formatter)
49 # logger.addHandler(handler)
50 if verbose == 1:
51 logger.setLevel(level=logging.INFO)
52 elif verbose == 2:
53 logger.setLevel(level=logging.VERBOSE)
54 elif verbose > 2:
55 logger.setLevel(level=logging.DEBUG)
56 if not sol005:
57 if version == 1:
58 return client.Client(host, *args, **kwargs)
59 else:
60 raise Exception("Unsupported client version")
61 else:
62 if version == 1:
63 return sol005client.Client(host, *args, **kwargs)
64 else:
65 raise Exception("Unsupported client version")