2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-01-19 17:32:31 +00:00

exploring recusrive behaviour

This commit is contained in:
Philip Sargent 2020-06-24 02:33:43 +01:00
parent 6bf762b72f
commit dc5a53376d
2 changed files with 8 additions and 5 deletions

View File

@ -203,11 +203,9 @@ class Cave(TroggleModel):
def getCaveByReference(reference): def getCaveByReference(reference):
areaname, code = reference.split("-", 1) areaname, code = reference.split("-", 1)
#print(areaname, code)
area = Area.objects.get(short_name = areaname) area = Area.objects.get(short_name = areaname)
#print(area)
foundCaves = list(Cave.objects.filter(area = area, kataster_number = code).all()) + list(Cave.objects.filter(area = area, unofficial_number = code).all()) foundCaves = list(Cave.objects.filter(area = area, kataster_number = code).all()) + list(Cave.objects.filter(area = area, unofficial_number = code).all())
print((list(foundCaves))) #print((list(foundCaves)))
if len(foundCaves) == 1: if len(foundCaves) == 1:
return foundCaves[0] return foundCaves[0]
else: else:

View File

@ -162,7 +162,7 @@ def RecursiveLoad(survexblock, survexfile, fin):
global callcount global callcount
global survexlegsnumber global survexlegsnumber
print(insp+" - MEM:{} Reading. parent:{} <> {} ".format(get_process_memory(),survexblock.survexfile.path,survexfile.path)) print(insp+" - MEM:{:.3f} Reading. parent:{} <> {} ".format(get_process_memory(),survexblock.survexfile.path,survexfile.path))
stamp = datetime.now() stamp = datetime.now()
lineno = 0 lineno = 0
@ -181,6 +181,8 @@ def RecursiveLoad(survexblock, survexfile, fin):
survexfile.cave = cave survexfile.cave = cave
svxlines = '' svxlines = ''
svxlines = fin.read().splitlines() svxlines = fin.read().splitlines()
# cannot close file now as it may be recursively called with the same file id fin if nested *begin
# occurs.
for svxline in svxlines: for svxline in svxlines:
lineno += 1 lineno += 1
# break the line at the comment # break the line at the comment
@ -341,20 +343,23 @@ def RecursiveLoad(survexblock, survexfile, fin):
survexblockdown.save() survexblockdown.save()
survexblock.save() survexblock.save()
survexblock = survexblockdown survexblock = survexblockdown
print(insp+" - ENTERING nested *begin/*end block: {}".format(name))
insp += "> " insp += "> "
RecursiveLoad(survexblockdown, survexfile, fin) RecursiveLoad(survexblockdown, survexfile, fin)
#-------------------------------------------------------- #--------------------------------------------------------
# do not close the file as there may be more blocks in this one # do not close the file as there may be more blocks in this one
# and it is re-read afresh with every nested begin-end block.
insp = insp[2:] insp = insp[2:]
else: else:
iblankbegins += 1 iblankbegins += 1
elif re.match("end$(?i)", cmd): elif re.match("end$(?i)", cmd):
if iblankbegins: if iblankbegins:
print(insp+" - RETURNING from nested *begin/*end block: {}".format(line))
iblankbegins -= 1 iblankbegins -= 1
else: else:
legsinblock = survexlegsnumber - previousnlegs legsinblock = survexlegsnumber - previousnlegs
print(insp+"LEGS: {} (previous: {}, now:{})".format(legsinblock,previousnlegs,survexlegsnumber)) print(insp+" - LEGS: {} (previous: {}, now:{})".format(legsinblock,previousnlegs,survexlegsnumber))
survexblock.legsall = legsinblock survexblock.legsall = legsinblock
survexblock.save() survexblock.save()
endstamp = datetime.now() endstamp = datetime.now()