forked from expo/troggle
refactored LinearLoad(), output unchanged
This commit is contained in:
parent
fd6f0b0a35
commit
abbe8d467b
@ -583,14 +583,18 @@ class LoadingSurvex():
|
|||||||
self.currentsurvexfile.save() # django insists on this although it is already saved !?
|
self.currentsurvexfile.save() # django insists on this although it is already saved !?
|
||||||
|
|
||||||
self.datastar = copy.deepcopy(self.datastardefault)
|
self.datastar = copy.deepcopy(self.datastardefault)
|
||||||
#self.datastack.append(self.datastar) # and extra push will do it ?
|
|
||||||
|
|
||||||
self.flagsstar = copy.deepcopy(self.flagsdefault)
|
self.flagsstar = copy.deepcopy(self.flagsdefault)
|
||||||
#self.flagsstack.append(self.flagsstar)
|
blkid = None
|
||||||
|
pathlist = None
|
||||||
|
args = None
|
||||||
|
previousnlegs = None
|
||||||
|
oldflags = None
|
||||||
blockcount = 0
|
blockcount = 0
|
||||||
self.lineno = 0
|
self.lineno = 0
|
||||||
|
|
||||||
def tickle():
|
def tickle():
|
||||||
nonlocal blockcount
|
nonlocal blockcount
|
||||||
|
|
||||||
blockcount +=1
|
blockcount +=1
|
||||||
if blockcount % 10 ==0 :
|
if blockcount % 10 ==0 :
|
||||||
print(".", file=sys.stderr,end='')
|
print(".", file=sys.stderr,end='')
|
||||||
@ -600,48 +604,91 @@ class LoadingSurvex():
|
|||||||
print(" ", file=sys.stderr,end='')
|
print(" ", file=sys.stderr,end='')
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
for svxline in svxlines:
|
def printbegin():
|
||||||
self.lineno += 1
|
nonlocal blkid
|
||||||
sline, comment = self.rx_comment.match(svxline).groups()
|
nonlocal pathlist
|
||||||
if comment:
|
|
||||||
# this catches the ;*include NEWFILE and ;*edulcni ENDOFFILE lines too
|
|
||||||
self.LoadSurvexComment(survexblock, comment)
|
|
||||||
|
|
||||||
if not sline:
|
|
||||||
continue # skip blank lines
|
|
||||||
|
|
||||||
# detect a star command
|
|
||||||
mstar = self.rx_star.match(sline)
|
|
||||||
if mstar: # yes we are reading a *cmd
|
|
||||||
cmd, args = mstar.groups()
|
|
||||||
cmd = cmd.lower()
|
|
||||||
|
|
||||||
# ------------------------BEGIN
|
|
||||||
if re.match("begin$(?i)", cmd):
|
|
||||||
depth = " " * self.depthbegin
|
depth = " " * self.depthbegin
|
||||||
blkid = args.lower()
|
|
||||||
self.stackbegin.append(blkid)
|
|
||||||
# PUSH state ++++++++++++++
|
|
||||||
print(" # datastack at 1 *begin {} 'type':".format(blkid), end="")
|
|
||||||
for dict in self.datastack:
|
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
|
||||||
print("")
|
|
||||||
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
|
||||||
self.flagsstack.append(copy.deepcopy(self.flagsstar))
|
|
||||||
self.datastack.append(copy.deepcopy(self.datastar))
|
|
||||||
print(" # datastack at 2 *begin {} 'type':".format(blkid), end="")
|
|
||||||
for dict in self.datastack:
|
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
|
||||||
print("")
|
|
||||||
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
|
||||||
# PUSH state ++++++++++++++
|
|
||||||
|
|
||||||
previousnlegs = self.survexlegsnumber
|
|
||||||
print("{:2}{} - Begin for :'{}'".format(self.depthbegin,depth, blkid))
|
print("{:2}{} - Begin for :'{}'".format(self.depthbegin,depth, blkid))
|
||||||
pathlist = ""
|
pathlist = ""
|
||||||
for id in self.stackbegin:
|
for id in self.stackbegin:
|
||||||
if len(id) > 0:
|
if len(id) > 0:
|
||||||
pathlist += "." + id
|
pathlist += "." + id
|
||||||
|
|
||||||
|
def printend():
|
||||||
|
nonlocal args
|
||||||
|
nonlocal previousnlegs
|
||||||
|
|
||||||
|
depth = " " * self.depthbegin
|
||||||
|
print("{:2}{} - End from:'{}'".format(self.depthbegin,depth,args))
|
||||||
|
legsinblock = self.survexlegsnumber - previousnlegs
|
||||||
|
print("{:2}{} - LEGS: {} (previous: {}, now:{})".format(self.depthbegin,
|
||||||
|
depth, legsinblock, previousnlegs, self.survexlegsnumber))
|
||||||
|
survexblock.legsall = legsinblock
|
||||||
|
|
||||||
|
def pushblock():
|
||||||
|
nonlocal blkid
|
||||||
|
|
||||||
|
print(" # datastack at 1 *begin {} 'type':".format(blkid), end="")
|
||||||
|
for dict in self.datastack:
|
||||||
|
print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
|
print("")
|
||||||
|
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
||||||
|
# ------------ * DATA
|
||||||
|
self.datastack.append(copy.deepcopy(self.datastar))
|
||||||
|
# ------------ * DATA
|
||||||
|
print(" # datastack at 2 *begin {} 'type':".format(blkid), end="")
|
||||||
|
for dict in self.datastack:
|
||||||
|
print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
|
print("")
|
||||||
|
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
||||||
|
# ------------ * FLAGS
|
||||||
|
self.flagsstack.append(copy.deepcopy(self.flagsstar))
|
||||||
|
# ------------ * FLAGS
|
||||||
|
|
||||||
|
def popblock():
|
||||||
|
nonlocal blkid
|
||||||
|
nonlocal oldflags
|
||||||
|
|
||||||
|
print(" # datastack at *end '{} 'type':".format(blkid), end="")
|
||||||
|
for dict in self.datastack:
|
||||||
|
print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
|
print("")
|
||||||
|
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
||||||
|
# ------------ * DATA
|
||||||
|
self.datastar = copy.deepcopy(self.datastack.pop())
|
||||||
|
# ------------ * DATA
|
||||||
|
print(" # datastack after *end '{} 'type':".format(blkid), end="")
|
||||||
|
for dict in self.datastack:
|
||||||
|
print("'{}' ".format(dict["type"].upper()), end="")
|
||||||
|
print("")
|
||||||
|
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
||||||
|
# ------------ * FLAGS
|
||||||
|
self.flagsstar = copy.deepcopy(self.flagsstack.pop())
|
||||||
|
# ------------ * FLAGS
|
||||||
|
if oldflags["any"] != self.flagsstar["any"]:
|
||||||
|
print(" # POP 'any' flag now:'{}' was:{} ".format(self.flagsstar["any"], oldflags["any"]))
|
||||||
|
|
||||||
|
def starstatement(mstar):
|
||||||
|
nonlocal survexblock
|
||||||
|
nonlocal blkid
|
||||||
|
nonlocal pathlist
|
||||||
|
nonlocal args
|
||||||
|
nonlocal previousnlegs
|
||||||
|
nonlocal oldflags
|
||||||
|
|
||||||
|
cmd, args = mstar.groups()
|
||||||
|
cmd = cmd.lower()
|
||||||
|
|
||||||
|
# ------------------------BEGIN
|
||||||
|
if re.match("begin$(?i)", cmd):
|
||||||
|
blkid = args.lower()
|
||||||
|
# PUSH state ++++++++++++++
|
||||||
|
self.stackbegin.append(blkid)
|
||||||
|
pushblock()
|
||||||
|
# PUSH state ++++++++++++++
|
||||||
|
previousnlegs = self.survexlegsnumber
|
||||||
|
printbegin()
|
||||||
newsurvexblock = models_survex.SurvexBlock(name=blkid, parent=survexblock,
|
newsurvexblock = models_survex.SurvexBlock(name=blkid, parent=survexblock,
|
||||||
survexpath=pathlist,
|
survexpath=pathlist,
|
||||||
cave=self.currentcave, survexfile=self.currentsurvexfile,
|
cave=self.currentcave, survexfile=self.currentsurvexfile,
|
||||||
@ -654,13 +701,7 @@ class LoadingSurvex():
|
|||||||
|
|
||||||
# ---------------------------END
|
# ---------------------------END
|
||||||
elif re.match("end$(?i)", cmd):
|
elif re.match("end$(?i)", cmd):
|
||||||
depth = " " * self.depthbegin
|
printend()
|
||||||
|
|
||||||
print("{:2}{} - End from:'{}'".format(self.depthbegin,depth,args))
|
|
||||||
legsinblock = self.survexlegsnumber - previousnlegs
|
|
||||||
print("{:2}{} - LEGS: {} (previous: {}, now:{})".format(self.depthbegin,
|
|
||||||
depth,legsinblock,previousnlegs,self.survexlegsnumber))
|
|
||||||
survexblock.legsall = legsinblock
|
|
||||||
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 !?
|
||||||
except:
|
except:
|
||||||
@ -671,25 +712,12 @@ class LoadingSurvex():
|
|||||||
except:
|
except:
|
||||||
print(survexblock, file=sys.stderr)
|
print(survexblock, file=sys.stderr)
|
||||||
raise
|
raise
|
||||||
print(" # datastack at *end '{} 'type':".format(blkid), end="")
|
|
||||||
for dict in self.datastack:
|
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
|
||||||
print("")
|
|
||||||
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
|
||||||
# POP state ++++++++++++++
|
# POP state ++++++++++++++
|
||||||
self.datastar = copy.deepcopy(self.datastack.pop())
|
popblock()
|
||||||
print(" # datastack after *end '{} 'type':".format(blkid), end="")
|
blkid = self.stackbegin.pop()
|
||||||
for dict in self.datastack:
|
|
||||||
print("'{}' ".format(dict["type"].upper()), end="")
|
|
||||||
print("")
|
|
||||||
print("'{}' self.datastar ".format(self.datastar["type"].upper()))
|
|
||||||
self.flagsstar = copy.deepcopy(self.flagsstack.pop())
|
|
||||||
if oldflags["any"] != self.flagsstar["any"]:
|
|
||||||
print(" # POP 'any' flag now:'{}' was:{} ".format(self.flagsstar["any"], oldflags["any"]))
|
|
||||||
# POP state ++++++++++++++
|
# POP state ++++++++++++++
|
||||||
self.currentsurvexblock = survexblock.parent
|
self.currentsurvexblock = survexblock.parent
|
||||||
survexblock = survexblock.parent
|
survexblock = survexblock.parent
|
||||||
blkid = self.stackbegin.pop()
|
|
||||||
oldflags = self.flagsstar
|
oldflags = self.flagsstar
|
||||||
self.depthbegin -= 1
|
self.depthbegin -= 1
|
||||||
|
|
||||||
@ -719,6 +747,22 @@ class LoadingSurvex():
|
|||||||
models.DataIssue.objects.create(parser='survex', message=message)
|
models.DataIssue.objects.create(parser='survex', message=message)
|
||||||
else:
|
else:
|
||||||
self.LoadSurvexIgnore(survexblock, args, cmd)
|
self.LoadSurvexIgnore(survexblock, args, cmd)
|
||||||
|
|
||||||
|
|
||||||
|
for svxline in svxlines:
|
||||||
|
self.lineno += 1
|
||||||
|
sline, comment = self.rx_comment.match(svxline).groups()
|
||||||
|
if comment:
|
||||||
|
# this catches the ;*include NEWFILE and ;*edulcni ENDOFFILE lines too
|
||||||
|
self.LoadSurvexComment(survexblock, comment)
|
||||||
|
|
||||||
|
if not sline:
|
||||||
|
continue # skip blank lines
|
||||||
|
|
||||||
|
# detect a star command
|
||||||
|
mstar = self.rx_star.match(sline)
|
||||||
|
if mstar: # yes we are reading a *cmd
|
||||||
|
starstatement(mstar)
|
||||||
else: # not a *cmd so we are reading data OR rx_comment failed
|
else: # not a *cmd so we are reading data OR rx_comment failed
|
||||||
self.LoadSurvexLineLeg(survexblock, sline, comment)
|
self.LoadSurvexLineLeg(survexblock, sline, comment)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user