From 2d856f7cd3da07a9bfffdf6232d0bf3cbf74e3c2 Mon Sep 17 00:00:00 2001
From: Philip Sargent
Date: Sun, 26 Apr 2020 23:41:29 +0100
Subject: [PATCH] takes a parameter which is path for loser
---
noinfo/walletscripts/wallets.py | 116 +++++++++++++++++++++-----------
1 file changed, 75 insertions(+), 41 deletions(-)
diff --git a/noinfo/walletscripts/wallets.py b/noinfo/walletscripts/wallets.py
index b5d335e1e..b0e58a829 100644
--- a/noinfo/walletscripts/wallets.py
+++ b/noinfo/walletscripts/wallets.py
@@ -1,42 +1,57 @@
#!/usr/bin/env python
-import os, operator, urllib, json, re
+import sys, os, operator, urllib, json, re, time
+# 2017 originally by Martin Green
+# 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
loser_dir = "/home/expo/loser/"
+#loser_dir = "/mnt/d/CUCC-Expo/loser/" # when running on Win10/bash
+#loser_dir = "/media/philip/SD-huge/CUCC-Expo/loser/" # when running on xubuntu laptop 'barbie'
+
+if len(sys.argv) > 1 :
+ if sys.argv[1] != "":
+ loser_dir = sys.argv[1]
+
+print "Loser repo is assumed to be in: " + loser_dir
+
html_base = "%(body)s"
-html_year_index = html_base % {"body": "%(year)s surveys
Persons
Wallets
Needing Scanning
Website needing updating
%(website needing updating)s
"}
-html_year_person = "%(person)s"
-html_year_wallet_entry = "%(walletname)s %(cave)s %(name)s | %(complaints)s |
"
-html_person_wallet_entry = "%(walletname)s "
-html_year_scanning_entry = "%(walletname)s %(cave)s %(name)s"
-html_wallet_file_entry = "%(filename)s"
-html_wallet_index = html_base % {"body": "%(title)s %(cave)s %(name)s
Date %(date)s
People %(people)s
Description
Survex file: %(survex)s
Issues
%(complaints)sFiles
"}
+html_year_index = html_base % {"body": "%(year)s surveys: wallets status
\nList of trips: expedition/%(year)s - troggle-processed .svx files and logbook entries on server
\nPersons
\n\nWallets
\n\nNeeding Scanning
\n\nWebsite (Guidebook description) needing updating\n
\n\n%(website needing updating)s
\n"}
+html_year_person = "%(person)s\n"
+html_year_wallet_entry = "%(walletname)s %(cave)s %(name)s | %(complaints)s |
\n"
+html_person_wallet_entry = "%(walletname)s \n"
+html_year_scanning_entry = "%(walletname)s %(cave)s %(name)s\n"
+html_wallet_file_entry = "%(filename)s\n"
+html_wallet_index = html_base % {"body": "%(title)s : %(cave)s : %(name)s
\nDate: %(date)s
People: %(people)s
\nCave Guidebook description - %(description_needed)s \n
Survex file:
Local (Windows): %(loser_dirw)s%(survex)s
Local (Linux): %(loser_dir)s%(survex)s
Server: %(survex)s
Wallet index for this year
\nIssues
\n%(complaints)s\nFiles
\n\n"}
html_survex_required = {True: "Survex ", False: ""}
html_plan_scanned = {True: "", False: "Plan "}
html_elev_scanned = {True: "", False: "Elev "}
html_description_written = {True: "", False: "Desc "}
html_qms_written = {True: "", False: "QMs "}
html_status = {True: "Issues: ", False: ""}
-html_person = html_base % {"body": "%(person)s
Outstanding Wallets
"}
+html_person = html_base % {"body": "%(person)s
Outstanding Wallets
"}
html_complaint_items = "%(count)i %(complaint)s"
html_items = "%s"
-blank_json = {"survex file": "",
- "survex not required": False,
- "plan not required": False,
- "elev not required": False,
- "plan drawn": False,
- "elev drawn": False,
- "description written": False,
- "qms written": False,
- "website updated": False,
- "electronic survey": False,
- "elev not required": False,
- "date": "",
- "people": ["Unknown"],
- "description url": "",
- "cave": "",
- "name": ""}
+blank_json = {
+ "cave": "",
+ "date": "",
+ "description url": "",
+ "description written": False,
+ "electronic survey": False,
+ "elev drawn": False,
+ "elev not required": False,
+ "name": "",
+ "people": [
+ "Unknown"
+ ],
+ "plan drawn": False,
+ "plan not required": False,
+ "qms written": False,
+ "survex file": "",
+ "survex not required": False,
+ "website updated": False}
#need to use wallets as a dict/tuple (id,cave,name) - not sure how.
wallets = []
@@ -47,21 +62,29 @@ people = {}
#use dir this file is in to get current year
path,year = os.path.split(os.path.dirname(os.path.realpath(__file__)))
-for item in os.listdir("."):
+print "Year: " + year
+
+for item in sorted(os.listdir(".")):
if os.path.isdir(item):
files = []
for f in os.listdir(os.path.join(".", item)):
if f not in ["contents.json", "contents.json~","index.html"] and os.path.isfile(os.path.join(".", item, f)):
files.append(f)
contents_path = os.path.join(".", item, "contents.json")
- print "Reading file %s" % (contents_path)
+# print "Trying to read file %s" % (contents_path)
if not os.path.isfile(contents_path):
+ print "Creating file %s from template" % (contents_path)
json_file = open(contents_path, "w")
- json.dump(blank_json, json_file, indent = 1)
+ json.dump(blank_json, json_file, sort_keys=True, indent = 1)
json_file.close()
+ # print "Reading file %s" % (contents_path)
json_file = open(contents_path)
#print json_file
data = json.load(json_file)
+ if not data["people"]:
+ data["people"]=["NOBODY"]
+
+
json_file.close()
write_required = False
try:
@@ -80,14 +103,16 @@ for item in os.listdir("."):
write_required = True
#print write_required
if write_required:
+ 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)
#make wallet descriptions
-
#Survex
survex_required = (data["survex not required"] and data["survex file"] == "") or \
not (not data["survex not required"] and os.path.isfile(os.path.join(loser_dir, data["survex file"])))
@@ -97,7 +122,7 @@ for item in os.listdir("."):
if not data["survex not required"] and data["survex file"] == "":
survex_complaint = "A survex file is required, but has not been specified!"
if not data["survex not required"] and not os.path.isfile(os.path.join(loser_dir, data["survex file"])):
- survex_complaint = "The specified survex file (%s) does not exist here!" % data["survex file"]
+ survex_complaint = "The specified survex file (%s) does not exist here!" % os.path.join(loser_dir, data["survex file"])
complaints = []
person_complaints = []
if survex_required:
@@ -117,7 +142,7 @@ for item in os.listdir("."):
complaints.append("The plan needs drawing (no planN.jpg file found)")
person_complaints.append(" plan(s) needs drawing (no planN.jpg file found)")
if not plan_drawing_required and not plan_scanned:
- complaints.append("The plan needs scanning (no planN.jpg file found)")
+ complaints.append("The plan needs scanning (no planN.jpg file found)")
wallets_needing_scanning.add(item)
@@ -128,13 +153,15 @@ for item in os.listdir("."):
complaints.append("The elev needs drawing (no elevN.jpg file found)")
person_complaints.append(" elev(s) needs drawing (no elevN.jpg file found)")
if not elev_drawing_required and not elev_scanned:
- complaints.append("The elev needs scanning (no elevN.jpg file found)")
+ complaints.append("The elev needs scanning (no elevN.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")
+ if not data["description written"]:
+ complaints.append("The description needs writing")
+ person_complaints.append(" description(s) needs writing")
+ description_needed = "Not present, needs doing."
+
#QMS
if not data["qms written"]:
@@ -143,7 +170,7 @@ for item in os.listdir("."):
#Website
if not data["website updated"]:
- complaints.append("The website needs updating")
+ complaints.append("The guidebook description on the website needs updating")
website_needing_updating.add(item)
#Electronic Surveys
@@ -160,8 +187,11 @@ for item in os.listdir("."):
"cave": data["cave"],
"name": data["name"],
"date": data["date"],
- "people": reduce(operator.add, [" %s" % person for person in data["people"]], ""),
- "description": data["description url"],
+ "people": reduce(operator.add, [" %s," % person for person in data["people"]], ""),
+ "description": "http://expo.survex.com"+data["description url"],
+ "description_needed": description_needed,
+ "loser_dir": loser_dir,
+ "loser_dirw": loser_dir[5].upper() + ':/' + loser_dir[7:],
"survex": survex_description,
"complaints": reduce(operator.add, ["" + complaint + "
" for complaint in complaints], ""),
"files": reduce(operator.add,
@@ -172,7 +202,11 @@ for item in os.listdir("."):
"")})
wallet_index_file.close()
wallets.append((item, data["cave"], data["name"], survex_required, plan_scanned, elev_scanned, data["description written"], data["qms written"]))
-
+ # Set modification time to be the same as that of contents.json
+ index_file = item+"/index.html"
+ os.utime(index_file, ( json_mtime,json_mtime))
+
+
#People
for person in data["people"]: