<commit_before>"""
Support for paramiko remote objects.
"""
from . import run
from .connection import connect
from teuthology import misc
import time
import pexpect
import re
import logging
from teuthology import lockstatus as ls

try:
    import libvirt
except ImportError:
    libvirt = None

log = logging.getLogger(__name__)


class Remote(object):

    """
    A connection to a remote host.

    This is a higher-level wrapper around Paramiko's `SSHClient`.
    """

    # for unit tests to hook into
    _runner = staticmethod(run.run)

    def __init__(self, name, ssh=None, shortname=None, console=None, host_key=None,
                 keep_alive=True):
        self.name = name
        self._shortname = shortname
        self.host_key = host_key
        self.keep_alive = keep_alive
        self.console = console
        if ssh is None:
            ssh = self._connect()
        self.ssh = ssh

    def _connect(self):
        return connect(user_at_host=self.name, host_key=self.host_key,
                       keep_alive=self.keep_alive)

    @property
    def shortname(self):
        """
        shortname decorator
        """
        name = self._shortname
        if name is None:
            name = self.name
        return name

    @property
    def hostname(self):
        return self.name.split('@')[1]

    @property
    def is_online(self):
        return self.ssh.get_transport().is_active()
<commit_msg>Make Remote.is_online more accurate<commit_after>"""
Support for paramiko remote objects.
"""
from . import run
from .connection import connect
from teuthology import misc
import time
import pexpect
import re
import logging
from teuthology import lockstatus as ls

try:
    import libvirt
except ImportError:
    libvirt = None

log = logging.getLogger(__name__)


class Remote(object):

    """
    A connection to a remote host.

    This is a higher-level wrapper around Paramiko's `SSHClient`.
    """

    # for unit tests to hook into
    _runner = staticmethod(run.run)

    def __init__(self, name, ssh=None, shortname=None, console=None, host_key=None,
                 keep_alive=True):
        self.name = name
        self._shortname = shortname
        self.host_key = host_key
        self.keep_alive = keep_alive
        self.console = console
        if ssh is None:
            ssh = self._connect()
        self.ssh = ssh

    def _connect(self):
        return connect(user_at_host=self.name, host_key=self.host_key,
                       keep_alive=self.keep_alive)

    @property
    def shortname(self):
        """
        shortname decorator
        """
        name = self._shortname
        if name is None:
            name = self.name
        return name

    @property
    def hostname(self):
        return self.name.split('@')[1]

    @property
    def is_online(self):
        try:
            self.run(args="echo online")
        except Exception:
            pass
        return self.ssh.get_transport().is_active()

{'fraction_non_alphanumeric': 0.08481394569225612, 'fraction_numerical': 0.0006704659738518271, 'mean_word_length': 2.2505446623093683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1185761', 'n_tokens_mistral': 891, 'n_tokens_neox': 856, 'n_words': 251}