From: Frank Brehm Date: Tue, 14 Mar 2017 11:47:17 +0000 (+0100) Subject: Creating FormatDuApp class and using it X-Git-Tag: 0.1.2~268 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=e61c235f98ad298b1a628181462968a24bd602b6;p=pixelpark%2Fadmin-tools.git Creating FormatDuApp class and using it --- diff --git a/format-du.py b/format-du.py index 8446382..3292d5b 100755 --- a/format-du.py +++ b/format-du.py @@ -16,9 +16,7 @@ if os.path.exists(os.path.join(cur_dir, 'pp_lib')): from pp_lib.common import pp -from pp_lib.app import PpApplication - -import pp_lib.format_du +from pp_lib.format_du import FormatDuApp log = logging.getLogger(__name__) @@ -26,7 +24,7 @@ __author__ = 'Frank Brehm ' __copyright__ = '(C) 2017 by Frank Brehm, Pixelpark GmbH, Berlin' -app = PpApplication() +app = FormatDuApp() #app.initialized = True if app.verbose > 2: diff --git a/pp_lib/format_du.py b/pp_lib/format_du.py index 7a883e7..d2a2a7c 100644 --- a/pp_lib/format_du.py +++ b/pp_lib/format_du.py @@ -10,6 +10,7 @@ from __future__ import absolute_import # Standard modules import logging +import textwrap import six @@ -18,10 +19,54 @@ from .errors import FunctionNotImplementedError, PpAppError from .app import PpApplication -__version__ = '0.1.0' +try: + from .local_version import __version__ as my_version +except ImportError: + from .global_version import __version__ as my_version + +__version__ = '0.2.1' LOG = logging.getLogger(__name__) +# ============================================================================= +class FormatDuApp(PpApplication): + """ + Application class for the format-du command + """ + + # ------------------------------------------------------------------------- + def __init__( + self, verbose=0, version=my_version, *arg, **kwargs): + + indent = ' ' * self.usage_term_len + + usage = textwrap.dedent("""\ + %(prog)s [General options] [Format options] [FILE] + + {i}%(prog)s --usage + {i}%(prog)s -h|--help + {i}%(prog)s -V|--version + """).strip().format(i=indent) + + desc = """Formats the output of 'du -k' for various modifiers.""" + + super(FormatDuApp, self).__init__( + usage=usage, + description=desc, + verbose=verbose, + version=version, + *arg, **kwargs + ) + + self.post_init() + self.initialized = True + + # ------------------------------------------------------------------------- + def _run(self): + """The underlaying startpoint of the application.""" + + LOG.info("Starting ...") + # =============================================================================