<commit_before># -*- coding:utf-8 -*-

# Copyright 2015 NEC Corporation.                                          #
#                                                                          #
# Licensed under the Apache License, Version 2.0 (the "License");          #
# you may not use this file except in compliance with the License.         #
# You may obtain a copy of the License at                                  #
#                                                                          #
#   http://www.apache.org/licenses/LICENSE-2.0                             #
#                                                                          #
# Unless required by applicable law or agreed to in writing, software      #
# distributed under the License is distributed on an "AS IS" BASIS,        #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and      #
# limitations under the License.                                           #

import copy
import signal
import sys
import threading
import time
from functools import partial

from org.o3project.odenos.core.component.network.flow.ofpflow.ofp_flow_match import OFPFlowMatch
from org.o3project.odenos.core.component.network.flow.basic.basic_flow import BasicFlow
from org.o3project.odenos.core.component.network.flow.basic.basic_flow_match import BasicFlowMatch
from org.o3project.odenos.core.component.network.flow.basic.flow_action_output import FlowActionOutput
from org.o3project.odenos.core.component.network.flow.flow import Flow
from org.o3project.odenos.core.component.network.flow.flow_set import FlowSet
from org.o3project.odenos.core.component.network.flow.ofpflow.ofp_flow import OFPFlow
from org.o3project.odenos.core.component.network.packet.in_packet import InPacket
from org.o3project.odenos.core.component.network.packet.ofp_in_packet import OFPInPacket
from org.o3project.odenos.core.component.network.packet.ofp_out_packet import OFPOutPacket
from org.o3project.odenos.core.component.network.packet.out_packet import OutPacket
from org.o3project.odenos.core.component.network.packet.packet import Packet
from org.o3project.odenos.core.component.network.packet.packet_status import PacketStatus
from org.o3project.odenos.core.component.network.topology.link import Link
from org.o3project.odenos.core.component.network.topology.node import Node
from org.o3project.odenos.core.component.network.topology.port import Port
from org.o3project.odenos.core.component.network.topology.topology import Topology
from org.o3project.odenos.core.util.network_interface import NetworkInterface
from org.o3project.odenos.core.util.remote_object_interface import RemoteObjectInterface
from org.o3project.odenos.core.util.system_manager_interface import SystemManagerInterface
from org.o3project.odenos.remoteobject.manager.system.component_connection import ComponentConnection
from org.o3project.odenos.remoteobject.manager.system.component_connection_logic_and_network import ComponentConnectionLogicAndNetwork
from org.o3project.odenos.remoteobject.message.request import Request
from org.o3project.odenos.remoteobject.message.response import Response
from org.o3project.odenos.remoteobject.object_property import ObjectProperty
from org.o3project.odenos.remoteobject.transport.message_dispatcher import MessageDispatcher


def signal_handler(num, stack, obj):
    print 'Received signal %d' % num
    del obj
    sys.exit()


class ServerThread(threading.Thread):
    def __init__(self, dispatcher):
        threading.Thread.__init__(self)
        self.disp = dispatcher

    def run(self):
        self.disp.start()


class OdenosConfigurator(object):
    CM1 = "romgr1"
    CM2 = "romgr2"
    CM3 = "romgr3"
    DEF_ATTR = {"oper_status": "UP"}
    DEF_VENDOR = "VENDOR1"

    def __init__(self, dispatcher=None):
      if dispatcher is None:
        bound_func = partial(signal_handler, obj=self)
        signal.signal(signal.SIGINT, bound_func)
        signal.signal(signal.SIGTERM, bound_func)

      self.disp = MessageDispatcher()
      if dispatcher is None:
        self.thread = ServerThread(self.disp)
        self.thread.start()
        
      self.sysmgr = SystemManagerInterface(self.disp)
      self.stations = {}
      self.packet_id = 0;

    def __del__(self):
        self.thread.join()
        self.disp.stop()

    def create_component(self, type, name, cm_id):
        obj = ObjectProperty(type, name)
        obj.set_property("version", "1")<commit_msg>update python/configurator.py<commit_after># -*- coding:utf-8 -*-

# Copyright 2015 NEC Corporation.                                          #
#                                                                          #
# Licensed under the Apache License, Version 2.0 (the "License");          #
# you may not use this file except in compliance with the License.         #
# You may obtain a copy of the License at                                  #
#                                                                          #
#   http://www.apache.org/licenses/LICENSE-2.0                             #
#                                                                          #
# Unless required by applicable law or agreed to in writing, software      #
# distributed under the License is distributed on an "AS IS" BASIS,        #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and      #
# limitations under the License.                                           #

import copy
import signal
import sys
import threading
import time
from functools import partial

from org.o3project.odenos.core.component.network.flow.ofpflow.ofp_flow_match import OFPFlowMatch
from org.o3project.odenos.core.component.network.flow.basic.basic_flow import BasicFlow
from org.o3project.odenos.core.component.network.flow.basic.basic_flow_match import BasicFlowMatch
from org.o3project.odenos.core.component.network.flow.basic.flow_action_output import FlowActionOutput
from org.o3project.odenos.core.component.network.flow.flow import Flow
from org.o3project.odenos.core.component.network.flow.flow_set import FlowSet
from org.o3project.odenos.core.component.network.flow.ofpflow.ofp_flow import OFPFlow
from org.o3project.odenos.core.component.network.packet.in_packet import InPacket
from org.o3project.odenos.core.component.network.packet.ofp_in_packet import OFPInPacket
from org.o3project.odenos.core.component.network.packet.ofp_out_packet import OFPOutPacket
from org.o3project.odenos.core.component.network.packet.out_packet import OutPacket
from org.o3project.odenos.core.component.network.packet.packet import Packet
from org.o3project.odenos.core.component.network.packet.packet_status import PacketStatus
from org.o3project.odenos.core.component.network.topology.link import Link
from org.o3project.odenos.core.component.network.topology.node import Node
from org.o3project.odenos.core.component.network.topology.port import Port
from org.o3project.odenos.core.component.network.topology.topology import Topology
from org.o3project.odenos.core.util.network_interface import NetworkInterface
from org.o3project.odenos.core.util.remote_object_interface import RemoteObjectInterface
from org.o3project.odenos.core.util.system_manager_interface import SystemManagerInterface
from org.o3project.odenos.remoteobject.manager.system.component_connection import ComponentConnection
from org.o3project.odenos.remoteobject.manager.system.component_connection_logic_and_network import ComponentConnectionLogicAndNetwork
from org.o3project.odenos.remoteobject.message.request import Request
from org.o3project.odenos.remoteobject.message.response import Response
from org.o3project.odenos.remoteobject.object_property import ObjectProperty
from org.o3project.odenos.remoteobject.transport.message_dispatcher import MessageDispatcher


def signal_handler(num, stack, obj):
    print 'Received signal %d' % num
    del obj
    sys.exit()


class ServerThread(threading.Thread):
    def __init__(self, dispatcher):
        threading.Thread.__init__(self)
        self.disp = dispatcher

    def run(self):
        self.disp.start()


class OdenosConfigurator(object):
    CM1 = "romgr1"
    CM2 = "romgr2"
    CM3 = "romgr3"
    DEF_ATTR = {"oper_status": "UP"}
    DEF_VENDOR = "VENDOR1"

    def __init__(self, dispatcher=None):
      if dispatcher is None:
        bound_func = partial(signal_handler, obj=self)
        signal.signal(signal.SIGINT, bound_func)
        signal.signal(signal.SIGTERM, bound_func)

      self.disp = dispatcher
      if dispatcher is None:
        self.disp = MessageDispatcher()
        self.thread = ServerThread(self.disp)
        self.thread.start()
        
      self.sysmgr = SystemManagerInterface(self.disp)
      self.stations = {}
      self.packet_id = 0;

    def __del__(self):
        self.thread.join()
        self.disp.stop()

    def create_component(self, type, name, cm_id):
        obj = ObjectProperty(type, name)
        obj.set_property("version", "1")
{'fraction_non_alphanumeric': 0.08036789663856345, 'fraction_numerical': 0.009635388152852293, 'mean_word_length': 2.9747606614447344, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4822763', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2471, 'n_words': 562}