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 |
1 |
""" |
19 |
|
OSM client entry point |
20 |
|
""" |
21 |
|
|
22 |
1 |
from osmclient.v1 import client as client |
23 |
1 |
from osmclient.sol005 import client as sol005client |
24 |
1 |
import logging |
25 |
1 |
import verboselogs |
26 |
|
|
27 |
|
# pylint: disable=E1101 |
28 |
1 |
verboselogs.install() |
29 |
|
|
30 |
|
|
31 |
1 |
def Client(version=1, host=None, sol005=True, *args, **kwargs): |
32 |
0 |
log_format_simple = "%(levelname)s %(message)s" |
33 |
0 |
log_format_complete = "%(asctime)s %(levelname)s %(name)s %(filename)s:%(lineno)s %(funcName)s(): %(message)s" |
34 |
0 |
log_formatter_simple = logging.Formatter( |
35 |
|
log_format_simple, datefmt="%Y-%m-%dT%H:%M:%S" |
36 |
|
) |
37 |
0 |
handler = logging.StreamHandler() |
38 |
0 |
handler.setFormatter(log_formatter_simple) |
39 |
0 |
logger = logging.getLogger("osmclient") |
40 |
0 |
logger.setLevel(level=logging.WARNING) |
41 |
0 |
logger.addHandler(handler) |
42 |
0 |
verbose = kwargs.get("verbose", 0) |
43 |
0 |
if verbose > 0: |
44 |
0 |
log_formatter = logging.Formatter( |
45 |
|
log_format_complete, datefmt="%Y-%m-%dT%H:%M:%S" |
46 |
|
) |
47 |
|
# handler = logging.StreamHandler() |
48 |
0 |
handler.setFormatter(log_formatter) |
49 |
|
# logger.addHandler(handler) |
50 |
0 |
if verbose == 1: |
51 |
0 |
logger.setLevel(level=logging.INFO) |
52 |
0 |
elif verbose == 2: |
53 |
0 |
logger.setLevel(level=logging.VERBOSE) |
54 |
0 |
elif verbose > 2: |
55 |
0 |
logger.setLevel(level=logging.DEBUG) |
56 |
0 |
if not sol005: |
57 |
0 |
if version == 1: |
58 |
0 |
return client.Client(host, *args, **kwargs) |
59 |
|
else: |
60 |
0 |
raise Exception("Unsupported client version") |
61 |
|
else: |
62 |
0 |
if version == 1: |
63 |
0 |
return sol005client.Client(host, *args, **kwargs) |
64 |
|
else: |
65 |
0 |
raise Exception("Unsupported client version") |