]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Creating FormatDuApp class and using it
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 14 Mar 2017 11:47:17 +0000 (12:47 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 14 Mar 2017 11:47:17 +0000 (12:47 +0100)
format-du.py
pp_lib/format_du.py

index 8446382e086119373356ed02ffefdb1c81098117..3292d5b1eea2dbce9d6d21d10f7986a5ba5646b5 100755 (executable)
@@ -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 <frank.brehm@pixelpark.com>'
 __copyright__ = '(C) 2017 by Frank Brehm, Pixelpark GmbH, Berlin'
 
 
-app = PpApplication()
+app = FormatDuApp()
 #app.initialized = True
 
 if app.verbose > 2:
index 7a883e72e3a20550dc6c550a4cb9372e4bb04062..d2a2a7c19f56d01c9f9de0677d0ae6c0b8da57a0 100644 (file)
@@ -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 ...")
+
 
 # =============================================================================