From 5ca2f8cad5bb7e42a5ddcbf004c4cd75f4fedbb9 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Fri, 28 Jun 2019 20:33:53 +0200 Subject: [PATCH] Colours! --- grmn/gcd.py | 19 ++++++++++++------- grmn/tlv.py | 9 +++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/grmn/gcd.py b/grmn/gcd.py index 15d8e2d..34d9381 100644 --- a/grmn/gcd.py +++ b/grmn/gcd.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Thanks to TurboCCC and kunix for all your work! +from .ansi import RED, GREEN, RESET from .chksum import ChkSum from .tlv import TLV, TLV6, TLV7, TLVbinary from struct import unpack @@ -35,10 +36,14 @@ class Gcd: with open(self.filename, "rb") as f: sig = f.read(8) if sig != GCD_SIG: - raise ParseException("Signature mismatch ({}, should be {})!".format(repr(sig), repr(GCD_SIG))) + raise ParseException(RED + "Signature mismatch ({}, should be {})!".format(repr(sig) + RESET, repr(GCD_SIG))) while True: cur_offset = f.tell() header = f.read(4) + if len(header) < 4: + #raise ParseException("File truncated. End marker not reached yet.") + print(RED + "WARNING: File truncated. End marker not reached yet. (pos={})".format(f.tell()) + RESET, file=sys.stderr) + break (type_id, length) = unpack("