From 23619f3175273403bf818d871068e9a1b2faec43 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 9 Feb 2026 16:10:52 +0000 Subject: [PATCH] stop print msgs in utils and models --- core/models/logbooks.py | 19 ++++++++++--------- core/models/wallets.py | 30 ++++++++++++++++-------------- core/utils.py | 29 +++++++++++++++-------------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/core/models/logbooks.py b/core/models/logbooks.py index 24675208..7c049759 100644 --- a/core/models/logbooks.py +++ b/core/models/logbooks.py @@ -99,11 +99,11 @@ class LogbookEntry(TroggleModel): if self in todays: index = todays.index(self) else: - print(f"DayIndex: Synchronization error in logbook entries. Restart server or do full reset. {self}") + # print(f"DayIndex: Synchronization error in logbook entries. Restart server or do full reset. {self}") index = 0 if index not in range(0, mx): - print(f"DayIndex: More than {mx-1} LogbookEntry items on one day '{index}' {self}, restarting colour sequence.") + # print(f"DayIndex: More than {mx-1} LogbookEntry items on one day '{index}' {self}, restarting colour sequence.") index = index % mx return index @@ -139,20 +139,20 @@ def writelogbook(year, filename, generate_on_view=False): "slug" ) # now that slug, aka tripid, is in our standard date form, this will preserve ordering. - print(f" - Logbook to be exported has {len(logbook_entries)} entries in it.") + # print(f" - Logbook to be exported has {len(logbook_entries)} entries in it.") try: t = loader.get_template("logbook2005style.html") logbookfile = t.render({"logbook_entries": logbook_entries}) except: - print(" ! Very Bad Error RENDERING template ", t) + # print(" ! Very Bad Error RENDERING template ", t) raise # print(" - template rendered") try: try: endpath = Path(settings.EXPOWEB, "years", str(year), "endmatter.html") except: - print(" ! FAIL Path " + {(settings.EXPOWEB, "years", year, "endmatter.html")}) + # print(" ! FAIL Path " + {(settings.EXPOWEB, "years", year, "endmatter.html")}) raise # print(f" - endpath {endpath}") endmatter = "" @@ -162,13 +162,13 @@ def writelogbook(year, filename, generate_on_view=False): with open(endpath, "r") as end: endmatter = end.read() except: - print(" ! Very Bad Error opening " + endpath) + # print(" ! Very Bad Error opening " + endpath) raise if generate_on_view: endmatter += READ_THIS except: - print(" ! FAIL endpath " + endpath) + # print(" ! FAIL endpath " + endpath) raise # print(" - endpath opened") @@ -178,7 +178,8 @@ def writelogbook(year, filename, generate_on_view=False): with open(frontpath, "r") as front: frontmatter = front.read() except: - print(" ! Very Bad Error opening " + frontpath) + pass + # print(" ! Very Bad Error opening " + frontpath) logbookfile = re.sub(r"", "\n" + frontmatter + endmatter, logbookfile) else: logbookfile = re.sub(r"", f"\n

Expo {year}

\n" + endmatter, logbookfile) @@ -189,7 +190,7 @@ def writelogbook(year, filename, generate_on_view=False): with (open(filepath, "w")) as lb: lb.writelines(logbookfile) except: - print(" ! Very Bad Error writing to " + filepath) + # print(" ! Very Bad Error writing to " + filepath) raise # print(f'Logbook exported to {filepath}') diff --git a/core/models/wallets.py b/core/models/wallets.py index 5e1538e5..2ab7dc67 100644 --- a/core/models/wallets.py +++ b/core/models/wallets.py @@ -67,13 +67,14 @@ def make_valid_date(walletname, date): samedate = datetime.date(y, m, d) try: swapdate = datetime.date(y, d, m) - print(f"! - ERROR, not in ISO format. datestr='{datestr}'day and month are ambiguous {samedate.isoformat()} {walletname}") + # print(f"! - ERROR, not in ISO format. datestr='{datestr}'day and month are ambiguous {samedate.isoformat()} {walletname}") except ValueError: # swapping day and month does not produce a valid date - print(f"- - Warning, not in ISO format. datestr='{datestr}' but we tried to guess: {samedate.isoformat()} {walletname}") + pass + # print(f"- - Warning, not in ISO format. datestr='{datestr}' but we tried to guess: {samedate.isoformat()} {walletname}") return samedate except ValueError: - print(f"! - Fail, tried to decompose date in dd-mm-yyyy format but failed: datestr='{datestr}'") + # print(f"! - Fail, tried to decompose date in dd-mm-yyyy format but failed: datestr='{datestr}'") return None # Stop processing # --- 3. Attempt ISO-Like Format (yyyy-m-d or yyyy-mm-dd) --- @@ -90,15 +91,16 @@ def make_valid_date(walletname, date): try: samedate = datetime.date(y, m, d) - print(f"- - Warning, 1 digit only for month or day datestr='{datestr}' but we coped: {samedate.isoformat()} {walletname}") + # print(f"- - Warning, 1 digit only for month or day datestr='{datestr}' but we coped: {samedate.isoformat()} {walletname}") return samedate except ValueError: - print(f"! - Fail, tried to decompose date in yyyy-m-d format but failed: datestr='{datestr}'") + # print(f"! - Fail, tried to decompose date in yyyy-m-d format but failed: datestr='{datestr}'") return None # Stop processing # --- 4. Final Failure Check --- if datestr and datestr != "None": - print(f"! - Failed to understand date, none of our tricks worked datestr='{datestr}'") + pass + # print(f"! - Failed to understand date, none of our tricks worked datestr='{datestr}'") return None @@ -229,7 +231,7 @@ class Wallet(models.Model): y = int(wyear) except: message = f"! Exception: Error or 3 or more deep subfolder detected?:\n {fp.parent.name=}\n {fp.name=} \n {self.fpath=} {wurl=}" - print(message) + # print(message) # this is a hack, work down from /surveyscans instead. To be fixed wname = fp.parent.parent.parent.name wyear = fp.parent.parent.parent.parent.name @@ -243,11 +245,11 @@ class Wallet(models.Model): jsonfile = Path(settings.DRAWINGS_DATA, "walletjson") / wyear / wname / "contents.json" if not Path(jsonfile).is_file(): message = f"! {jsonfile} is not a file:\n {wyear=} (should be eg. '2035')\n {wname=} (should be eg. '2035#13')\n {self.fpath=}" - print(message) + # print(message) if wname not in archaic_wallets: message = f"! {jsonfile} (not archaic) is not a file:\n {wyear=} (should be eg. '2023')\n {wname=} (should be eg. '2023#13')\n {self.fpath=}" - print(message) + # print(message) from troggle.core.models.troggle import DataIssue DataIssue.objects.update_or_create(parser="wallets", message=message, url=wurl) return None @@ -257,7 +259,7 @@ class Wallet(models.Model): waldata = json.load(json_f) except: message = f"! {str(self.walletname)} Failed to load {jsonfile} JSON file" - print(message) + # print(message) from troggle.core.models.troggle import DataIssue DataIssue.objects.update_or_create(parser="wallets", message=message, url=wurl) return None @@ -314,7 +316,7 @@ class Wallet(models.Model): message = f"FAIL adding cave {caveobject} to wallet.caves '{i}'" DataIssue.objects.update_or_create(parser="wallets", message=message, url=wurl) - print(message) + # print(message) pass def year(self): @@ -502,16 +504,16 @@ class Wallet(models.Model): zipfiles = True if zipfiles: - print(f".zip file or .top file found at {self.walletname}") + # print(f".zip file or .top file found at {self.walletname}") waldata["electronic survey"] = True if topodroid: waldata["electronic survey"] = True - print(f"topodroid found at {self.walletname}") + # print(f"topodroid found at {self.walletname}") if sexytopo: waldata["electronic survey"] = True - print(f"sexytopo found at {self.walletname}") + # print(f"sexytopo found at {self.walletname}") for f in files: # This list 'files' is only used to calculate tick lists and to colour the boxes if str(f).endswith("ext-elevation.json"): diff --git a/core/utils.py b/core/utils.py index 0655790c..0d3558c9 100644 --- a/core/utils.py +++ b/core/utils.py @@ -247,7 +247,7 @@ def parse_aliases(aliasfile): filepath = Path(settings.EXPOWEB) / "cave_data" / aliasfile if not filepath.is_file(): message = f' ** {filepath} is not a file.' - print(message) + # print(message) return [(None, None)] try: with open(filepath, "r") as aliasfile: @@ -266,14 +266,14 @@ def parse_aliases(aliasfile): key, sep, target = l.partition(' ') if len(key) == 0 or len(target) == 0: message = f' ** Parsing failure for {line}' - print(message) + # print(message) continue # print(f"{key} => {target}") aliases.append((key,target)) except: message = f' ** Cannot open {filepath} for text file reading even though it is a file.' - print(message) + # print(message) return [(None, None)], "Fail on file reading" return aliases, report @@ -321,10 +321,10 @@ def shared_use_machine(request): if not (cookie_txt := request.COOKIES.get(PUBLIC_LAPTOP_COOKIE_NAME, "")): return False elif cookie_txt == PUBLIC_LAPTOP_COOKIE_TEXT: - print(f" - shared use cookie exists, and has expected value: '{cookie_txt}'") + # print(f" - shared use cookie exists, and has expected value: '{cookie_txt}'") return True else: - print(f" - shared use cookie exists, but has wrong value: '{cookie_txt}' not '{PUBLIC_LAPTOP_COOKIE_TEXT}'") + # print(f" - shared use cookie exists, but has wrong value: '{cookie_txt}' not '{PUBLIC_LAPTOP_COOKIE_TEXT}'") return True def get_cookie(request): @@ -360,7 +360,7 @@ def git_string(author_string): if editor.startswith("_"): editor = "X" + editor editor += f" <{editor}@potatohut.expo>" - print(f"++ Not git-compatible author string '{author_string}', replacing as '{editor}'") + # print(f"++ Not git-compatible author string '{author_string}', replacing as '{editor}'") return editor def git_add(filename, cwd, commands=[]): @@ -370,7 +370,7 @@ def git_add(filename, cwd, commands=[]): # what is the purpose of this 'git diff' ? Assumed to be a fossil. # it sometimes crashes with return code 129: wrong arguments. - print(f"git diff {filename} in {cwd}") + # print(f"git diff {filename} in {cwd}") cmd_diff = [git, "diff"] commands.append(cmd_diff) cp_diff = subprocess.run(cmd_diff, cwd=cwd, capture_output=True, text=True) @@ -396,20 +396,21 @@ def git_commit(cwd, message, editor, commands=[]): """Commits whatever has been Staged by git in this directory 'cwd' """ git = settings.GIT - print(f"git commit in {cwd}") + # print(f"git commit in {cwd}") if socket.gethostname() != EXPOSERVER: message += f" - on dev machine '{socket.gethostname()}'" elif settings.DEVSERVER: message += " - on a dev machine using 'runserver'" - print(f"..{message=}\n..{editor=}") + # print(f"..{message=}\n..{editor=}") cmd_commit = [git, "commit", "-m", message, "--author", f"{editor}"] commands.append(cmd_commit) - print(commands) + # print(commands) try: cp_commit = subprocess.run(cmd_commit, cwd=cwd, capture_output=True, text=True) except Exception as e: - print(e) + pass + # print(e) # This produces return code = 1 if it commits OK, but when the local repo still needs to be pushed to origin/repo # which will be the case when running a test troggle system on a development machine @@ -421,7 +422,7 @@ def git_commit(cwd, message, editor, commands=[]): "nothing to commit, working tree clean" ): msgdata = f'--Ask a nerd to fix this problem in git_commit().\n--{cp_commit.stderr}\n--"{cp_commit.stdout}"\n--return code:{str(cp_commit.returncode)}' - print(msgdata) + # print(msgdata) raise WriteAndCommitError( f"Error code with git on server in this directory: {cwd}. Edits saved, added to git, but NOT committed.\n\n" + msgdata @@ -450,11 +451,11 @@ def add_commit(fname, message, editor): except subprocess.SubprocessError: msg = f"CANNOT git ADD or COMMIT on server for this file {filename}.\nSubprocess error: {commands}\nEdits probably not saved.\nAsk a nerd to fix this." - print(msg) + # print(msg) raise WriteAndCommitError(msg) def write_binary_file(filepath, content): - print(f"write_binary_file: {filepath}") + # print(f"write_binary_file: {filepath}") write_files([(filepath, content, "")]) # null encoding does "wb" def ensure_dir_exists(filepath):