2010-02-23 13:20:05 +00:00
|
|
|
#
|
|
|
|
# base.py
|
|
|
|
#
|
2015-05-06 17:38:57 +00:00
|
|
|
# Copyright (C) 2009-2015 Red Hat, Inc.
|
2010-02-23 13:20:05 +00:00
|
|
|
#
|
|
|
|
# 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 2 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# Red Hat Author(s): Martin Gracik <mgracik@redhat.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
from abc import ABCMeta, abstractmethod
|
|
|
|
import sys
|
|
|
|
|
2014-05-09 00:21:34 +00:00
|
|
|
import pylorax.output as output
|
2010-02-23 13:20:05 +00:00
|
|
|
|
|
|
|
|
2015-05-06 17:38:57 +00:00
|
|
|
class BaseLoraxClass(object, metaclass=ABCMeta):
|
2010-02-23 13:20:05 +00:00
|
|
|
@abstractmethod
|
|
|
|
def __init__(self):
|
|
|
|
self.output = output.LoraxOutput()
|
|
|
|
|
2010-12-02 11:41:14 +00:00
|
|
|
def pcritical(self, msg, fobj=sys.stdout):
|
|
|
|
self.output.critical(msg, fobj)
|
2010-02-23 13:20:05 +00:00
|
|
|
|
2010-12-02 11:41:14 +00:00
|
|
|
def perror(self, msg, fobj=sys.stdout):
|
|
|
|
self.output.error(msg, fobj)
|
2010-02-23 13:20:05 +00:00
|
|
|
|
2010-12-02 11:41:14 +00:00
|
|
|
def pwarning(self, msg, fobj=sys.stdout):
|
|
|
|
self.output.warning(msg, fobj)
|
2010-02-23 13:20:05 +00:00
|
|
|
|
2010-12-02 11:41:14 +00:00
|
|
|
def pinfo(self, msg, fobj=sys.stdout):
|
|
|
|
self.output.info(msg, fobj)
|
2010-02-23 13:20:05 +00:00
|
|
|
|
2010-12-02 11:41:14 +00:00
|
|
|
def pdebug(self, msg, fobj=sys.stdout):
|
|
|
|
self.output.debug(msg, fobj)
|
2010-11-23 11:49:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DataHolder(dict):
|
|
|
|
|
2010-11-23 12:19:36 +00:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
dict.__init__(self)
|
|
|
|
|
|
|
|
for attr, value in kwargs.items():
|
|
|
|
self[attr] = value
|
|
|
|
|
2010-11-23 11:49:02 +00:00
|
|
|
def __getattr__(self, attr):
|
2016-05-04 17:34:02 +00:00
|
|
|
if attr in self:
|
|
|
|
return self[attr]
|
|
|
|
else:
|
|
|
|
raise AttributeError
|
2010-11-23 11:49:02 +00:00
|
|
|
|
|
|
|
def __setattr__(self, attr, value):
|
|
|
|
self[attr] = value
|
2011-06-24 21:42:53 +00:00
|
|
|
|
|
|
|
def copy(self):
|
|
|
|
return DataHolder(**dict.copy(self))
|