From 5f6c91612bcf83b87172968c9b79c2bf1c7307a4 Mon Sep 17 00:00:00 2001
From: Philip Sargent <philip@Muscogee.localdomain>
Date: Sun, 26 Apr 2020 23:42:43 +0100
Subject: [PATCH] link to drawings

---
 noinfo/walletscripts/wallets.py | 37 ++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/noinfo/walletscripts/wallets.py b/noinfo/walletscripts/wallets.py
index b0e58a829..94deb79d3 100644
--- a/noinfo/walletscripts/wallets.py
+++ b/noinfo/walletscripts/wallets.py
@@ -5,6 +5,7 @@ import sys, os, operator, urllib, json, re, time
 # 2018-08-27 edited Philip Sargent
 # 2019-03-02 extended to take command line argument of loser_dir and set mod time of index.html to be sane as json file
 # 2019-12-17 extra output of links to troggle-generated trip data
+# 2019-12-31 bits to make website link-checker not barf so much. .startswith() replaced by .find() for notes, elev, plan filenames
 
 loser_dir = "/home/expo/loser/"
 #loser_dir = "/mnt/d/CUCC-Expo/loser/"  # when running on Win10/bash
@@ -14,7 +15,10 @@ if len(sys.argv) > 1 :
 	if sys.argv[1] != "":
 		loser_dir = sys.argv[1]
 
-print "Loser repo is assumed to be in: " + loser_dir
+print "Loser repo (for svx files) is assumed to be in: " + loser_dir
+
+drawings_dir =  loser_dir[0:len(loser_dir)-5] + "drawings"
+print "Drawings repo (for drawings files) is assumed to be in: " + drawings_dir
 
 html_base = "<html><body>%(body)s</body></html>"
 html_year_index = html_base % {"body": "<H1>%(year)s surveys: wallets status</H1>\n<p>List of trips: <a href=\"http://expo.survex.com/expedition/%(year)s\">expedition/%(year)s</a> - troggle-processed .svx files and logbook entries on server</p>\n<H2>Persons</H2>\n<UL>\n%(persons)s</UL>\n<H2>Wallets</H2>\n<table>%(wallets)s</table>\n<H2>Needing Scanning</H2>\n<UL>\n%(needing scanning)s</ul>\n<H2>Website (Guidebook description) needing updating\n</H2>\n<UL>\n%(website needing updating)s</ul>\n"}
@@ -23,7 +27,7 @@ html_year_wallet_entry = "<tr><td><a href='%(walletindex)s'>%(walletname)s %(cav
 html_person_wallet_entry = "<li><a href='%(walletindex)s'>%(walletname)s</a> <UL>\n%(complaints)s</ul></li>\n"
 html_year_scanning_entry = "<li><a href='%(walletindex)s'>%(walletname)s %(cave)s %(name)s</a></li>\n"
 html_wallet_file_entry = "<li><a href='%(fileurl)s'>%(filename)s</a></li>\n"
-html_wallet_index = html_base % {"body": "<H1>%(title)s : %(cave)s : %(name)s</H1>\n<p>Date: %(date)s</p><p>People: %(people)s</p>\n<p>Cave <a href='%(description)s'>Guidebook description</a> - %(description_needed)s \n<p>Survex file:<br>&nbsp;&nbsp;Local (Windows): <a href='%(loser_dirw)s%(survex)s' download>%(loser_dirw)s%(survex)s</a><br>&nbsp;&nbsp;Local (Linux): <a href='%(loser_dir)s%(survex)s' download>%(loser_dir)s%(survex)s</a><br>&nbsp;&nbsp;Server: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://expo.survex.com/survexfile/%(survex)s' download>%(survex)s</a></p><a href='../index.html'>Wallet index for this year</a> </p>\n<H2>Issues</H2>\n%(complaints)s\n<H2>Files</H2>\n<UL>\n%(files)s</UL>\n"}
+html_wallet_index = html_base % {"body": "<H1>%(title)s : %(cave)s : %(name)s</H1>\n<p>Date: %(date)s</p><p>People: %(people)s</p>\n<p>Cave <a href='%(description)s'>Guidebook description</a> - %(description_needed)s \n<p>Survex file:<br>&nbsp;&nbsp;Local (Windows): <a href='file://%(loser_dirw)s/%(survex)s' download>file://%(loser_dirw)s/%(survex)s</a><br>&nbsp;&nbsp;Local (Linux): <a href='file:///%(loser_dir)s/%(survex)s' download>file:///%(loser_dir)s/%(survex)s</a><br>&nbsp;&nbsp;Server: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://expo.survex.com/survexfile/%(survex)s' download>http://expo.survex.com/survexfile/%(survex)s</a></p><a href='../index.html'>Wallet index for this year</a><br/>Local location for ::loser:: repo specified on command line is  <a href='file:///%(loser_dir)s'>%(loser_dir)s</a>. </p>\n<H2>Issues</H2>\n%(complaints)s\n<H2>Files</H2>\n<UL>\n%(files)s</UL>\n"}
 html_survex_required = {True: "Survex ", False: ""}
 html_plan_scanned = {True: "", False: "Plan "}
 html_elev_scanned = {True: "", False: "Elev "}
@@ -37,7 +41,7 @@ html_items = "<li>%s</li>"
 blank_json = {
  "cave": "", 
  "date": "", 
- "description url": "", 
+ "description url": "/1623/", 
  "description written": False, 
  "electronic survey": False, 
  "elev drawn": False, 
@@ -53,6 +57,7 @@ blank_json = {
  "survex not required": False, 
  "website updated": False}
 
+
 #need to use wallets as a dict/tuple (id,cave,name) - not sure how.
 wallets = []
 wallets_needing_scanning = set()
@@ -106,7 +111,8 @@ for item in sorted(os.listdir(".")):
             print "Writing file %s" % (contents_path) 
             json_file = open(contents_path, "w")
             json.dump(data, json_file, indent = 1)
-            json_file.close() 					
+            json_file.close() 			
+						
 	# Get modification time of contents.json
 	# print("json last modified: %s" % time.ctime(os.path.getmtime(contents_path)))
 	json_mtime = os.path.getmtime(contents_path)
@@ -131,36 +137,39 @@ for item in sorted(os.listdir(".")):
         
         #Notes
         notes_scanned = reduce(operator.or_, [f.startswith("note") for f in files], False)
+        notes_scanned = reduce(operator.or_, [f.endswith("note") for f in files], notes_scanned)
         if not notes_scanned:
-            complaints.append("The notes needs scanning (no noteN.jpg file found)") 
+            complaints.append("The notes needs scanning (no noteNN.jpg or XXnote.jpg file found)") 
             wallets_needing_scanning.add(item)
         
         #Plan drawing required
         plan_scanned = reduce(operator.or_, [f.startswith("plan") for f in files], False)
+        plan_scanned = reduce(operator.or_, [f.endswith("plan") for f in files], plan_scanned)
         plan_drawing_required = not (plan_scanned or data["plan drawn"])
         if plan_drawing_required:
-            complaints.append("The plan needs drawing (no planN.jpg file found)") 
-            person_complaints.append(" plan(s) needs drawing (no planN.jpg file found)") 
+            complaints.append("The plan needs drawing (no planNN.jpg or XXplan.jpg file found)") 
+            person_complaints.append(" plan(s) needs drawing (no planNN.jpg or XXplan.jpg file found)") 
         if not plan_drawing_required and not plan_scanned:
-            complaints.append("The plan needs  <em>scanning</em> (no planN.jpg file found)") 
+            complaints.append("The plan needs  <em>scanning</em> (no planNN.jpg or XXplan.jpg file found)") 
             wallets_needing_scanning.add(item)
 
         
         #Elev drawing required
         elev_scanned = reduce(operator.or_, [f.startswith("elev") for f in files], False)
+        elev_scanned = reduce(operator.or_, [f.endswith("elev") for f in files], elev_scanned)
         elev_drawing_required = not (elev_scanned or data["elev drawn"])
         if elev_drawing_required:
-            complaints.append("The elev needs drawing (no elevN.jpg file found)") 
-            person_complaints.append(" elev(s) needs drawing (no elevN.jpg file found)") 
+            complaints.append("The elev needs drawing (no elevNN.jpg or XXelev.jpg file found)") 
+            person_complaints.append(" elev(s) needs drawing (no elevNN.jpg or XXelev.jpg file found)") 
         if not elev_drawing_required and not elev_scanned:
-            complaints.append("The elev needs <em>scanning</em> (no elevN.jpg file found)")
+            complaints.append("The elev needs <em>scanning</em> (no elevNN.jpg or XXelev.jpg file found)")
             wallets_needing_scanning.add(item)
 
         #Description
         if not data["description written"]: 
            complaints.append("The description needs writing") 
            person_complaints.append(" description(s) needs writing")
-	description_needed = "Not present, needs doing."
+	description_needed = "A description is indicated as being needed, so may need adding into this cave page."
  	
 
         #QMS
@@ -170,12 +179,12 @@ for item in sorted(os.listdir(".")):
 
         #Website
         if not data["website updated"]:
-            complaints.append("The guidebook description on the website needs updating")
+            complaints.append("The website is marked as needing updating (using the guidebook description)")
             website_needing_updating.add(item) 
 
         #Electronic Surveys
         if not data["electronic survey"]:
-            complaints.append("Tunnel / Therion files need drawing") 
+            complaints.append("Tunnel / Therion drawing files need drawing") 
 
         if data["survex file"]:
             survex_description = data["survex file"]