]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Start evaluating output of du
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 15 Mar 2017 13:13:09 +0000 (14:13 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 15 Mar 2017 13:13:09 +0000 (14:13 +0100)
pp_lib/format_du.py
pp_lib/global_version.py

index 804310e4afe625e6ab8366df737d3fd686b93725..6bec32feaae1b81677f382429b22ba6c2c90d00b 100644 (file)
@@ -13,6 +13,7 @@ import logging
 import textwrap
 import sys
 
+# Third party modules
 import six
 
 # Own modules
@@ -25,7 +26,7 @@ try:
 except ImportError:
     from .global_version import __version__ as my_version
 
-__version__ = '0.2.1'
+__version__ = '0.3.1'
 LOG = logging.getLogger(__name__)
 
 
@@ -144,13 +145,58 @@ class FormatDuApp(PpApplication):
                 self.exit(1)
             self.precision = self.args.precision
 
-
     # -------------------------------------------------------------------------
     def _run(self):
         """The underlaying startpoint of the application."""
 
-        LOG.info("Starting ...")
+        fh = None
+        opened = False
+        open_args = {}
+        if six.PY3:
+            open_args['encoding'] = 'utf-8'
+            open_args['errors'] = 'surrogateescape'
+        filename = None
+
+        try:
+            if self.args.file and self.args.file != '-':
+                fh = open(self.args.file, 'r', **open_args)
+                opened = True
+                filename = '{!r}'.format(self.args.file)
+            else:
+                fh = sys.stdin
+                filename = '<standard input>'
+
+            LOG.debug("Reading DU info from {}.".format(filename))
+            self.read_file(fh)
+
+        finally:
+            if opened:
+                fh.close()
+
+    # -------------------------------------------------------------------------
+    def read_file(self, fh):
+
+        line = None
+        eof = False
+
+        while not eof:
+            line = fh.readline()
+            if not line:
+                eof = True
+                break
+            line = line.strip()
+            if not line:
+                continue
+            self.eval_line(line)
+
+        if self.verbose > 1:
+            LOG.debug("Finished reading.")
+
+    # -------------------------------------------------------------------------
+    def eval_line(self, line):
 
+        if self.verbose > 2:
+            LOG.debug("Evaluating line {!r} ...".format(line))
 
 # =============================================================================
 
index f7d71aa5f6665e28cfba507173a76abaed64dd67..6acf14e2cc2c240c1189ac8128198922028b5b1c 100644 (file)
@@ -9,7 +9,7 @@
 
 __author__ = 'Frank Brehm <frank.brehm@pixelpark.com>'
 __contact__ = 'frank.brehm@pixelpark.com'
-__version__ = '0.1.1'
+__version__ = '0.2.1'
 __license__ = 'LGPL3+'
 
 # vim: fileencoding=utf-8 filetype=python ts=4