From: Frank Brehm Date: Mon, 13 Mar 2017 15:25:13 +0000 (+0100) Subject: Adding pp_lib/app.py X-Git-Tag: 0.1.2~272 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=15f395af319e285a46092648c69aa85f74e353fc;p=pixelpark%2Fadmin-tools.git Adding pp_lib/app.py --- diff --git a/pp_lib/app.py b/pp_lib/app.py new file mode 100644 index 0000000..749947c --- /dev/null +++ b/pp_lib/app.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +@author: Frank Brehm +@contact: frank.brehm@pixelpark.com +@copyright: © 2017 by Frank Brehm, Berlin +@summary: The module for the application object. +""" +from __future__ import absolute_import + +# Standard modules +import sys +import os +import logging +import re +import traceback +import textwrap +import datetime + +# Third party modules +import six + +import argparse + +# Own modules +try: + from .global_version import __version__ as __global_version__ +except (SystemError, ImportError): + from global_version import __version__ as __global_version__ + +try: + from .errors import FunctionNotImplementedError, PpAppError +except (SystemError, ImportError): + from errors import FunctionNotImplementedError, PpAppError + +try: + from .common import pp, terminal_can_colors +except (SystemError, ImportError): + from common import pp, terminal_can_colors + +try: + from .colored import ColoredFormatter, colorstr +except (SystemError, ImportError): + from colored import ColoredFormatter, colorstr + +try: + from .obj import PpBaseObjectError, PpBaseObject +except (SystemError, ImportError): + from obj import PpBaseObjectError, PpBaseObject + +__version__ = '0.1.0' +LOG = logging.getLogger(__name__) + + +# ============================================================================= +class PpApplication(PpBaseObject): + """ + Class for the application objects. + """ + + pass + +# ============================================================================= + +if __name__ == "__main__": + + pass + +# ============================================================================= + +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list diff --git a/pp_lib/errors.py b/pp_lib/errors.py index 481af30..2afec35 100644 --- a/pp_lib/errors.py +++ b/pp_lib/errors.py @@ -9,7 +9,7 @@ import errno -__version__ = '0.2.2' +__version__ = '0.3.1' # ============================================================================= class PpError(Exception): @@ -48,6 +48,42 @@ class InvalidMailAddressError(PpError): return msg +# ============================================================================= +class FunctionNotImplementedError(PpError, NotImplementedError): + """ + Error class for not implemented functions. + """ + + # ------------------------------------------------------------------------- + def __init__(self, function_name, class_name): + """ + Constructor. + + @param function_name: the name of the not implemented function + @type function_name: str + @param class_name: the name of the class of the function + @type class_name: str + + """ + + self.function_name = function_name + if not function_name: + self.function_name = '__unkown_function__' + + self.class_name = class_name + if not class_name: + self.class_name = '__unkown_class__' + + # ------------------------------------------------------------------------- + def __str__(self): + """ + Typecasting into a string for error output. + """ + + msg = "Function {func}() has to be overridden in class {cls!r}." + return msg.format(func=self.function_name, cls=self.class_name) + + # ============================================================================= if __name__ == "__main__": diff --git a/pp_lib/global_version.py b/pp_lib/global_version.py new file mode 100644 index 0000000..f7d71aa --- /dev/null +++ b/pp_lib/global_version.py @@ -0,0 +1,15 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +@author: Frank Brehm +@contact: frank.brehm@pixelpark.com +@copyright: © 2017 by Frank Brehm, Berlin +@summary: Modules global version number +""" + +__author__ = 'Frank Brehm ' +__contact__ = 'frank.brehm@pixelpark.com' +__version__ = '0.1.1' +__license__ = 'LGPL3+' + +# vim: fileencoding=utf-8 filetype=python ts=4 diff --git a/pp_lib/obj.py b/pp_lib/obj.py index ffd59dc..4e77640 100644 --- a/pp_lib/obj.py +++ b/pp_lib/obj.py @@ -144,7 +144,7 @@ class PpBaseObject(object): if v >= 0: self._verbose = v else: - log.warn(_("Wrong verbose level %r, must be >= 0"), value) + LOG.warn(_("Wrong verbose level %r, must be >= 0"), value) # ----------------------------------------------------------- @property @@ -168,10 +168,10 @@ class PpBaseObject(object): value = os.path.expanduser(value) if not os.path.exists(value): msg = _("Base directory %r does not exists.") % (value) - log.error(msg) + LOG.error(msg) elif not os.path.isdir(value): msg = _("Base directory %r is not a directory.") % (value) - log.error(msg) + LOG.error(msg) else: self._base_dir = value @@ -269,9 +269,9 @@ class PpBaseObject(object): has_handlers = True if has_handlers: - log.error(msg) + LOG.error(msg) if do_traceback: - log.error(traceback.format_exc()) + LOG.error(traceback.format_exc()) if not has_handlers: curdate = datetime.datetime.now() @@ -312,7 +312,7 @@ class PpBaseObject(object): has_handlers = True if has_handlers: - log.info(msg) + LOG.info(msg) if not has_handlers: curdate = datetime.datetime.now()