forked from expo/troggle
Allows creation of new svxfile with unknown cave
This commit is contained in:
parent
770edd6391
commit
8b5887a87a
@ -82,6 +82,8 @@ def set_dummy_entrance(id, slug, cave, msg="DUMMY"):
|
|||||||
DataIssue.objects.create(parser="caves", message=message, url=f"{cave.url}")
|
DataIssue.objects.create(parser="caves", message=message, url=f"{cave.url}")
|
||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
|
def create_new_cave():
|
||||||
|
pass
|
||||||
|
|
||||||
def do_pending_cave(k, url, area):
|
def do_pending_cave(k, url, area):
|
||||||
"""
|
"""
|
||||||
|
@ -1474,32 +1474,6 @@ class LoadingSurvex:
|
|||||||
return cave
|
return cave
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# def LoadSurvexSetup(self, survexblock, survexfile):
|
|
||||||
# """REFACTOR to use get_cave()
|
|
||||||
|
|
||||||
# This does not seem to get run at all ?!
|
|
||||||
# """
|
|
||||||
# self.depthbegin = 0
|
|
||||||
# self.datastar = self.datastardefault
|
|
||||||
# print(
|
|
||||||
# self.insp
|
|
||||||
# + f" - MEM:{get_process_memory():.3f} Reading. parent:{survexblock.survexfile.path} <> {survexfile.path} "
|
|
||||||
# )
|
|
||||||
# self.lineno = 0
|
|
||||||
# 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="")
|
|
||||||
# # Try to find the cave in the DB if not use the string as before
|
|
||||||
# path_match = re.search(r"caves-(\d\d\d\d)/(\d+|\d\d\d\d-?\w+-\d+)/", survexblock.survexfile.path)
|
|
||||||
# if path_match:
|
|
||||||
# pos_cave = f"{path_match.group(1)}-{path_match.group(2)}"
|
|
||||||
# cave = getCaveByReference(pos_cave)
|
|
||||||
# if cave:
|
|
||||||
# survexfile.cave = cave
|
|
||||||
|
|
||||||
def LinearLoad(self, survexblock, path, collatefilename):
|
def LinearLoad(self, survexblock, path, collatefilename):
|
||||||
"""Loads a single survex file. Usually used to import all the survex files which have been collated
|
"""Loads a single survex file. Usually used to import all the survex files which have been collated
|
||||||
into a single file: either the tree or the _unseens.
|
into a single file: either the tree or the _unseens.
|
||||||
@ -2327,16 +2301,18 @@ def parse_one_file(fpath): # --------------------------------------in progress--
|
|||||||
in an earlier stange than LinearLoad(). By the time LinearLoad() is called,
|
in an earlier stange than LinearLoad(). By the time LinearLoad() is called,
|
||||||
all the *include expansion has happened.
|
all the *include expansion has happened.
|
||||||
"""
|
"""
|
||||||
def parse_new_svx(fpath, svx_load, cave, svxfileroot=None):
|
def parse_new_svx(fpath, svx_load, svxfileroot=None):
|
||||||
"""We need a dummy survex block which has the survexfile being parsed
|
"""We need a dummy survex block which has the survexfile being parsed
|
||||||
as its .survexfile field. But it is used in two ways, it is also
|
as its .survexfile field. But it is used in two ways, it is also
|
||||||
set as the parent block for the new blocks being created. This has to be fixed
|
set as the parent block for the new blocks being created. This has to be fixed
|
||||||
later.
|
later.
|
||||||
This all needs refactoring.
|
This all needs refactoring.
|
||||||
|
|
||||||
|
We also need to re-plumb the fileroot after importing, so that
|
||||||
|
the new survexfile appears in the survexdirectory lists
|
||||||
"""
|
"""
|
||||||
if svxfileroot == None:
|
if svxfileroot == None:
|
||||||
|
svxfileroot = MakeFileRoot(fpath)
|
||||||
svxfileroot = MakeFileRoot(fpath, cave)
|
|
||||||
svxfileroot.save()
|
svxfileroot.save()
|
||||||
|
|
||||||
# It is vital that the block has attached the survexfile object which is being parsed.
|
# It is vital that the block has attached the survexfile object which is being parsed.
|
||||||
@ -2362,6 +2338,8 @@ def parse_one_file(fpath): # --------------------------------------in progress--
|
|||||||
# Now we don't need or want the dummy any more
|
# Now we don't need or want the dummy any more
|
||||||
block_dummy.delete()
|
block_dummy.delete()
|
||||||
|
|
||||||
|
#svxfile.survexdirectory =
|
||||||
|
|
||||||
global svx_load
|
global svx_load
|
||||||
print(f"\n - Loading One Survex file '{fpath}'", file=sys.stderr)
|
print(f"\n - Loading One Survex file '{fpath}'", file=sys.stderr)
|
||||||
svx_load = LoadingSurvex()
|
svx_load = LoadingSurvex()
|
||||||
@ -2411,7 +2389,7 @@ def parse_one_file(fpath): # --------------------------------------in progress--
|
|||||||
# Logic is that we need an SB which links to the survexfile we are parsing for the parser
|
# Logic is that we need an SB which links to the survexfile we are parsing for the parser
|
||||||
# to work, but we delete all those before we start parsing. Urk.
|
# to work, but we delete all those before we start parsing. Urk.
|
||||||
#===========
|
#===========
|
||||||
parse_new_svx(fpath, svx_load, existingsvx, svxfileroot=existingsvx)
|
parse_new_svx(fpath, svx_load, svxfileroot=existingsvx)
|
||||||
#===========
|
#===========
|
||||||
|
|
||||||
print(f" - survexfile id={existingsvx.id} update ")
|
print(f" - survexfile id={existingsvx.id} update ")
|
||||||
@ -2429,7 +2407,7 @@ def parse_one_file(fpath): # --------------------------------------in progress--
|
|||||||
else:
|
else:
|
||||||
print(f" - Not seen this survexfile before '{fpath}' Loading. ..")
|
print(f" - Not seen this survexfile before '{fpath}' Loading. ..")
|
||||||
#===========
|
#===========
|
||||||
parse_new_svx(fpath,svx_load, IdentifyCave(fpath))
|
parse_new_svx(fpath,svx_load)
|
||||||
#===========
|
#===========
|
||||||
|
|
||||||
# print(f" - Number of SurvexDirectories: {len(svx_load.survexdict):,}")
|
# print(f" - Number of SurvexDirectories: {len(svx_load.survexdict):,}")
|
||||||
@ -2460,18 +2438,49 @@ def MakeSurvexFileRoot():
|
|||||||
return fileroot
|
return fileroot
|
||||||
|
|
||||||
|
|
||||||
def MakeFileRoot(fn, cave):
|
def MakeFileRoot(fn):
|
||||||
"""Returns a file_object.path = _unseens.svx associated with directory_object.path = SURVEX_DATA
|
"""Returns a file_object.path = _unseens.svx associated with directory_object.path = SURVEX_DATA
|
||||||
|
or tries to find the primary survex file for this cave
|
||||||
CHANGE THIS to just use the same block root as for SURVEX_TOPNAME ?
|
|
||||||
"""
|
"""
|
||||||
print(f" - Making a new root survexfile for this import: {fn}")
|
|
||||||
fileroot = SurvexFile(path=fn, cave=cave)
|
|
||||||
fileroot.survexdirectory = SurvexDirectory.objects.get(id=1) # just re-use the first thing we made
|
|
||||||
fileroot.save()
|
|
||||||
cave = IdentifyCave(fn)
|
cave = IdentifyCave(fn)
|
||||||
|
|
||||||
|
print(f" - Making/finding a new root survexfile for this import: {fn}")
|
||||||
|
|
||||||
|
#this doesn't work. Using the cave primary survex file as the fileroot
|
||||||
|
# 1. does not parse the file correctly and does not attach the blocks in it to the surfvexfile
|
||||||
|
# 2. it still doesn't appear on the http://localhost:8000/survexfile/107 list
|
||||||
|
# 3. it does make the sb appear on http://localhost:8000/survexfile/caves-1623/107/107.svx when it shouldnt.
|
||||||
|
|
||||||
|
# if cave == None:
|
||||||
|
# fileroot = SurvexFile(path=fn, cave=cave)
|
||||||
|
# fileroot.survexdirectory = SurvexDirectory.objects.get(id=1) # just re-use the first thing we made
|
||||||
|
# fileroot.save()
|
||||||
|
# fileroot.cave = cave
|
||||||
|
# print(f" - new fileroot {type(fileroot)} for {fn} with cave {cave} - {fileroot}")
|
||||||
|
# else:
|
||||||
|
# print(f" - {cave.survexdirectory_set.all()}")
|
||||||
|
# print(f" - {cave.survexdirectory_set.filter(cave=cave)}")
|
||||||
|
# for sd in cave.survexdirectory_set.filter(cave=cave):
|
||||||
|
# print(f" - {sd.cave} {sd.primarysurvexfile}")
|
||||||
|
# if f"{sd.primarysurvexfile}".replace("caves-","").startswith(f"{sd.cave}"[:4]):
|
||||||
|
# print(f" - USE THIS ONE {sd.cave} {sd.primarysurvexfile}")
|
||||||
|
# fileroot = sd.primarysurvexfile
|
||||||
|
# print(f" - old fileroot {type(fileroot)} for {fn} with cave {cave} - {fileroot}")
|
||||||
|
|
||||||
|
fileroot = SurvexFile(path=fn, cave=cave)
|
||||||
|
fileroot.survexdirectory = SurvexDirectory.objects.get(id=1) # default
|
||||||
|
|
||||||
|
if cave:
|
||||||
|
# But setting the SurvexDirectory does work !
|
||||||
|
# The fluffy stuff is because of errors in the original setting of survex directories
|
||||||
|
# which needs to be cleaned up..
|
||||||
|
for sd in cave.survexdirectory_set.filter(cave=cave):
|
||||||
|
if f"{sd.primarysurvexfile}".replace("caves-","").startswith(f"{sd.cave}"[:4]):
|
||||||
|
fileroot.survexdirectory = sd
|
||||||
|
fileroot.save()
|
||||||
fileroot.cave = cave
|
fileroot.cave = cave
|
||||||
print(f" - new fileroot {type(fileroot)} for {fn} with cave {cave}")
|
print(f" - new fileroot {type(fileroot)} for {fn} with cave {cave} - {fileroot}")
|
||||||
|
|
||||||
return fileroot
|
return fileroot
|
||||||
|
|
||||||
|
|
||||||
@ -2521,7 +2530,7 @@ def LoadSurvexBlocks():
|
|||||||
# sudo service mariadb start
|
# sudo service mariadb start
|
||||||
survexblockroot.save()
|
survexblockroot.save()
|
||||||
|
|
||||||
omitsfileroot = MakeFileRoot(UNSEENS, None)
|
omitsfileroot = MakeFileRoot(UNSEENS)
|
||||||
survexomitsroot = SurvexBlock(
|
survexomitsroot = SurvexBlock(
|
||||||
name=OMITBLOCK, survexpath="", survexfile=omitsfileroot, legsall=0, legslength=0.0
|
name=OMITBLOCK, survexpath="", survexfile=omitsfileroot, legsall=0, legslength=0.0
|
||||||
)
|
)
|
||||||
|
@ -81,9 +81,10 @@ LOGMESSAGES
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
underground survey length: {{svxlength|floatformat:2}} metres<br />
|
underground survey length: {{svxlength|floatformat:2}} metres<br />
|
||||||
parent survex file <a href="/survexfile/{{ survexfile.cave.survex_file }}">{{survexfile.cave.survex_file}}</a> for this cave {{survexfile.cave}} <br />
|
parent survex file <a href="/survexfile/{{ survexfile.cave.survex_file }}">{{survexfile.cave.survex_file}}</a> for this cave <br>
|
||||||
|
survex directory <a href="/survexfile/{{survexfile.survexdirectory.primarysurvexfile}}">{{survexfile.survexdirectory}}</a> <br />
|
||||||
{% for sb in svxblocks %}
|
{% for sb in svxblocks %}
|
||||||
block:({{sb}}) has parent block:<a href="{{sb.parent.path}}">({{sb.parent}})</a>
|
block <em>{{sb}}</em> has parent block <em>{{sb.parent}}</em><br />
|
||||||
{% empty %}
|
{% empty %}
|
||||||
Cannot find any <em>dated</em> survex blocks in this survex file (not looking at *include files). <br />
|
Cannot find any <em>dated</em> survex blocks in this survex file (not looking at *include files). <br />
|
||||||
Report this to a nerd if you think this is incorrect.
|
Report this to a nerd if you think this is incorrect.
|
||||||
|
Loading…
Reference in New Issue
Block a user