]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding output of total
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 16 Mar 2017 12:43:11 +0000 (13:43 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 16 Mar 2017 12:43:11 +0000 (13:43 +0100)
pp_lib/format_du.py

index b89c2093d596821acf291a69bd669ac43c0279af..f2457ddce29df89a4dd6f97becf20276c376879e 100644 (file)
@@ -34,7 +34,7 @@ try:
 except ImportError:
     from .global_version import __version__ as my_version
 
-__version__ = '0.4.2'
+__version__ = '0.4.3'
 LOG = logging.getLogger(__name__)
 
 
@@ -186,6 +186,10 @@ class FormatDuApp(PpApplication):
         eof = False
         lnr = 0
 
+        total = 0
+        if six.PY2:
+            total = long(0)
+
         while not eof:
             lnr += 1
             line = fh.readline()
@@ -195,7 +199,17 @@ class FormatDuApp(PpApplication):
             line = line.strip()
             if not line:
                 continue
-            self.eval_line(line, lnr)
+            entry = self.eval_line(line, lnr)
+            if entry:
+                total += entry.size_kb
+
+        if self.total:
+            total_entry = DuEntry(
+                size_kb=total, path='total', appname=self.appname,
+                verbose=self.verbose, base_dir=self.base_dir)
+            if self.verbose > 1:
+                LOG.debug("Total entry:\n{}".format(pp(total_entry.as_dict())))
+            print(total_entry.to_str(unit=self.unit, precision=self.precision))
 
         if self.verbose > 1:
             LOG.debug("Finished reading.")
@@ -212,11 +226,14 @@ class FormatDuApp(PpApplication):
         except DuParseError as e:
             LOG.error("Could not parse line {lnr}: {e}".format(lnr=lnr, e=e))
             LOG.debug("Parsing pattern: {!r}".format(DuEntry.parse_pattern))
-            return
+            return None
 
-        LOG.debug("Entry:\n{}".format(pp(entry.as_dict())))
+        if self.verbose > 1:
+            LOG.debug("Entry:\n{}".format(pp(entry.as_dict())))
         print(entry.to_str(unit=self.unit, precision=self.precision))
 
+        return entry
+
 # =============================================================================
 
 if __name__ == "__main__":