import textwrap
import sys
+# Third party modules
import six
# Own modules
except ImportError:
from .global_version import __version__ as my_version
-__version__ = '0.2.1'
+__version__ = '0.3.1'
LOG = logging.getLogger(__name__)
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))
# =============================================================================