Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed usused code - for Pythons <3.7 #497

Merged
merged 8 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions moler/config/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"""

__author__ = 'Grzegorz Latuszek, Michal Ernst, Marcin Usielski'
__copyright__ = 'Copyright (C) 2018-2021, Nokia'
__email__ = '[email protected], [email protected], marcin'
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
__email__ = '[email protected], [email protected], marcin[email protected]'

import sys
import platform
Expand Down Expand Up @@ -54,10 +54,6 @@ def set_defaults():
set_default_variant(io_type="sshshell", variant="threaded")


def _running_python_3_5_or_above():
return (sys.version_info[0] >= 3) and (sys.version_info[1] >= 5)


supported_unix_systems = ['Linux', "FreeBSD", "Darwin", "SunOS"]
supported_windows_systems = ['Windows']
supported_systems = supported_unix_systems + supported_windows_systems
Expand All @@ -73,13 +69,11 @@ def _running_on_supported_windows():

def register_builtin_connections(connection_factory, moler_conn_class):
_register_builtin_connections(connection_factory, moler_conn_class) # unix & windows connections
if _running_python_3_5_or_above():
_register_python3_builtin_connections(connection_factory, moler_conn_class)
_register_python3_builtin_connections(connection_factory, moler_conn_class)

if _running_on_supported_unix():
_register_builtin_unix_connections(connection_factory, moler_conn_class) # unix-only connections
if _running_python_3_5_or_above():
_register_builtin_py3_unix_connections(connection_factory, moler_conn_class)
_register_builtin_py3_unix_connections(connection_factory, moler_conn_class)
elif _running_on_supported_windows():
pass # placeholder for windows-only connections
else:
Expand Down
7 changes: 1 addition & 6 deletions moler/config/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

__author__ = 'Grzegorz Latuszek, Marcin Usielski, Michal Ernst'
__copyright__ = 'Copyright (C) 2018-2023, Nokia'
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
__email__ = '[email protected], [email protected], [email protected]'

import codecs
Expand Down Expand Up @@ -514,11 +514,6 @@ def configure_moler_main_logger():
configure_moler_threads_logger()
logger.info("More logs in: {}".format(_logging_path))
_list_libraries(logger=logger)
if sys.version_info < (3, 7):
logger.warning("****************************************************\n"
"* Support for Python < 3.7 will be removed soon. *\n"
"* Please update your Python to 3.7 at least. *\n"
"****************************************************")
global _main_logger
_main_logger = logger

Expand Down
7 changes: 3 additions & 4 deletions moler/config/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"""

__author__ = 'Grzegorz Latuszek'
__copyright__ = 'Copyright (C) 2018, Nokia'
__email__ = '[email protected]'
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
__email__ = '[email protected], [email protected]'

import sys

Expand All @@ -26,8 +26,7 @@ def clear():

def register_builtin_runners(runner_factory):
_register_builtin_runners(runner_factory)
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 5):
_register_python3_builtin_runners(runner_factory)
_register_python3_builtin_runners(runner_factory)


def _register_builtin_runners(runner_factory):
Expand Down
13 changes: 6 additions & 7 deletions moler/connection_observer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

__author__ = 'Grzegorz Latuszek, Marcin Usielski, Michal Ernst'
__copyright__ = 'Copyright (C) 2018-2023 Nokia'
__copyright__ = 'Copyright (C) 2018-2024 Nokia'
__email__ = '[email protected], [email protected], [email protected]'

import logging
Expand Down Expand Up @@ -29,14 +29,16 @@
from moler.runner_factory import get_runner
from moler.command_scheduler import CommandScheduler
from moler.util.connection_observer_life_status import ConnectionObserverLifeStatus
from moler.abstract_moler_connection import AbstractMolerConnection
from moler.runner import ConnectionObserverRunner


@add_metaclass(ABCMeta)
class ConnectionObserver(object):
_not_raised_exceptions = list() # list of dict: "exception" and "time"
_exceptions_lock = threading.Lock()

def __init__(self, connection=None, runner=None):
def __init__(self, connection: AbstractMolerConnection = None, runner: ConnectionObserverRunner = None):
"""
Create instance of ConnectionObserver class
:param connection: connection used to receive data awaited for
Expand Down Expand Up @@ -324,11 +326,8 @@ def _set_exception_without_done(self, exception):
:param exception: exception to set
:return: None
"""
if sys.version_info >= (3, 6):
mg = traceback.format_list(traceback.extract_stack()[:-3] + traceback.extract_tb(exception.__traceback__))
stack_msg = ''.join(mg) + '\n {} {}'.format(exception.__class__, exception)
else:
stack_msg = traceback.format_exc()
mg = traceback.format_list(traceback.extract_stack()[:-3] + traceback.extract_tb(exception.__traceback__))
stack_msg = ''.join(mg) + '\n {} {}'.format(exception.__class__, exception)

if self._is_done:
self._log(logging.WARNING,
Expand Down
10 changes: 2 additions & 8 deletions moler/device/textualdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- be the state machine that controls which commands may run in given state
"""
__author__ = 'Grzegorz Latuszek, Marcin Usielski, Michal Ernst'
__copyright__ = 'Copyright (C) 2018-2023, Nokia'
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
__email__ = '[email protected], [email protected], [email protected]'

import abc
Expand All @@ -18,7 +18,7 @@
import time
import traceback
import threading

import queue
from moler.cmd.commandtextualgeneric import CommandTextualGeneric
from moler.connection_observer import ConnectionObserver
from moler.config.loggers import configure_device_logger
Expand All @@ -31,12 +31,6 @@
from moler.device.abstract_device import AbstractDevice
from moler.config.loggers import change_logging_suffix

try:
import queue
except ImportError:
# noinspection PyUnresolvedReferences
import Queue as queue # For python 2


# TODO: name, logger/logger_name as param
class TextualDevice(AbstractDevice):
Expand Down
5 changes: 1 addition & 4 deletions moler/events/textualevent.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-

__author__ = 'Marcin Usielski, Michal Ernst'
__copyright__ = 'Copyright (C) 2018-2021, Nokia'
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
__email__ = '[email protected], [email protected]'

import abc
import six
import sys
import logging
from moler.event import Event
from moler.cmd import RegexHelper
Expand Down Expand Up @@ -51,8 +50,6 @@ def data_received(self, data, recv_time):
if not self._paused:
self._last_recv_time_data_read_from_connection = recv_time
try:
# Workaround for some terminals and python 2.7
data = u"".join(str(data.encode("utf-8", errors="ignore"))) if sys.version_info < (3, 0) else data
lines = data.splitlines(True)
for current_chunk in lines:
if not self.done():
Expand Down
25 changes: 7 additions & 18 deletions moler/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@
"""

__author__ = 'Grzegorz Latuszek, Michal Ernst, Marcin Usielski'
__copyright__ = 'Copyright (C) 2018-2023, Nokia'
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
__email__ = '[email protected], [email protected], [email protected]'

import copy
import importlib
import logging
import re
import sys
import collections.abc
from functools import wraps
from types import FunctionType, MethodType
from six import string_types
if sys.version_info > (3, 5):
from math import isclose

try:
import collections.abc as collections
except ImportError:
import collections
from math import isclose


class ClassProperty(property):
Expand Down Expand Up @@ -208,7 +203,7 @@ def create_object_from_name(full_class_name, constructor_params):
def update_dict(target_dict, expand_dict):
for key, value in expand_dict.items():
if (key in target_dict and isinstance(target_dict[key], dict) and isinstance(expand_dict[key],
collections.Mapping)):
collections.abc.Mapping)):
update_dict(target_dict[key], expand_dict[key])
else:
target_dict[key] = expand_dict[key]
Expand Down Expand Up @@ -275,15 +270,9 @@ def diff_data(first_object, second_object, significant_digits=None,
abs_tol = 0.0001
if significant_digits:
abs_tol = 1.0 / 10 ** significant_digits
if sys.version_info > (3, 5):
if not isclose(first_object, second_object, abs_tol=abs_tol):
return "{} the first value {} is different from the second value" \
" {}.".format(msg, first_object, second_object)
else:
# Remove when no support for Python 2.7
if abs(first_object - second_object) > abs_tol:
return "{} the first value {} is different from the second value" \
" {}.".format(msg, first_object, second_object)
if not isclose(first_object, second_object, abs_tol=abs_tol):
return "{} the first value {} is different from the second value" \
" {}.".format(msg, first_object, second_object)
else:
if first_object != second_object:
return "{} First value {} is different from the second {}.".format(
Expand Down
12 changes: 3 additions & 9 deletions moler/observer_thread_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@
"""Wrapper for observer registered in ThreadedMolerConnection (old name: ObservableConnection)."""

__author__ = 'Marcin Usielski'
__copyright__ = 'Copyright (C) 2020-2023, Nokia'
__copyright__ = 'Copyright (C) 2020-2024, Nokia'
__email__ = '[email protected]'

import logging
import traceback
import threading
from threading import Thread

import queue
from moler.util import tracked_thread
from moler.config.loggers import TRACE
from moler.exceptions import CommandFailure, MolerException

try:
import queue
except ImportError:
# noinspection PyUnresolvedReferences
import Queue as queue # For python 2
from threading import Thread


class ObserverThreadWrapper(object):
Expand Down
17 changes: 5 additions & 12 deletions moler/runner_single_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@
"""

__author__ = 'Marcin Usielski'
__copyright__ = 'Copyright (C) 2021-2023, Nokia'
__copyright__ = 'Copyright (C) 2021-2024, Nokia'
__email__ = '[email protected]'


from threading import Lock
import threading
import logging
import time
from moler.runner import ConnectionObserverRunner
from moler.exceptions import CommandTimeout
from moler.exceptions import ConnectionObserverTimeout
from moler.util.loghelper import log_into_logger
from moler.helpers import copy_list
import threading
import logging
import time

try:
import queue
except ImportError:
# noinspection PyUnresolvedReferences
import Queue as queue # For python 2


class RunnerSingleThread(ConnectionObserverRunner):
Expand All @@ -48,7 +41,7 @@ def __init__(self):
name="RunnerSingle-{}".format(RunnerSingleThread._th_nr)
)
RunnerSingleThread._th_nr += 1
self._connection_observer_lock = Lock()
self._connection_observer_lock = threading.Lock()
self._loop_thread.daemon = True
self._loop_thread.start()

Expand Down
22 changes: 2 additions & 20 deletions moler/util/cmds_events_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
from __future__ import print_function

__author__ = 'Grzegorz Latuszek', 'Michal Ernst', 'Michal Plichta, Marcin Usielski'
__copyright__ = 'Copyright (C) 2018-2023, Nokia'
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
__email__ = '[email protected]', '[email protected]', '[email protected],' \
' [email protected]'

import collections
import sys
import time
from argparse import ArgumentParser
from datetime import datetime
from importlib import import_module
from os import walk, sep
from os.path import abspath, join, relpath, exists, split
from pprint import pformat
import time

from moler.command import Command
from moler.event import Event
Expand Down Expand Up @@ -200,18 +199,6 @@ def _reformat_str_to_unicode(cmd_result):
return cmd_result


def _convert_str_to_unicode(input):
if isinstance(input, dict):
return {_convert_str_to_unicode(key): _convert_str_to_unicode(value) for key, value in input.items()}
elif isinstance(input, list):
return [_convert_str_to_unicode(element) for element in input]
elif isinstance(input, str):
# noinspection PyUnresolvedReferences
return input.decode('utf-8') # Python 2.7
else:
return input


def _run_command_parsing_test(moler_cmd, creation_str, buffer_io, cmd_output, cmd_result, variant, base_class,
observer_type):
with buffer_io: # open it (autoclose by context-mngr)
Expand All @@ -226,11 +213,6 @@ def _run_command_parsing_test(moler_cmd, creation_str, buffer_io, cmd_output, cm
buffer_io.remote_inject_response([cmd_output])
result = moler_cmd()

if sys.version_info < (3, 0):
# workaround for python2.7 - convert str to unicode
cmd_result = _convert_str_to_unicode(cmd_result)
result = _convert_str_to_unicode(result)

try:
diff = compare_objects(cmd_result, result, significant_digits=6, exclude_types=exclude_types)
except TypeError:
Expand Down
10 changes: 2 additions & 8 deletions moler/util/devices_SM.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"""

__author__ = 'Michal Ernst, Marcin Usielski'
__copyright__ = 'Copyright (C) 2019-2023, Nokia'
__copyright__ = 'Copyright (C) 2019-2024, Nokia'
__email__ = '[email protected], [email protected]'

import os
import random
import time
import math
import threading

import queue
from moler.io.raw.memory import ThreadedFifoBuffer
from moler.device import DeviceFactory
from moler.device.textualdevice import TextualDevice
Expand All @@ -21,12 +21,6 @@
from moler.helpers import copy_list
from moler.util.moler_test import MolerTest

try:
import queue
except ImportError:
# noinspection PyUnresolvedReferences
import Queue as queue # Python 2 and 3.


def iterate_over_device_states(device, max_time=None, tests_per_device=300, max_no_of_threads=11, rerun=0,
timeout_multiply=3.0):
Expand Down
Loading