From d3e6b7e4a334a3471cc1f3309a106af9bbc69d95 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 16 Mar 2017 13:43:11 +0100 Subject: [PATCH] Adding output of total --- pp_lib/format_du.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/pp_lib/format_du.py b/pp_lib/format_du.py index b89c209..f2457dd 100644 --- a/pp_lib/format_du.py +++ b/pp_lib/format_du.py @@ -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__": -- 2.39.5