deleting ad hoc copy, keep version history in subfolder

This commit is contained in:
Philip Sargent
2020-04-26 23:47:04 +01:00
parent 5f6c91612b
commit f5046f99f9
2 changed files with 42 additions and 332 deletions

View File

@@ -1,47 +1,57 @@
#!/usr/bin/env python
import sys, os, operator, urllib, json, re, time
from datetime import datetime
# 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-03-02 extended to take command line argument of loser_dir and set mod time of index.html to be same 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
# 2019-12-31 bits to make website link-checker not barf so much. Added endswith() to .startswith() for notes, elev, plan filenames
# 2020-01-21 Now we are using Windows10-WSL1, +links to expedition logbook on every generated page
# 2020-03-15 Adding timestamp to visible outputs, changing name of produced files to walletindex.html so that contents can be browsed
# 2020-03-15 Added "ignore" to the <year>#00 folder containing scraps - then removed as we do
# want it to appear in the reports under "UNKNOWN"
loser_dir = "/home/expo/loser/"
#loser_dir = "/mnt/d/CUCC-Expo/loser/" # when running on Win10/bash
loser_dir = "/home/expo/loser"
#loser_dir = "/mnt/d/CUCC-Expo/Loser/" # when running on Win10-WSL1
#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 (for svx files) is assumed to be in: " + loser_dir
dateTimeObj=datetime.now(tz=None)
timestamp = dateTimeObj.strftime("%d-%b-%Y (%H:%M)")
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
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"}
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>\nAs of %(timestamp)s\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 style=\"column-count: 3; \">\n%(website needing updating)s</ul>\n"}
html_year_person = "<li><a href='%(person)s.html'>%(person)s</a><UL>\n%(complaints)s</ul></li>\n"
html_year_wallet_entry = "<tr><td><a href='%(walletindex)s'>%(walletname)s %(cave)s %(name)s</a></td> <td>%(complaints)s</td></tr>\n"
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='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_wallet_index = html_base % {"body": "<H1>%(title)s : %(cave)s : %(name)s</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<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;<br>&nbsp;&nbsp;Local: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='file:///%(loser_dir)s/%(survex)s' download>file:///%(loser_dir)s/%(survex)s</a><br>&nbsp;Server: &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='../walletindex.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 "}
html_description_written = {True: "", False: "Desc "}
html_qms_written = {True: "", False: "QMs "}
html_status = {True: "Issues: ", False: ""}
html_person = html_base % {"body": "<H1>%(person)s</H1><H2>Outstanding Wallets</H2><UL>\n%(wallets)s</UL>"}
html_person = html_base % {"body": "<H1>%(person)s</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>Outstanding Wallets</H2>\nAs of %(timestamp)s\n<UL>\n%(wallets)s</UL>"}
html_complaint_items = "<li>%(count)i %(complaint)s</li>"
html_items = "<li>%s</li>"
blank_json = {
"cave": "",
"date": "",
"description url": "/1623/",
"description url": "/caves",
"description written": False,
"electronic survey": False,
"elev drawn": False,
@@ -70,26 +80,28 @@ path,year = os.path.split(os.path.dirname(os.path.realpath(__file__)))
print "Year: " + year
for item in sorted(os.listdir(".")):
if os.path.isdir(item):
if os.path.isdir(item) and item != year+"indexpages":
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)):
if f not in ["contents.json", "contents.json~","walletindex.html"] and os.path.isfile(os.path.join(".", item, f)):
files.append(f)
contents_path = os.path.join(".", item, "contents.json")
# print "Trying to read 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, sort_keys=True, indent = 1)
json_file.close()
# print "Reading file %s" % (contents_path)
#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"]
try:
data = json.load(json_file)
except:
print "FAILURE parsing JSON file %s" % (contents_path)
# Python bug: https://github.com/ShinNoNoir/twitterwebsearch/issues/12
raise
if not data["people"]:
data["people"]=["NOBODY"]
json_file.close()
write_required = False
try:
@@ -191,8 +203,8 @@ for item in sorted(os.listdir(".")):
else:
survex_description = "Not specified"
wallet_index_file = open(os.path.join(item, "index.html"), "w")
wallet_index_file.write(html_wallet_index % {"title": item,
wallet_index_file = open(os.path.join(item, "walletindex.html"), "w")
wallet_index_file.write(html_wallet_index % {"title": item, "year": year,
"cave": data["cave"],
"name": data["name"],
"date": data["date"],
@@ -212,7 +224,7 @@ for item in sorted(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"
index_file = item+"/walletindex.html"
os.utime(index_file, ( json_mtime,json_mtime))
@@ -245,8 +257,8 @@ for person, person_wallets in people.items():
person_summary = dict(person_summary)
year_index_file = open("index.html", "w")
year_index_file.write(html_year_index % {"year": year, "persons": reduce(operator.add, [html_year_person % {"person": person,
year_index_file = open("walletindex.html", "w")
year_index_file.write(html_year_index % {"year": year, "timestamp": timestamp, "persons": reduce(operator.add, [html_year_person % {"person": person,
"complaints": reduce(operator.add,
[html_complaint_items % {"complaint": complaint,
"count": count}
@@ -258,20 +270,20 @@ year_index_file.write(html_year_index % {"year": year, "persons": reduce(operato
"needing scanning": reduce(operator.add, [html_year_scanning_entry % {"walletname": wallet,
"cave": cave,
"name": name,
"walletindex": urllib.quote(wallet) + "/index.html"}
"walletindex": urllib.quote(wallet) + "/walletindex.html"}
for (wallet)
in wallets_needing_scanning], ""),
"website needing updating": reduce(operator.add, [html_year_scanning_entry % {"walletname": wallet,
"cave": cave,
"name": name,
"walletindex": urllib.quote(wallet) + "/index.html"}
"walletindex": urllib.quote(wallet) + "/walletindex.html"}
for (wallet)
in website_needing_updating], ""),
"wallets": reduce(operator.add,
[html_year_wallet_entry % {"walletname": wallet,
"cave": cave,
"name": name,
"walletindex": urllib.quote(wallet) + "/index.html",
"walletindex": urllib.quote(wallet) + "/walletindex.html",
"complaints": html_status[survex_required or not plan_scanned or not elev_scanned or description_written] + html_survex_required[survex_required] + html_plan_scanned[plan_scanned] + html_elev_scanned[elev_scanned] + html_description_written[description_written] + html_qms_written[qms_written] }
for (wallet, cave, name, survex_required, plan_scanned, elev_scanned, description_written, qms_written)
in wallets])})
@@ -279,9 +291,9 @@ year_index_file.close()
for person, item_complaint_list in people.items():
person_file = open(person + ".html", "w")
person_file.write(html_person % {"person": person,
person_file.write(html_person % {"person": person, "year": year, "timestamp": timestamp,
"wallets": reduce(operator.add, [html_person_wallet_entry % {"walletname": wallet,
"walletindex": urllib.quote(wallet) + "/index.html",
"walletindex": urllib.quote(wallet) + "/walletindex.html",
"complaints": reduce(operator.add,
[html_items % complaint
for complaint