diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2020-06-27 12:08:02 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2020-06-27 12:08:02 +0100 |
commit | c55716df085c3a66c5eb919f1ea6f74f5cd2c650 (patch) | |
tree | 1dee1187ab8b1372bae4a4b269054380d5abc4f7 /parsers/survex.py | |
parent | ca6f7ed587f5d4b4f20573db46ec0d154b0d2666 (diff) | |
download | troggle-c55716df085c3a66c5eb919f1ea6f74f5cd2c650.tar.gz troggle-c55716df085c3a66c5eb919f1ea6f74f5cd2c650.tar.bz2 troggle-c55716df085c3a66c5eb919f1ea6f74f5cd2c650.zip |
move function (correctly this time)
Diffstat (limited to 'parsers/survex.py')
-rw-r--r-- | parsers/survex.py | 148 |
1 files changed, 75 insertions, 73 deletions
diff --git a/parsers/survex.py b/parsers/survex.py index 0c4fd25..9e4a275 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -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='') + + 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, survexfileroot): +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)) |