Now inheriting *date from parent survexblock

This commit is contained in:
Philip Sargent 2023-03-13 19:44:39 +00:00
parent 83dc9e6c09
commit d0a05af9c6

View File

@ -297,6 +297,8 @@ class LoadingSurvex:
slengthstack = [] slengthstack = []
teaminheritstack = [] teaminheritstack = []
teamcurrentstack = [] teamcurrentstack = []
dateinheritstack = []
datecurrentstack = []
stackbegin = [] stackbegin = []
flagsstack = [] flagsstack = []
datastack = [] datastack = []
@ -331,6 +333,8 @@ class LoadingSurvex:
caverndate = None caverndate = None
currentteam = set() currentteam = set()
inheritteam = set() inheritteam = set()
currentdate = set()
inheritdate = set()
pending = [] pending = []
adhocload = False adhocload = False
@ -376,10 +380,39 @@ class LoadingSurvex:
# ) # )
return self.inheritteam return self.inheritteam
def fix_undated(self, survexblock):
"""Called when we reach *end of a block
Checks to see if the block has no *date, in which case it uses the
inherited date.
This is fine if the inherited date is from the same SurvexFile,
but inheriting dates across *include files is almost certainly NOT
expected behaviour, even though it is syntactically "correct".
"""
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
return
def fix_anonymous(self, survexblock): def fix_anonymous(self, survexblock):
"""Called when we reach *end of a block """Called when we reach *end of a block
Checks to see if the block has no team attached, in which case it uses the Checks to see if the block has no team attached, in which case it uses the
inherited team. inherited team.
This is fine if the inherited team is from the same SurvexFile,
but inheriting team across *include files is almost certainly NOT
expected behaviour, even though it is syntactically "correct".
If the block has no date, then it is assumed to be an abstract container, If the block has no date, then it is assumed to be an abstract container,
with no relevant team, and anyway we can't attach a PersonExpedition without with no relevant team, and anyway we can't attach a PersonExpedition without
knowing the year. Unless its parent has an identified expo""" knowing the year. Unless its parent has an identified expo"""
@ -642,6 +675,10 @@ class LoadingSurvex:
# raise # raise
setdate_on_survexblock(year) setdate_on_survexblock(year)
if survexblock.date:
# do not actually need a distict variable 'currentdate' but it makes the code clearer
self.currentdate = survexblock.date
def LoadSurvexLeg(self, survexblock, sline, comment, svxline): def LoadSurvexLeg(self, survexblock, sline, comment, svxline):
"""This reads compass, clino and tape data but only keeps the tape lengths, """This reads compass, clino and tape data but only keeps the tape lengths,
@ -1266,7 +1303,7 @@ class LoadingSurvex:
if survexblock.date: if survexblock.date:
expoyear = str(survexblock.date.year) expoyear = str(survexblock.date.year)
else: else:
message = f" ! No survexblock.date in'{survexblock.survexfile.path}', setting to 1976" message = f" ! No survexblock.date in {survexblock} in '{survexblock.survexfile.path}', setting to 1976"
print(insp + message) print(insp + message)
stash_data_issue( stash_data_issue(
parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)
@ -1528,6 +1565,8 @@ class LoadingSurvex:
self.slengthstack.append(self.slength) self.slengthstack.append(self.slength)
self.teaminheritstack.append(self.inheritteam) self.teaminheritstack.append(self.inheritteam)
self.teamcurrentstack.append(self.currentteam) self.teamcurrentstack.append(self.currentteam)
self.dateinheritstack.append(self.inheritdate)
self.datecurrentstack.append(self.currentdate)
pushblock() pushblock()
# PUSH state ++++++++++++++ # PUSH state ++++++++++++++
self.legsnumber = 0 self.legsnumber = 0
@ -1535,6 +1574,8 @@ class LoadingSurvex:
self.units = "metres" self.units = "metres"
self.inheritteam = self.currentteam self.inheritteam = self.currentteam
self.currentteam = set() # zero the current team when we start a new block self.currentteam = set() # zero the current team when we start a new block
self.inheritdate = self.currentdate
self.currentdate = set() # zero the current date when we start a new block
printbegin() printbegin()
newsurvexblock = SurvexBlock( newsurvexblock = SurvexBlock(
name=blkid, name=blkid,
@ -1560,6 +1601,7 @@ class LoadingSurvex:
slengthtotal += self.slength slengthtotal += self.slength
nlegstotal += self.legsnumber nlegstotal += self.legsnumber
self.fix_undated(survexblock)
self.fix_anonymous(survexblock) self.fix_anonymous(survexblock)
try: try:
survexblock.parent.save() # django insists on this although it is already saved !? survexblock.parent.save() # django insists on this although it is already saved !?
@ -1576,6 +1618,8 @@ class LoadingSurvex:
popblock() popblock()
self.inheritteam = self.teaminheritstack.pop() self.inheritteam = self.teaminheritstack.pop()
self.currentteam = self.teamcurrentstack.pop() self.currentteam = self.teamcurrentstack.pop()
self.inheritdate = self.dateinheritstack.pop()
self.currentdate = self.datecurrentstack.pop()
self.legsnumber = self.legsnumberstack.pop() self.legsnumber = self.legsnumberstack.pop()
self.units, self.unitsfactor = self.unitsstack.pop() self.units, self.unitsfactor = self.unitsstack.pop()
self.slength = self.slengthstack.pop() self.slength = self.slengthstack.pop()