コード例 #1
0
    def __init__(self, buffer_size=2048):
        self._buffer_size = buffer_size
        self._connection_socket = None
        self._request_handler = None

        self._server_socket_timeout = ConfigurationParser.get(
            "common_variable", "server_timeout")
        self._commands_dict = dict()

        self._re_command_end = r'</Commands>'
        self._end_command = '\r\n'

        self._parsing_error_xml = XMLWrapper.parse_xml_from_file(
            get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                          'common/response_template/'
                          'parsing_error.xml'))

        self._command_response_data = open(
            get_file_path(
                ConfigurationParser.L1_CORE_FOLDER, 'common/response_template/'
                'command_response_template.xml')).read()

        self._responses_data = open(
            get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                          'common/response_template/'
                          'responses_template.xml')).read()
コード例 #2
0
    def convert_to_xml(self, resource_template=None, attribute_template=None, incoming_map_template=None, relative_address=''):
        if resource_template is None:
            resource_template = open(get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                                                   'common/response_template/'
                                                   'resource_template.xml')).read()

        if attribute_template is None:
            attribute_template = open(get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                                                    'common/response_template/'
                                                    'resource_attribute_template.xml')).read()

        if incoming_map_template is None:
            incoming_map_template = open(get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                                                       'common/response_template/'
                                                       'resource_incoming_map_template.xml')).read()

        resource_node = XMLWrapper.parse_xml(resource_template)

        XMLWrapper.set_node_attr(resource_node, "Name",
                                 attr_value=self.get_resource_attribute("resource_name", self._index))
        XMLWrapper.set_node_attr(resource_node, "ResourceFamilyName",
                                 attr_value=self.get_resource_attribute("resource_family_name"))
        XMLWrapper.set_node_attr(resource_node, "ResourceModelName",
                                 attr_value=self.get_resource_attribute("resource_model_name", self._model_name))
        XMLWrapper.set_node_attr(resource_node, "SerialNumber",
                                 attr_value=self._serial_number)

        if self._depth != 0:
            relative_address += "/" + self._index
        else:
            relative_address = self._address

        XMLWrapper.set_node_attr(resource_node, "Address", attr_value=relative_address)

        resource_attributes_node = XMLWrapper.get_child_node(resource_node, "ResourceAttributes")
        for name, value in self._attributes_data.items():
            attribute_node = XMLWrapper.parse_xml(attribute_template)

            type_str = self._get_attribute_type(value)

            XMLWrapper.set_node_attr(attribute_node, "Name", attr_value=name)
            XMLWrapper.set_node_attr(attribute_node, "Type", attr_value=type_str)
            XMLWrapper.set_node_attr(attribute_node, "Value", attr_value=str(value))

            XMLWrapper.append_child(resource_attributes_node, attribute_node)

        if len(self._map_path) > 0:
            incoming_map_node = XMLWrapper.parse_xml(incoming_map_template)
            child_incoming_node = XMLWrapper.get_child_node(incoming_map_node, "IncomingMapping")
            XMLWrapper.set_node_text(child_incoming_node, self._map_path)
            XMLWrapper.append_child(resource_node, incoming_map_node)

        child_resources_node = XMLWrapper.get_child_node(resource_node, "ChildResources")
        for index, value in self._child_resource_data.items():
            child_resource_node = value.convert_to_xml(resource_template, attribute_template, incoming_map_template,
                                                       relative_address)
            XMLWrapper.append_child(child_resources_node, child_resource_node)

        return resource_node
コード例 #3
0
    def init():
        if ConfigurationParser._CONFIG_JSON is None:
            configure_path = ConfigurationParser._CONFIG_PATH
            json_data = open(get_file_path(ConfigurationParser._ROOT_FOLDER, configure_path)).read()
            ConfigurationParser._CONFIG_JSON = json.loads(json_data)

        if ConfigurationParser._RUNTIME_CONFIG_JSON is None:
            configure_path = ConfigurationParser._ROOT_FOLDER + \
                             ConfigurationParser._CONFIG_JSON["common_variable"]["runtime_configuration"]
            json_data = open(configure_path).read()
            ConfigurationParser._RUNTIME_CONFIG_JSON = json.loads(json_data)
コード例 #4
0
    def __init__(self):
        self._driver_handler = None
        self._state_id = '-1'

        self._device_address = None
        self._device_user = None
        self._device_password = None

        self._state_id_template = open(get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                                                     'common/response_template/'
                                                     'state_id_template.xml')).read()
        self.init_driver_handler()
コード例 #5
0
    def __init__(self):
        self._driver_handler = None
        self._state_id = '-1'

        self._device_address = None
        self._device_user = None
        self._device_password = None

        self._state_id_template = open(
            get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                          'common/response_template/'
                          'state_id_template.xml')).read()
        self.init_driver_handler()
コード例 #6
0
    def __init__(self, buffer_size=2048):
        self._buffer_size = buffer_size
        self._connection_socket = None
        self._request_handler = None

        self._server_socket_timeout = ConfigurationParser.get("common_variable", "server_timeout")
        self._commands_dict = dict()

        self._re_command_end = r'</Commands>'
        self._end_command = '\r\n'

        self._parsing_error_xml = XMLWrapper.parse_xml_from_file(get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                                                                               'common/response_template/'
                                                                               'parsing_error.xml'))

        self._command_response_data = open(get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                                                         'common/response_template/'
                                                         'command_response_template.xml')).read()

        self._responses_data = open(get_file_path(ConfigurationParser.L1_CORE_FOLDER,
                                                  'common/response_template/'
                                                  'responses_template.xml')).read()
コード例 #7
0
    def init():
        if ConfigurationParser._CONFIG_JSON is None:
            configure_path = ConfigurationParser._CONFIG_PATH
            json_data = open(get_file_path(ConfigurationParser._ROOT_FOLDER, configure_path)).read()
            ConfigurationParser._CONFIG_JSON = json.loads(json_data)

        if ConfigurationParser._RUNTIME_CONFIG_JSON is None:
            configure_path = ConfigurationParser._ROOT_FOLDER + \
                             ConfigurationParser._CONFIG_JSON.get("common_variable", {}).get("runtime_configuration", "")
            if os.path.exists(configure_path):
                json_data = open(configure_path).read()
                ConfigurationParser._RUNTIME_CONFIG_JSON = json.loads(json_data)
            else:
                raise Exception("Runtime configuration file '{}' is missing".format(configure_path))
コード例 #8
0
    def convert_to_xml(self,
                       resource_template=None,
                       attribute_template=None,
                       incoming_map_template=None,
                       relative_address=''):
        if resource_template is None:
            resource_template = open(
                get_file_path(
                    ConfigurationParser.L1_CORE_FOLDER,
                    'common/response_template/'
                    'resource_template.xml')).read()

        if attribute_template is None:
            attribute_template = open(
                get_file_path(
                    ConfigurationParser.L1_CORE_FOLDER,
                    'common/response_template/'
                    'resource_attribute_template.xml')).read()

        if incoming_map_template is None:
            incoming_map_template = open(
                get_file_path(
                    ConfigurationParser.L1_CORE_FOLDER,
                    'common/response_template/'
                    'resource_incoming_map_template.xml')).read()

        resource_node = XMLWrapper.parse_xml(resource_template)

        XMLWrapper.set_node_attr(resource_node,
                                 "Name",
                                 attr_value=self.get_resource_attribute(
                                     "resource_name", self._index))
        XMLWrapper.set_node_attr(
            resource_node,
            "ResourceFamilyName",
            attr_value=self.get_resource_attribute("resource_family_name"))
        XMLWrapper.set_node_attr(resource_node,
                                 "ResourceModelName",
                                 attr_value=self.get_resource_attribute(
                                     "resource_model_name", self._model_name))
        XMLWrapper.set_node_attr(resource_node,
                                 "SerialNumber",
                                 attr_value=self._serial_number)

        if self._depth != 0:
            relative_address += "/" + str(self._index)
        else:
            relative_address = self._address

        XMLWrapper.set_node_attr(resource_node,
                                 "Address",
                                 attr_value=relative_address)

        resource_attributes_node = XMLWrapper.get_child_node(
            resource_node, "ResourceAttributes")
        for name, value in self._attributes_data.items():
            attribute_node = XMLWrapper.parse_xml(attribute_template)

            type_str = self._get_attribute_type(value)

            XMLWrapper.set_node_attr(attribute_node, "Name", attr_value=name)
            XMLWrapper.set_node_attr(attribute_node,
                                     "Type",
                                     attr_value=type_str)
            XMLWrapper.set_node_attr(attribute_node,
                                     "Value",
                                     attr_value=str(value))

            XMLWrapper.append_child(resource_attributes_node, attribute_node)

        if len(self._map_path) > 0:
            incoming_map_node = XMLWrapper.parse_xml(incoming_map_template)
            child_incoming_node = XMLWrapper.get_child_node(
                incoming_map_node, "IncomingMapping")
            XMLWrapper.set_node_text(child_incoming_node, self._map_path)
            XMLWrapper.append_child(resource_node, incoming_map_node)

        child_resources_node = XMLWrapper.get_child_node(
            resource_node, "ChildResources")
        for index, value in self._child_resource_data.items():
            child_resource_node = value.convert_to_xml(resource_template,
                                                       attribute_template,
                                                       incoming_map_template,
                                                       relative_address)
            XMLWrapper.append_child(child_resources_node, child_resource_node)

        return resource_node