diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2025-02-25 00:54:49 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2025-02-25 00:54:49 +0000 |
commit | 54717a436c4654a13989ad798801ccdab513ab5e (patch) | |
tree | 02d8d52f2965c16373982477cd1fe4907ad29f99 /parsers | |
parent | c98f386c13aa4600934871f13928fbc63794a997 (diff) | |
download | troggle-54717a436c4654a13989ad798801ccdab513ab5e.tar.gz troggle-54717a436c4654a13989ad798801ccdab513ab5e.tar.bz2 troggle-54717a436c4654a13989ad798801ccdab513ab5e.zip |
*team new code to fit updated survex
Diffstat (limited to 'parsers')
-rw-r--r-- | parsers/survex.py | 115 |
1 files changed, 75 insertions, 40 deletions
diff --git a/parsers/survex.py b/parsers/survex.py index b6aa073..cf6c23d 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -269,10 +269,19 @@ class LoadingSurvex: #rx_names = re.compile(r"(?i)names") rx_flagsnot = re.compile(r"not\s") rx_linelen = re.compile(r"[\d\-+.]+$") - instruments = "(bitch|bodger|bolt|bolter|bolting|book|clino|comp|compass|consultant|disto|distox|distox2|dog|dogsbody|drawing|drill|gps|helper|inst|instr|instrument|monkey|nagging|nail|nail_polish|nail_polish_bitch|nail_polish_monkey|nail_varnish|nail_varnish_bitch|note|paint|photo|pic|point|polish|powerdrill|rig|rigger|rigging|shoot|sketch|slacker|something|surface|tape|topodroid|unknown|useless|varnish|waiting_patiently)" - rx_teammem = re.compile(r"(?i)" + instruments + r"?(?:es|s)?\s+(.*)$") - rx_teamold = re.compile(r"(?i)(.*)\s+" + instruments + r"?(?:es|s)?$") - rx_teamabs = re.compile(r"(?i)^\s*(" + instruments + r")?(?:es|s)?\s*$") + + # this extensive list of expo roles are now (after 24/2/2025) just comments and not legal survex code. + roles = "(assistant|bitch|bodger|bolt|bolter|bolting|book|clino|comp|compass|consultant|disto|distox|distox2|" + roles += "dog|dogsbody|drawing|drill|gps|helper|inst|instr|instrument|length|monkey|nagging|nail|" + roles += "nail_polish|nail_polish_bitch|nail_polish_monkey|nail_varnish|nail_varnish_bitch|note|notebook|" + roles += "paint|photo|pic|pictures|point|polish|powerdrill|rig|rigger|rigging|shoot|sketch|slacker|" + roles += "something|station|surface|tape|topodroid|unknown|useless|varnish|waiting_patiently)" + + #rx_teammem = re.compile(r"(?i)" + roles + r"?(?:es|s)?\s+(.*)$") no longer legal survex ordering + teamfix = r"(?i)(.*?)\s+" + roles + r"?(?:es|s)?$" + rx_teamfix = re.compile(teamfix) + rx_teamabs = re.compile(r"(?i)^\s*(" + roles + r")?(?:es|s)?\s*$") + rx_teamone = re.compile(r"(?i)^\s*(.*)\s*$") rx_person = re.compile(r"(?i) and |/| / |, | , |&| & | \+ |^both$|^none$") rx_qm = re.compile( # r"(?i)^\s*QM(\d+)\s+(.+)\s+([\w\-\_]+)\.([\w\.\-]+)\s+(([\w\-]+)\.([\w\.\-]+)|\-)\s+(.+)$" @@ -579,6 +588,12 @@ class LoadingSurvex: # we will have to attach them to the survexblock anyway, and then do a # later check on whether they are valid when we get the date. + # big changes 24/2/2025 when Olly changed survex behaviour, and unilaterally eddited hundreds of + # survex files to match. So troggle has to change to match the revised, stricter syntax. + + if not tm: # i.e. null person inthe *team + return # ignore: troggle does not need to know. Survex want to though. + self.currentteam.add(tm) # used in push/pop block code expo = survexblock.expedition # may be None if no *date yet @@ -588,12 +603,12 @@ class LoadingSurvex: put_person_on_trip(survexblock, personexpedition, tm) elif known_foreigner(tm): # note, not using .lower() - message = f"- *team {expo.year} '{tm}' known foreigner on *team {survexblock.survexfile.path} ({survexblock}) in '{line}'" + message = f"- *team {expo.year} '{tm}' known foreigner on *team {survexblock.survexfile.path} ({survexblock}) in '{line=}'" print(self.insp + message) # stash_data_issue(parser='survex', message=message, url=None, sb=(survexblock.survexfile.path)) else: # we know the date and expo, but can't find the person - message = f"! *team {expo.year} '{tm}' FAIL personexpedition lookup on *team {survexblock.survexfile.path} ({survexblock}) in '{line}'" + message = f"! *team {expo.year} '{tm}' FAIL personexpedition lookup on *team {survexblock.survexfile.path} ({survexblock}) in '{line=}' {tm=}" print(self.insp + message) stash_data_issue( parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) @@ -611,41 +626,61 @@ class LoadingSurvex: # parser="survex team", message=message, url=None, sb=(survexblock.survexfile.path) # ) - mteammember = self.rx_teammem.match(line) # matches the role at the beginning - if not mteammember: - moldstyle = self.rx_teamold.match(line) # matches the role at the the end of the string - if moldstyle: - for tm in self.rx_person.split(moldstyle.group(1)): - if tm: - record_team_member(tm, survexblock) - # seems to be working - # msg = "! OLD tm='{}' line: '{}' ({}) {}".format(tm, line, survexblock, survexblock.survexfile.path) - # print(msg, file=sys.stderr) - else: - message = f"! *team {survexblock.survexfile.path} ({survexblock}) Weird '{mteammember.group(1)}' oldstyle line: '{line}'" - print(self.insp + message) - stash_data_issue( - parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) - ) - else: - nullmember = self.rx_teamabs.match(line) # matches empty role line. Ignore these. - if not nullmember: - message = f"! *team {survexblock.survexfile.path} ({survexblock}) Bad line: '{line}'" - print(self.insp + message) - stash_data_issue( - parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) - ) - else: - for tm in self.rx_person.split(mteammember.group(2)): - if tm: - record_team_member(tm, survexblock) + # teamfix = r"(?i)(.*?)\s+" + roles + r"?(?:es|s)?$" -- (.*?) means a non-greedy capture + if fixstyle := self.rx_teamfix.match(line): # matches the optional role at the the end of the string WALRUS + tmlist = fixstyle.group(1).strip('\"') # remove quotes, if present + for tm in self.rx_person.split(tmlist): + if tm.lower() =="": + # message = f"! *team {survexblock.survexfile.path} ({survexblock}) NONE PERSON '{line=}'" + # print(self.insp + message) + # stash_data_issue( + # parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + # ) + pass # does not add any information troggle is interested in else: - if mteammember.group(2).lower() not in ("none", "both"): - message = f"! Weird *team '{mteammember.group(2)}' newstyle line: '{line}' ({survexblock}) {survexblock.survexfile.path}" - print(self.insp + message) - stash_data_issue( - parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) - ) + record_team_member(tm.strip('\"'), survexblock) + # else: + # message = f"! *team {survexblock.survexfile.path} ({survexblock}) Weird '{fixstyle.group(1)}' strictstyle {line=} {tm=}" + # print(self.insp + message) + # stash_data_issue( + # parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + # ) + elif nullperson := self.rx_teamabs.match(line): # matches role but no person. Ignore these. WALRUS + return + elif line.startswith("unknown "): + message = f"! *team {survexblock.survexfile.path} ({survexblock}) role 'unknown' in wrong place '{line=}'" + print(self.insp + message) + stash_data_issue( + parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + ) + record_team_member(line.replace("unknown ","").strip('\"'), survexblock) + elif no_role_person := self.rx_teamone.match(line): + nrp = no_role_person.group(1).strip('\"') + # message = f"! *team {survexblock.survexfile.path} ({survexblock}) person {nrp=} has no role '{line=}'" + # print(self.insp + message) + # stash_data_issue( + # parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + # ) + record_team_member(nrp, survexblock) + else: + message = f"! *team {survexblock.survexfile.path} ({survexblock}) Bad '{line=}'" + print(self.insp + message) + stash_data_issue( + parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + ) + # mteammember = self.rx_teammem.match(line) # matches the role at the beginning [deprecated after 24/2/2025] + # if not mteammember: + # else: + # for tm in self.rx_person.split(mteammember.group(2)): + # if tm: + # record_team_member(tm, survexblock) + # else: + # if mteammember.group(2).lower() not in ("none", "both"): + # message = f"! Weird *team '{mteammember.group(2)}' expostyle line: '{line}' ({survexblock}) {survexblock.survexfile.path}" + # print(self.insp + message) + # stash_data_issue( + # parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) + # ) def LoadSurvexSet(self, survexblock, line): """survex *set can reset the character for space, decinmal point, field separator |