From b428a87f1a7f70c4ae7540e07ccf9fceb247f1b0 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 13 Mar 2023 20:27:27 +0000 Subject: [PATCH] Better debug messages --- core/models/survex.py | 6 ++--- parsers/survex.py | 56 +++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/core/models/survex.py b/core/models/survex.py index 6a0a357..0e336ab 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -153,11 +153,11 @@ class SurvexBlock(models.Model): class Meta: ordering = ("id",) - def __str__(self): - return "[SurvexBlock:" + str(self.name) + "-path:" + str(self.survexpath) + "-cave:" + str(self.cave) + "]" + # def __str__(self): + # return "[SurvexBlock:" + str(self.name) + "-path:" + str(self.survexpath) + "-cave:" + str(self.cave) + "]" def __str__(self): - return self.name and str(self.name) or "no name" + return self.name and str(self.name) or "no_name-#" + str(self.id) def isSurvexBlock(self): # Function used in templates return True diff --git a/parsers/survex.py b/parsers/survex.py index 1f7859b..45384e3 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -391,18 +391,34 @@ class LoadingSurvex: if survexblock.parent.name == "troggle_unseens": # Bolluxed up if we try to inherit from this random junk, so don't. return - - if not self.currentdate: - if self.inheritdate: - message = ( - f"- INHERITING ({survexblock.parent})>({survexblock}) {survexblock.survexfile.path} '{self.inheritdate:%Y-%m-%d}'" - ) - print(self.insp + message) - stash_data_issue( - parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) - ) - survexblock.date = self.inheritdate - return self.inheritdate + + if self.currentdate: + # already set + return + + if self.inheritdate: + # Not an error, so not put in DataIssues, but is printed to debug output + message = ( + f"- No *date. INHERITING date from ({survexblock})-{survexblock.survexfile.path} to ({survexblock.parent}) to {self.inheritdate:%Y-%m-%d}" + ) + print(self.insp + message) + # stash_data_issue( + # parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + # ) + survexblock.date = self.inheritdate + self.currentdate = self.inheritdate # unecessary duplication + return self.inheritdate + else: + # This is not an error in the Expo dataset. + # Many files just holding *include lines do not have dates. + # Hardly _any_ of the ARGE survex files have dates ! + pass + # message = f" ! No survexblock.date inheritable in '{survexblock}' in '{survexblock.survexfile.path}', setting to 1976" + # print(self.insp + message) + # stash_data_issue( + # parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + # ) + # expoyear = "1976" return def fix_anonymous(self, survexblock): @@ -1300,15 +1316,10 @@ class LoadingSurvex: survexblock.survexfile.cave.slug() else: pass - if survexblock.date: - expoyear = str(survexblock.date.year) - else: - message = f" ! No survexblock.date in {survexblock} in '{survexblock.survexfile.path}', setting to 1976" - print(insp + message) - stash_data_issue( - parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) - ) - expoyear = "1976" + + self.fix_undated(survexblock) # null-op if already set + expoyear = str(survexblock.date.year) + try: qm = QM.objects.create( number=qm_no, @@ -1336,8 +1347,7 @@ class LoadingSurvex: expoyear=expoyear, cave=survexblock.survexfile.cave, ) - print(qms) - message = f" ! QM{qm_no} FAIL to create {qm_nearest} in'{survexblock.survexfile.path}'" + message = f" ! QM{qm_no} FAIL to create {qm_nearest} in'{survexblock.survexfile.path}' found {len(qms)}:{qms}" print(insp + message) stash_data_issue( parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)