Page MenuHomec4science

debug_message.py
No OneTemporary

File Metadata

Created
Mon, May 20, 23:56

debug_message.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" This class can be used to represent a debug message.
"""
# Copyright (C) University of Basel 2019 {{{1
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/> 1}}}
__author__ = "Christian Steiner"
__maintainer__ = __author__
__copyright__ = 'University of Basel'
__email__ = "christian.steiner@unibas.ch"
__status__ = "Development"
__license__ = "GPL v3"
__version__ = "0.0.1"
from lxml import etree as ET
from .attachable_object import AttachableObject
class DebugMessage(AttachableObject):
"""
This class represents a debug message.
Args:
id (int): object id
message (str): debug message
"""
XML_TAG = 'debug'
def __init__(self, node=None, id=0, message='', tag=XML_TAG):
self.stringKeys = [ 'id', 'message' ]
self.attachable_objects = []
if node is not None:
self.id = node.get('id')
self.message = node.get('message')
self.tag = node.tag
else:
self.id = str(id)
self.message = message
self.tag = tag
def attach_object_to_tree(self, target_tree):
"""Attach object to tree.
"""
if target_tree.__class__.__name__ == '_ElementTree':
target_tree = target_tree.getroot()
obj_node = target_tree.xpath('.//' + self.tag + '[@id="%s"]' % self.id)[0] \
if(len(target_tree.xpath('.//' + self.tag + '[@id="%s"]' % self.id)) > 0) \
else ET.SubElement(target_tree, self.tag)
for key in self.stringKeys:
if self.__dict__[key] is not None:
obj_node.set(key.replace('_','-'), self.__dict__[key])
for attachable_object in self.attachable_objects:
attachable_object.attach_object_to_tree(obj_node)

Event Timeline