<commit_before># Copyright (c) 2015  Kontron Europe GmbH
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import logging
from tclproto import TclClient
from ixapi import _MetaIxTclApi, TclMember, FLAG_RDONLY
from ixapi import IxTclHalApi, IxTclHalError

log = logging.getLogger(__name__)

class PortGroup(object):
    START_TRANSMIT = 7
    STOP_TRANSMIT = 8
    START_CAPTURE = 9
    STOP_CAPTURE = 10
    RESET_STATISTICS = 13
    PAUSE_TRANSMIT = 15
    STEP_TRANSMIT = 16
    TRANSMIT_PING = 17
    TAKE_OWNERSHIP = 40
    TAKE_OWNERSHIP_FORCED = 41
    CLEAR_OWNERSHIP = 42
    CLEAR_OWNERSHIP_FORCED = 43

    __metaclass__ = _MetaIxTclApi
    __tcl_command__ = 'portGroup'
    __tcl_members__ = [
            TclMember('lastTimeStamp', type=int, flags=FLAG_RDONLY),
    ]

    next_free_id = 1

    def __init__(self, api, id=None):
        self._api = api
        if id is None:
            self.id = self.next_free_id
            self.next_free_id += 1
        else:
            self.id = id

    def _ix_get(self):
        pass

    def create(self):
        self._api.call_rc('portGroup create %s', self.id)

    def destroy(self):
        self._api.call_rc('portGroup destroy %s', self.id)

    def add_port(self, port):
        self._api.call_rc('portGroup add %s %d %d %d',
                self.id, *port._port_id())

    def del_port(self, port):
        self._api.call_rc('portGroup del %s %d %d %d',
                self.id, *port._port_id())

    def _set_command(self, cmd):
        self._api.call_rc('portGroup setCommand %s %d', self.id, cmd)

    def start_transmit(self):
        self._set_command(self.START_TRANSMIT)

    def stop_transmit(self):
        self._set_command(self.STOP_TRANSMIT)

    def start_capture(self):
        self._set_command(self.START_CAPTURE)

    def stop_capture(self):
        self._set_command(self.STOP_CAPTURE)

    def reset_statistics(self):
        self._set_command(self.RESET_STATISTICS)

    def pause_transmit(self):
        self._set_command(self.PAUSE_TRANSMIT)

    def step_transmit(self):
        self._set_command(self.STEP_TRANSMIT)

    def transmit_ping(self):
        self._set_command(self.TRANSMIT_PING)

    def take_ownership(self, force=False):
        if not force:
            self._set_command(self.TAKE_OWNERSHIP)
        else:
            self._set_command(self.TAKE_OWNERSHIP_FORCED)

    def clear_ownership(self, force=False):
        if not force:
            self._set_command(self.CLEAR_OWNERSHIP)
        else:
            self._set_command(self.CLEAR_OWNERSHIP_FORCED)


class Statistics(object):
    """Per port statistics."""
    __metaclass__ = _MetaIxTclApi
    __tcl_command__ = 'stat'
    __tcl_members__ = [
            TclMember('bytesReceived', type=int, flags=FLAG_RDONLY),
            TclMember('bytesSent', type=int, flags=FLAG_RDONLY),
            TclMember('bitsReceived', type=int, flags=FLAG_RDONLY),
            TclMember('bitsSent', type=int, flags=FLAG_RDONLY),
            TclMember('framesReceived', type=int, flags=FLAG_RDONLY),
            TclMember('framesSent', type=int, flags=FLAG_RDONLY),
            TclMember('fcsErrors', type=int, flags=FLAG_RDONLY),
            TclMember('framerFCSErrors', type=int, flags=FLAG_RDONLY),
            TclMember('fragments', type=int, flags=FLAG_RDONLY),
    ]

    def __init__(self, api, port):
        self._api = api
        self.port = port

    def _ix_get(self, member):
        self._api.call('stat get %s %d %d %d',
                member.name, *self.port._port_id())

    def _ix_set(self, member):
        self._api.call('stat set %s %d %d %d',
                member.name, *self.port._port_id())


class Port(object):
    __metaclass__ = _MetaIxTclApi
    __tcl_command__ = 'port'
    __tcl_members__ = [
            TclMember('name'),
            TclMember('owner', flags=FLAG_RDONLY),
            TclMember('type', type=int, flags=FLAG_RDONLY),
            TclMember('loopback'),
            TclMember('flowControl'),
            TclMember('linkState', type=int, flags=FLAG_RDONLY),
            TclMember('portMode', type=int),
            TclMember('transmitMode'),
    ]<commit_msg>unify variable name in __init__.py<commit_after># Copyright (c) 2015  Kontron Europe GmbH
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import logging
from tclproto import TclClient
from ixapi import _MetaIxTclApi, TclMember, FLAG_RDONLY
from ixapi import IxTclHalApi, IxTclHalError

log = logging.getLogger(__name__)

class PortGroup(object):
    START_TRANSMIT = 7
    STOP_TRANSMIT = 8
    START_CAPTURE = 9
    STOP_CAPTURE = 10
    RESET_STATISTICS = 13
    PAUSE_TRANSMIT = 15
    STEP_TRANSMIT = 16
    TRANSMIT_PING = 17
    TAKE_OWNERSHIP = 40
    TAKE_OWNERSHIP_FORCED = 41
    CLEAR_OWNERSHIP = 42
    CLEAR_OWNERSHIP_FORCED = 43

    __metaclass__ = _MetaIxTclApi
    __tcl_command__ = 'portGroup'
    __tcl_members__ = [
            TclMember('lastTimeStamp', type=int, flags=FLAG_RDONLY),
    ]

    next_free_id = 1

    def __init__(self, api, id=None):
        self._api = api
        if id is None:
            self.id = self.next_free_id
            self.next_free_id += 1
        else:
            self.id = id

    def _ix_get(self):
        pass

    def create(self):
        self._api.call_rc('portGroup create %s', self.id)

    def destroy(self):
        self._api.call_rc('portGroup destroy %s', self.id)

    def add_port(self, port):
        self._api.call_rc('portGroup add %s %d %d %d',
                self.id, *port._port_id())

    def del_port(self, port):
        self._api.call_rc('portGroup del %s %d %d %d',
                self.id, *port._port_id())

    def _set_command(self, cmd):
        self._api.call_rc('portGroup setCommand %s %d', self.id, cmd)

    def start_transmit(self):
        self._set_command(self.START_TRANSMIT)

    def stop_transmit(self):
        self._set_command(self.STOP_TRANSMIT)

    def start_capture(self):
        self._set_command(self.START_CAPTURE)

    def stop_capture(self):
        self._set_command(self.STOP_CAPTURE)

    def reset_statistics(self):
        self._set_command(self.RESET_STATISTICS)

    def pause_transmit(self):
        self._set_command(self.PAUSE_TRANSMIT)

    def step_transmit(self):
        self._set_command(self.STEP_TRANSMIT)

    def transmit_ping(self):
        self._set_command(self.TRANSMIT_PING)

    def take_ownership(self, force=False):
        if not force:
            self._set_command(self.TAKE_OWNERSHIP)
        else:
            self._set_command(self.TAKE_OWNERSHIP_FORCED)

    def clear_ownership(self, force=False):
        if not force:
            self._set_command(self.CLEAR_OWNERSHIP)
        else:
            self._set_command(self.CLEAR_OWNERSHIP_FORCED)


class Statistics(object):
    """Per port statistics."""
    __metaclass__ = _MetaIxTclApi
    __tcl_command__ = 'stat'
    __tcl_members__ = [
            TclMember('bytesReceived', type=int, flags=FLAG_RDONLY),
            TclMember('bytesSent', type=int, flags=FLAG_RDONLY),
            TclMember('bitsReceived', type=int, flags=FLAG_RDONLY),
            TclMember('bitsSent', type=int, flags=FLAG_RDONLY),
            TclMember('framesReceived', type=int, flags=FLAG_RDONLY),
            TclMember('framesSent', type=int, flags=FLAG_RDONLY),
            TclMember('fcsErrors', type=int, flags=FLAG_RDONLY),
            TclMember('framerFCSErrors', type=int, flags=FLAG_RDONLY),
            TclMember('fragments', type=int, flags=FLAG_RDONLY),
    ]

    def __init__(self, tcl, port):
        self._api = tcl
        self.port = port

    def _ix_get(self, member):
        self._api.call('stat get %s %d %d %d',
                member.name, *self.port._port_id())

    def _ix_set(self, member):
        self._api.call('stat set %s %d %d %d',
                member.name, *self.port._port_id())


class Port(object):
    __metaclass__ = _MetaIxTclApi
    __tcl_command__ = 'port'
    __tcl_members__ = [
            TclMember('name'),
            TclMember('owner', flags=FLAG_RDONLY),
            TclMember('type', type=int, flags=FLAG_RDONLY),
            TclMember('loopback'),
            TclMember('flowControl'),
            TclMember('linkState', type=int, flags=FLAG_RDONLY),
            TclMember('portMode', type=int),
            TclMember('transmitMode'),
    ]
{'fraction_non_alphanumeric': 0.09937054999484057, 'fraction_numerical': 0.008255082034877721, 'mean_word_length': 2.815748031496063, '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': '4509352', 'n_tokens_mistral': 3311, 'n_tokens_neox': 3131, 'n_words': 746}