move function (correctly this time)

This commit is contained in:
Philip Sargent
2020-06-27 12:08:02 +01:00
parent ca6f7ed587
commit c55716df08
7 changed files with 75 additions and 58078 deletions

View File

@@ -311,77 +311,6 @@ class LoadSurvex():
if cave:
survexfile.cave = cave
def RecursiveScan(self, survexblock, survexfile, fin, flinear):
"""Follows the *include links in all the survex files from the root file 1623.svx
and reads only the *import and *begin and *end statements. It produces a linearised
list of the import tree
"""
indent = " " * self.depthimport
sys.stderr.flush();
self.callcount +=1
if self.callcount % 10 ==0 :
print(".", file=sys.stderr,end='')
if self.callcount % 500 ==0 :
print("\n", file=sys.stderr,end='')
self.svxfileslist.append(survexfile)
svxlines = fin.read().splitlines()
for svxline in svxlines:
self.lineno += 1
sline, comment = self.rx_comment.match(svxline.strip()).groups()
mstar = self.rx_star.match(sline)
if mstar: # yes we are reading a *cmd
cmd, args = mstar.groups()
cmd = cmd.lower()
if re.match("include$(?i)", cmd):
includepath = os.path.normpath(os.path.join(os.path.split(survexfile.path)[0], re.sub(r"\.svx$", "", args)))
path_match = re.search(r"caves-(\d\d\d\d)/(\d+|\d\d\d\d-?\w+-\d+)/", includepath)
includesurvexfile = models_survex.SurvexFile(path=includepath)
if includesurvexfile.exists():
#--------------------------------------------------------
self.depthimport += 1
fininclude = includesurvexfile.OpenFile()
flinear.write("{:2} {} *import {}\n".format(self.depthimport, indent, includesurvexfile.path))
push = includesurvexfile.path.lower()
self.stackimport.append(push)
self.RecursiveScan(survexblock, includesurvexfile, fininclude, flinear)
pop = self.stackimport.pop()
if pop != push:
print("!!!!!!! ERROR pop != push {} != {} {}".format(pop, push, self.stackimport))
print("!!!!!!! ERROR pop != push {} != {} {}\n".format(pop, push, self.stackimport),file=flinear)
print("!!!!!!! ERROR pop != push {} != {} {}".format(pop, push, self.stackimport),file=sys.stderr)
flinear.write("{:2} {} *tropmi {}\n".format(self.depthimport, indent, includesurvexfile.path))
fininclude.close()
self.depthimport -= 1
#--------------------------------------------------------
else:
print(" ! ERROR *include file not found for {}".format(includesurvexfile))
elif re.match("begin$(?i)", cmd):
self.depthbegin += 1
depth = " " * self.depthbegin
if args:
pushargs = args
else:
pushargs = " "
self.stackbegin.append(pushargs.lower())
flinear.write(" {:2} {} *begin {}\n".format(self.depthbegin, depth, args))
pass
elif re.match("end$(?i)", cmd):
depth = " " * self.depthbegin
flinear.write(" {:2} {} *end {}\n".format(self.depthbegin, depth, args))
if not args:
args = " "
popargs = self.stackbegin.pop()
if popargs != args.lower():
print("!!!!!!! ERROR BEGIN/END pop != push {} != {}\n{}".format(popargs, args, self. stackbegin))
print("!!!!!!! ERROR BEGIN/END pop != push {} != {}\n{}\n".format(popargs, args, self. stackbegin), file=flinear)
print(" !!!!!!! ERROR BEGIN/END pop != push {} != {}\n{}".format(popargs, args,self. stackbegin), file=sys.stderr,)
self.depthbegin -= 1
pass
def RecursiveLoad(self, survexblock, survexfile, fin):
@@ -522,8 +451,80 @@ class LoadSurvex():
else:
pass # ignore all other sorts of data
def RecursiveScan(self, survexblock, survexfile, fin, flinear):
"""Follows the *include links in all the survex files from the root file 1623.svx
and reads only the *import and *begin and *end statements. It produces a linearised
list of the import tree
"""
indent = " " * self.depthimport
sys.stderr.flush();
self.callcount +=1
if self.callcount % 10 ==0 :
print(".", file=sys.stderr,end='')
if self.callcount % 500 ==0 :
print("\n", file=sys.stderr,end='')
def FindAndLoadAllSurvex(survexblockroot, survexfileroot):
self.svxfileslist.append(survexfile)
svxlines = fin.read().splitlines()
for svxline in svxlines:
self.lineno += 1
sline, comment = self.rx_comment.match(svxline.strip()).groups()
mstar = self.rx_star.match(sline)
if mstar: # yes we are reading a *cmd
cmd, args = mstar.groups()
cmd = cmd.lower()
if re.match("include$(?i)", cmd):
includepath = os.path.normpath(os.path.join(os.path.split(survexfile.path)[0], re.sub(r"\.svx$", "", args)))
path_match = re.search(r"caves-(\d\d\d\d)/(\d+|\d\d\d\d-?\w+-\d+)/", includepath)
includesurvexfile = models_survex.SurvexFile(path=includepath)
if includesurvexfile.exists():
#--------------------------------------------------------
self.depthimport += 1
fininclude = includesurvexfile.OpenFile()
flinear.write("{:2} {} *import {}\n".format(self.depthimport, indent, includesurvexfile.path))
push = includesurvexfile.path.lower()
self.stackimport.append(push)
self.RecursiveScan(survexblock, includesurvexfile, fininclude, flinear)
pop = self.stackimport.pop()
if pop != push:
print("!!!!!!! ERROR pop != push {} != {} {}".format(pop, push, self.stackimport))
print("!!!!!!! ERROR pop != push {} != {} {}\n".format(pop, push, self.stackimport),file=flinear)
print("!!!!!!! ERROR pop != push {} != {} {}".format(pop, push, self.stackimport),file=sys.stderr)
flinear.write("{:2} {} *tropmi {}\n".format(self.depthimport, indent, includesurvexfile.path))
fininclude.close()
self.depthimport -= 1
#--------------------------------------------------------
else:
print(" ! ERROR *include file not found for {}".format(includesurvexfile))
elif re.match("begin$(?i)", cmd):
self.depthbegin += 1
depth = " " * self.depthbegin
if args:
pushargs = args
else:
pushargs = " "
self.stackbegin.append(pushargs.lower())
flinear.write(" {:2} {} *begin {}\n".format(self.depthbegin, depth, args))
pass
elif re.match("end$(?i)", cmd):
depth = " " * self.depthbegin
flinear.write(" {:2} {} *end {}\n".format(self.depthbegin, depth, args))
if not args:
args = " "
popargs = self.stackbegin.pop()
if popargs != args.lower():
print("!!!!!!! ERROR BEGIN/END pop != push {} != {}\n{}".format(popargs, args, self. stackbegin))
print("!!!!!!! ERROR BEGIN/END pop != push {} != {}\n{}\n".format(popargs, args, self. stackbegin), file=flinear)
print(" !!!!!!! ERROR BEGIN/END pop != push {} != {}\n{}".format(popargs, args,self. stackbegin), file=sys.stderr,)
self.depthbegin -= 1
pass
def FindAndLoadAllSurvex(survexblockroot):
"""Follows the *include links recursively to find files
"""
print(' - redirecting stdout to svxblks.log...')
@@ -532,6 +533,7 @@ def FindAndLoadAllSurvex(survexblockroot, survexfileroot):
sys.stdout = open('svxblks.log', 'w')
print(' - SCANNING All Survex Blocks...',file=sys.stderr)
survexfileroot = survexblockroot.survexfile
svxl0 = LoadSurvex()
svxl0.callcount = 0
@@ -599,7 +601,7 @@ def LoadAllSurvexBlocks():
print(' - Loading All Survex Blocks...')
memstart = models.get_process_memory()
survexlegsnumber, survexlegsalllength = FindAndLoadAllSurvex(survexblockroot, survexfileroot)
survexlegsnumber, survexlegsalllength = FindAndLoadAllSurvex(survexblockroot)
memend = models.get_process_memory()
print(" - MEMORY start:{:.3f} MB end:{:.3f} MB increase={:.3f} MB".format(memstart,memend, memend-memstart))