diff --git a/parsers/caves.py b/parsers/caves.py index 361d950..e09debe 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -400,7 +400,7 @@ def readcave(filename): caves_xslug[slug] = cs except Exception as ex: # This fails to do an update! It just crashes.. to be fixed - message = " ! Cave update/create failure : %s, skipping file cave_data/%s with exception\nException: %s" % (slug, context, ex.__class__) + message = f" ! Cave update/create failure : {slug}, skipping file cave_data/{context} with exception\nException: {ex.__class__}" DataIssue.objects.create(parser='caves', message=message) print(message) diff --git a/parsers/drawings.py b/parsers/drawings.py index 1ef03a9..132b663 100644 --- a/parsers/drawings.py +++ b/parsers/drawings.py @@ -37,7 +37,7 @@ def find_dwg_file(dwgfile, path): if len(scanswalletl): wallet = scanswalletl[0] if len(scanswalletl) > 1: - message = "! More than one scan FOLDER matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.dwgpath, path) + message = f"! More than one scan FOLDER matches filter query. [{scansfilel[0]}]: {mscansdir.group(1)} {mscansdir.group(2)} {dwgfile.dwgpath} {path}" print(message) DataIssue.objects.create(parser='Tunnel', message=message) @@ -48,7 +48,7 @@ def find_dwg_file(dwgfile, path): plist =[] for sf in scansfilel: plist.append(sf.ffile) - message = "! More than one image FILENAME matches filter query. [{}]: {} {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.dwgpath, path, plist) + message = f"! More than one image FILENAME matches filter query. [{scansfilel[0]}]: {mscansdir.group(1)} {mscansdir.group(2)} {dwgfile.dwgpath} {path} {plist}" print(message) DataIssue.objects.create(parser='Tunnel', message=message) scansfile = scansfilel[0] @@ -100,7 +100,7 @@ def findwalletimage(therionfile, foundpath): plist =[] for sf in scansfilel: plist.append(sf.ffile) - message = "! More than one image FILENAME matches filter query. [{}]: {} {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.dwgpath, path, plist) + message = f"! More than one image FILENAME matches filter query. [{scansfilel[0]}]: {mscansdir.group(1)} {mscansdir.group(2)} {dwgfile.dwgpath} {path} {plist}" print(message) DataIssue.objects.create(parser='Therion', message=message) scansfile = scansfilel[0] @@ -129,7 +129,7 @@ def settherionfileinfo(filetuple): ff = os.path.join(settings.DRAWINGS_DATA, therionfile.dwgpath) therionfile.filesize = os.stat(ff)[stat.ST_SIZE] if therionfile.filesize <= 0: - message = "! Zero length therion file {}".format(ff) + message = f"! Zero length therion file {ff}" print(message) DataIssue.objects.create(parser='Therion', message=message, url=f'/dwgdataraw/{therionfile.dwgpath}') return @@ -185,7 +185,7 @@ def settnlfileinfo(dwgfile): ff = os.path.join(settings.DRAWINGS_DATA, dwgfile.dwgpath) dwgfile.filesize = os.stat(ff)[stat.ST_SIZE] if dwgfile.filesize <= 0: - message = "! Zero length tunnel file {}".format(ff) + message = f"! Zero length tunnel file {ff}" print(message) DataIssue.objects.create(parser='Tunnel', message=message, url=f'/dwgdataraw/{dwgfile.dwgpath}') return @@ -217,7 +217,7 @@ def setdrwfileinfo(dwgfile): ff = Path(settings.DRAWINGS_DATA) / dwgfile.dwgpath dwgfile.filesize = ff.stat().st_size if dwgfile.filesize <= 0: - message = "! Zero length drawing file {}".format(ff) + message = f"! Zero length drawing file {ff}" print(message) DataIssue.objects.create(parser='drawings', message=message, url=f'/dwgdataraw/{dwgfile.dwgpath}') return diff --git a/parsers/people.py b/parsers/people.py index 83d656c..4f85c1b 100644 --- a/parsers/people.py +++ b/parsers/people.py @@ -77,7 +77,7 @@ def load_people_expos(): for year in years: lookupAttribs = {'year':year} - nonLookupAttribs = {'name':"CUCC expo %s" % year} + nonLookupAttribs = {'name':f"CUCC expo {year}"} save_carefully(Expedition, lookupAttribs, nonLookupAttribs) diff --git a/parsers/survex.py b/parsers/survex.py index 3754035..bfa2ad7 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -72,24 +72,24 @@ class MapLocations(object): try: k = ent.caveandentrance_set.all()[0].cave except: - message = " ! Failed to get Cave linked to Entrance:{} from:{} best:{}".format(ent.name, ent.filename, ent.best_station()) + message = f" ! Failed to get Cave linked to Entrance:{ent.name} from:{ent.filename} best:{ent.best_station()}" DataIssue.objects.create(parser='entrances', message=message) print(message) raise try: areaName = k.getArea().short_name except: - message = " ! Failed to get Area on cave '{}' linked to Entrance:{} from:{} best:{}".format(k, ent.name, ent.filename, ent.best_station()) + message = f" ! Failed to get Area on cave '{k}' linked to Entrance:{ent.name} from:{ent.filename} best:{ent.best_station()}" DataIssue.objects.create(parser='entrances', message=message) print(message) raise - self.p.append((ent.best_station(), "%s-%s" % (areaName, str(ent)[5:]), ent.needs_surface_work(), str(ent))) + self.p.append((ent.best_station(), f"{areaName}-{str(ent)[5:]}", ent.needs_surface_work(), str(ent))) message = f" - {len(self.p)} entrances linked to caves." print(message) return self.p def __str__(self): - return "{} map locations".format(len(self.p)) + return f"{len(self.p)} map locations" def get_offending_filename(path): """Used to provide the URL for a line in the DataErrors page @@ -216,11 +216,11 @@ class LoadingSurvex(): pass # we ignore all these, which is fine. else: if cmd in ["include", "data", "flags", "title", "entrance","set", "units", "alias", "ref"]: - message = "! Warning. Unparsed [*{}]: '{}' {} - not an error (probably)".format(cmd, line, survexblock.survexfile.path) + message = f"! Warning. Unparsed [*{cmd}]: '{line}' {survexblock.survexfile.path} - not an error (probably)" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) else: - message = "! Bad unrecognised svx command: [*{}] {} ({}) {}".format(cmd, line, survexblock, survexblock.survexfile.path) + message = f"! Bad unrecognised svx command: [*{cmd}] {line} ({survexblock}) {survexblock.survexfile.path}" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) @@ -250,7 +250,7 @@ class LoadingSurvex(): if expo: if not survexblock.expeditionday: # *date has been set # should not happen - message = "! *team {} expo ok, expedition day not in *team {} ({}) ".format(expo.year, survexblock.survexfile.path, survexblock ) + message = f"! *team {expo.year} expo ok, expedition day not in *team {survexblock.survexfile.path} ({survexblock}) " print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) @@ -262,12 +262,12 @@ class LoadingSurvex(): self.currentpersonexped.append(personexpedition) # used in push/pop block code personrole.save() elif known_foreigner(tm): # note, not using .lower() - message = "- *team {} '{}' known foreigner on *team {} ({}) in '{}'".format(expo.year, tm, survexblock.survexfile.path, survexblock, line) + message = f"- *team {expo.year} '{tm}' known foreigner on *team {survexblock.survexfile.path} ({survexblock}) in '{line}'" print(self.insp+message) # DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) else: # we know the date and expo, but can't find the person - message = "! *team {} '{}' FAIL personexpedition lookup on *team {} ({}) in '{}'".format(expo.year, tm, survexblock.survexfile.path, survexblock, line) + message = f"! *team {expo.year} '{tm}' FAIL personexpedition lookup on *team {survexblock.survexfile.path} ({survexblock}) in '{line}'" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) else: @@ -290,13 +290,13 @@ class LoadingSurvex(): # msg = "! OLD tm='{}' line: '{}' ({}) {}".format(tm, line, survexblock, survexblock.survexfile.path) # print(msg, file=sys.stderr) else: - message = "! *team {} ({}) Weird '{}' oldstyle line: '{}'".format(survexblock.survexfile.path, survexblock, mteammember.group(1), line) + message = f"! *team {survexblock.survexfile.path} ({survexblock}) Weird '{mteammember.group(1)}' oldstyle line: '{line}'" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) else: nullmember = self.rx_teamabs.match(line) # matches empty role line. Ignore these. if not nullmember: - message = "! *team {} ({}) Bad line: '{}'".format(survexblock.survexfile.path, survexblock, line) + message = f"! *team {survexblock.survexfile.path} ({survexblock}) Bad line: '{line}'" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) else: @@ -305,7 +305,7 @@ class LoadingSurvex(): record_team_member(tm, survexblock) else: if not mteammember.group(2).lower() in ('none', 'both'): - message = "! Weird *team '{}' newstyle line: '{}' ({}) {}".format(mteammember.group(2), line, survexblock, survexblock.survexfile.path) + message = f"! Weird *team '{mteammember.group(2)}' newstyle line: '{line}' ({survexblock}) {survexblock.survexfile.path}" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) @@ -319,7 +319,7 @@ class LoadingSurvex(): if splayalias: self.flagsstar["splayalias"] = True else: - message = "! Bad *ALIAS: '{}' ({}) {}".format(line, survexblock, survexblock.survexfile.path) + message = f"! Bad *ALIAS: '{line}' ({survexblock}) {survexblock.survexfile.path}" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message) @@ -334,7 +334,7 @@ class LoadingSurvex(): factor = convert.groups()[1] self.unitsfactor = float(factor) if debugprint: - message = "! *UNITS NUMERICAL conversion [{}x] '{}' ({}) {}".format(factor, line, survexblock, survexblock.survexfile.path) + message = f"! *UNITS NUMERICAL conversion [{factor}x] '{line}' ({survexblock}) {survexblock.survexfile.path}" print(self.insp+message) DataIssue.objects.create(parser='survexunits', message=message) @@ -345,7 +345,7 @@ class LoadingSurvex(): elif metres: self.units = "metres" else: - message = "! *UNITS in YARDS!? - not converted '{}' ({}) {}".format(line, survexblock, survexblock.survexfile.path) + message = f"! *UNITS in YARDS!? - not converted '{line}' ({survexblock}) {survexblock.survexfile.path}" print(self.insp+message) DataIssue.objects.create(parser='survexunits', message=message) @@ -392,11 +392,11 @@ class LoadingSurvex(): pr.save() self.currentpersonexped.append(pe) # used in push/pop block code elif known_foreigner(pr.personname): # note, not using .lower() - message = "- *team {} '{}' known foreigner on *date {} ({}) in '{}'".format(expo.year, pr.personname, survexblock.survexfile.path, survexblock, line) + message = f"- *team {expo.year} '{pr.personname}' known foreigner on *date {survexblock.survexfile.path} ({survexblock}) in '{line}'" print(self.insp+message) # DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) else: - message = "! *team {} '{}' FAIL personexpedition lookup on *date {} ({}) '{}'".format(year, pr.personname, survexblock.survexfile.path, survexblock, pr.personname) + message = f"! *team {year} '{pr.personname}' FAIL personexpedition lookup on *date {survexblock.survexfile.path} ({survexblock}) '{pr.personname}'" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) @@ -431,7 +431,7 @@ class LoadingSurvex(): setdate_on_survexblock(year) else: # these errors are reporting the wrong survexblock, which is actually a SurvexFile (!) - message = "! DATE Error unrecognised '{}-{}' ({}) {}".format(oline, survexblock, type(survexblock), survexblock.survexfile.path) + message = f"! DATE Error unrecognised '{oline}-{survexblock}' ({type(survexblock)}) {survexblock.survexfile.path}" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) print(f" {type(survexblock)=}") # survexblock.parent fails as a SurvexFile has no .parent ...ugh. @@ -457,7 +457,7 @@ class LoadingSurvex(): return if debugprint: - print("! LEG datastar type:{}++{}\n{} ".format(self.datastar["type"].upper(), survexblock.survexfile.path, sline)) + print(f"! LEG datastar type:{self.datastar['type'].upper()}++{survexblock.survexfile.path}\n{sline} ") if self.datastar["type"] == "passage": return if self.datastar["type"] == "cartesian": @@ -469,7 +469,7 @@ class LoadingSurvex(): if self.datastar["type"] == "cylpolar": return if debugprint: - print(" !! LEG data lineno:{}\n !! sline:'{}'\n !! datastar['tape']: {}".format(self.lineno, sline, self.datastar["tape"])) + print(f" !! LEG data lineno:{self.lineno}\n !! sline:'{sline}'\n !! datastar['tape']: {self.datastar['tape']}") if self.datastar["type"] != "normal": return @@ -508,7 +508,7 @@ class LoadingSurvex(): print("Aliased splay in ", survexblock.survexfile.path) return except: - message = ' ! datastar parsing from/to incorrect in line %s in %s' % (ls, survexblock.survexfile.path) + message = f' ! datastar parsing from/to incorrect in line {ls} in {survexblock.survexfile.path}' print(self.insp+message) DataIssue.objects.create(parser='survexleg', message=message, url=get_offending_filename(survexblock.survexfile.path)) return @@ -516,7 +516,7 @@ class LoadingSurvex(): try: tape = ls[datastar["tape"]] except: - message = ' ! datastar parsing incorrect in line %s in %s' % (ls, survexblock.survexfile.path) + message = f' ! datastar parsing incorrect in line {ls} in {survexblock.survexfile.path}' print(self.insp+message) DataIssue.objects.create(parser='survexleg', message=message, url=get_offending_filename(survexblock.survexfile.path)) survexleg.tape = invalid_tape @@ -529,19 +529,19 @@ class LoadingSurvex(): if self.unitsfactor: tape = float(tape) * self.unitsfactor if debugprint: - message = " ! Units: Length scaled {}m '{}' in ({}) units:{} factor:{}x".format(tape, ls, survexblock.survexfile.path, self.units, self.unitsfactor) + message = f" ! Units: Length scaled {tape}m '{ls}' in ({survexblock.survexfile.path}) units:{self.units} factor:{self.unitsfactor}x" print(self.insp+message) DataIssue.objects.create(parser='survexleg', message=message, url=get_offending_filename(survexblock.survexfile.path)) if self.units =="feet": tape = float(tape) / METRESINFEET if debugprint: - message = " ! Units: converted to {:.3f}m from {} '{}' in ({})".format(tape, self.units, ls, survexblock.survexfile.path) + message = f" ! Units: converted to {tape:.3f}m from {self.units} '{ls}' in ({survexblock.survexfile.path})" print(self.insp+message) DataIssue.objects.create(parser='survexleg', message=message, url=get_offending_filename(survexblock.survexfile.path)) survexleg.tape = float(tape) self.legsnumber += 1 except ValueError: - message = " ! Value Error: Tape misread in line'{}' in {} units:{}".format(ls, survexblock.survexfile.path, self.units) + message = f" ! Value Error: Tape misread in line'{ls}' in {survexblock.survexfile.path} units:{self.units}" print(self.insp+message) DataIssue.objects.create(parser='survexleg', message=message, url=get_offending_filename(survexblock.survexfile.path)) survexleg.tape = invalid_tape @@ -549,14 +549,14 @@ class LoadingSurvex(): survexblock.legslength += survexleg.tape self.slength += survexleg.tape except ValueError: - message = " ! Value Error: Tape length not added '{}' in {} units:{}".format(ls, survexblock.survexfile.path, self.units) + message = f" ! Value Error: Tape length not added '{ls}' in {survexblock.survexfile.path} units:{self.units}" print(self.insp+message) DataIssue.objects.create(parser='survexleg', message=message, url=get_offending_filename(survexblock.survexfile.path)) try: lcompass = ls[datastar["compass"]] except: - message = ' ! Value Error: Compass not found in line %s in %s' % (ls, survexblock.survexfile.path) + message = f' ! Value Error: Compass not found in line {ls} in {survexblock.survexfile.path}' print(self.insp+message) DataIssue.objects.create(parser='survexleg', message=message, url=get_offending_filename(survexblock.survexfile.path)) lcompass = invalid_compass @@ -608,7 +608,7 @@ class LoadingSurvex(): return if len(args)< 4: - message = " ! Empty or BAD *REF statement '{}' in '{}'".format(args, survexblock.survexfile.path) + message = f" ! Empty or BAD *REF statement '{args}' in '{survexblock.survexfile.path}'" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=url) return @@ -634,21 +634,21 @@ class LoadingSurvex(): print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=url) - refscan = "%s#%s%s" % (yr, letterx, wallet) + refscan = f"{yr}#{letterx}{wallet}" try: if int(wallet)>99: - message = " ! Wallet *REF {} - very big (more than 99) so probably wrong in '{}'".format(refscan, survexblock.survexfile.path) + message = f" ! Wallet *REF {refscan} - very big (more than 99) so probably wrong in '{survexblock.survexfile.path}'" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=url) except: - message = " ! Wallet *REF {} - not numeric in '{}'".format(refscan, survexblock.survexfile.path) + message = f" ! Wallet *REF {refscan} - not numeric in '{survexblock.survexfile.path}'" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=url) manywallets = Wallet.objects.filter(walletname=refscan) # assumes all wallets found in earlier pass of data import if manywallets: if len(manywallets) > 1: - message = " ! Wallet *REF {} - more than one found {} wallets in db with same id {}".format(refscan, len(manywallets), survexblock.survexfile.path) + message = f" ! Wallet *REF {refscan} - more than one found {len(manywallets)} wallets in db with same id {survexblock.survexfile.path}" print(self.insp+message) DataIssue.objects.create(parser='survex', message=message, url=url) @@ -738,7 +738,7 @@ class LoadingSurvex(): cave = survexblock.survexfile.cave) qm.save except: - message = " ! QM{} FAIL to create {} in'{}'".format(qm_no, qm_nearest,survexblock.survexfile.path) + message = f" ! QM{qm_no} FAIL to create {qm_nearest} in'{survexblock.survexfile.path}'" print(insp+message) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) @@ -766,7 +766,7 @@ class LoadingSurvex(): self.datastar = copy.deepcopy(self.datastardefault) elif ls[0] == "normal" or ls[0] == "topofil": if not ("from" in datastar and "to" in datastar): - message = " ! - Unrecognised *data normal statement '{}' {}|{}".format(args, survexblock.name, survexblock.survexpath) + message = f" ! - Unrecognised *data normal statement '{args}' {survexblock.name}|{survexblock.survexpath}" print(message) print(message,file=sys.stderr) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) @@ -803,7 +803,7 @@ class LoadingSurvex(): #DataIssue.objects.create(parser='survex', message=message) self.datastar["type"] = ls[0] else: - message = " ! - Unrecognised *data statement '{}' {}|{}".format(args, survexblock.name, survexblock.survexpath) + message = f" ! - Unrecognised *data statement '{args}' {survexblock.name}|{survexblock.survexpath}" print(message) print(message,file=sys.stderr) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(survexblock.survexfile.path)) @@ -820,7 +820,7 @@ class LoadingSurvex(): for s in argslist: flags.append(s) if debugprint: - print(" ^ flagslist:{}".format(flags),) + print(f" ^ flagslist:{flags}",) if "duplicate" in flags: self.flagsstar["duplicate"] = True @@ -841,7 +841,7 @@ class LoadingSurvex(): if self.flagsstar["surface"] == True or self.flagsstar["splay"] == True: self.flagsstar["skiplegs"] = True if debugprint: - print(" $ flagslist:{}".format(flags),) + print(f" $ flagslist:{flags}",) def IdentifyCave(self, cavepath): @@ -850,13 +850,13 @@ class LoadingSurvex(): # TO DO - this predates the big revision to Gcavelookup so look at this again carefully path_match = self.rx_cave.search(cavepath) if path_match: - sluggy = '{}-{}'.format(path_match.group(1), path_match.group(2)) + sluggy = f'{path_match.group(1)}-{path_match.group(2)}' guesses = [sluggy.lower(), path_match.group(2).lower()] for g in guesses: if g in self.caveslist: self.caveslist[cavepath] = self.caveslist[g] return self.caveslist[g] - print(' ! Failed to find cave for {}'.format(cavepath.lower())) + print(f' ! Failed to find cave for {cavepath.lower()}') else: # not a cave, but that is fine. # print(' ! No regex(standard identifier) cave match for %s' % cavepath.lower()) @@ -931,9 +931,9 @@ class LoadingSurvex(): The survexblock passed-in is not necessarily the parent. FIX THIS. """ if debugprint: - print(" # datastack in LoadSurvexFile:{} 'type':".format(svxid), end="") + print(f" # datastack in LoadSurvexFile:{svxid} 'type':", end="") for dict in self.datastack: - print("'{}' ".format(dict["type"].upper()), end="") + print(f"'{dict['type'].upper()}' ", end="") print("") @@ -951,7 +951,7 @@ class LoadingSurvex(): cave = self.IdentifyCave(headpath) # cave already exists in db if not newdirectory: - message = " ! 'None' SurvexDirectory returned from GetSurvexDirectory({})".format(headpath) + message = f" ! 'None' SurvexDirectory returned from GetSurvexDirectory({headpath})" print(message) print(message,file=sys.stderr) DataIssue.objects.create(parser='survex', message=message, url = f'/survexfile/{svxid}') @@ -964,7 +964,7 @@ class LoadingSurvex(): self.ReportNonCaveIncludes(headpath, svxid, depth) if not newfile.survexdirectory: - message = " ! SurvexDirectory NOT SET in new SurvexFile {} ".format(svxid) + message = f" ! SurvexDirectory NOT SET in new SurvexFile {svxid} " print(message) print(message,file=sys.stderr) DataIssue.objects.create(parser='survex', message=message) @@ -977,9 +977,9 @@ class LoadingSurvex(): raise if debugprint: - print(" # datastack end LoadSurvexFile:{} 'type':".format(svxid), end="") + print(f" # datastack end LoadSurvexFile:{svxid} 'type':", end="") for dict in self.datastack: - print("'{}' ".format(dict["type"].upper()), end="") + print(f"'{dict['type'].upper()}' ", end="") print("") def ProcessIncludeLine(self, included): @@ -997,7 +997,7 @@ class LoadingSurvex(): svxid = edulcni.groups()[0] if debugprint: depth = " " * self.depthbegin - print("{:2}{} - Edulcni survexfile:'{}'".format(self.depthbegin, depth, svxid)) + print(f"{self.depthbegin:2}{depth} - Edulcni survexfile:'{svxid}'") if svxid.lower() == debugprinttrigger.lower(): debugprint = False self.currentsurvexfile.save() @@ -1056,7 +1056,7 @@ class LoadingSurvex(): self.depthbegin = 0 self.datastar = self.datastardefault blocklegs = self.legsnumber - print(self.insp+" - MEM:{:.3f} Reading. parent:{} <> {} ".format(get_process_memory(),survexblock.survexfile.path, survexfile.path)) + 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 @@ -1067,7 +1067,7 @@ class LoadingSurvex(): # 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 = '%s-%s' % (path_match.group(1), path_match.group(2)) + pos_cave = f'{path_match.group(1)}-{path_match.group(2)}' cave = getCaveByReference(pos_cave) if cave: survexfile.cave = cave @@ -1103,7 +1103,7 @@ class LoadingSurvex(): if blockcount % 800 ==0 : print("\n", file=sys.stderr,end='') mem=get_process_memory() - print(" - MEM: {:7.2f} MB in use".format(mem),file=sys.stderr) + print(f" - MEM: {mem:7.2f} MB in use",file=sys.stderr) print(" ", file=sys.stderr,end='') sys.stderr.flush() @@ -1114,7 +1114,7 @@ class LoadingSurvex(): depth = " " * self.depthbegin self.insp = depth if debugprint: - print("{:2}{} - Begin for :'{}'".format(self.depthbegin,depth, blkid)) + print(f"{self.depthbegin:2}{depth} - Begin for :'{blkid}'") pathlist = "" for id in self.stackbegin: if len(id) > 0: @@ -1125,27 +1125,27 @@ class LoadingSurvex(): depth = " " * self.depthbegin if debugprint: - print("{:2}{} - End from:'{}'".format(self.depthbegin,depth,args)) + print(f"{self.depthbegin:2}{depth} - End from:'{args}'") print("{:2}{} - LEGS: {} (n: {}, length:{} units:{})".format(self.depthbegin, depth, self.slength, self.slength, self.legsnumber, self.units)) def pushblock(): nonlocal blkid if debugprint: - print(" # datastack at 1 *begin {} 'type':".format(blkid), end="") + print(f" # datastack at 1 *begin {blkid} 'type':", end="") for dict in self.datastack: - print("'{}' ".format(dict["type"].upper()), end="") + print(f"'{dict['type'].upper()}' ", end="") print("") - print("'{}' self.datastar ".format(self.datastar["type"].upper())) + print(f"'{self.datastar['type'].upper()}' self.datastar ") # ------------ * DATA self.datastack.append(copy.deepcopy(self.datastar)) # ------------ * DATA if debugprint: - print(" # datastack at 2 *begin {} 'type':".format(blkid), end="") + print(f" # datastack at 2 *begin {blkid} 'type':", end="") for dict in self.datastack: - print("'{}' ".format(dict["type"].upper()), end="") + print(f"'{dict['type'].upper()}' ", end="") print("") - print("'{}' self.datastar ".format(self.datastar["type"].upper())) + print(f"'{self.datastar['type'].upper()}' self.datastar ") # ------------ * FLAGS self.flagsstack.append(copy.deepcopy(self.flagsstar)) @@ -1156,27 +1156,27 @@ class LoadingSurvex(): nonlocal blkid nonlocal oldflags if debugprint: - print(" # datastack at *end '{} 'type':".format(blkid), end="") + print(f" # datastack at *end '{blkid} 'type':", end="") for dict in self.datastack: - print("'{}' ".format(dict["type"].upper()), end="") + print(f"'{dict['type'].upper()}' ", end="") print("") - print("'{}' self.datastar ".format(self.datastar["type"].upper())) + print(f"'{self.datastar['type'].upper()}' self.datastar ") # ------------ * DATA self.datastar = copy.deepcopy(self.datastack.pop()) # ------------ * DATA if debugprint: - print(" # datastack after *end '{} 'type':".format(blkid), end="") + print(f" # datastack after *end '{blkid} 'type':", end="") for dict in self.datastack: - print("'{}' ".format(dict["type"].upper()), end="") + print(f"'{dict['type'].upper()}' ", end="") print("") - print("'{}' self.datastar ".format(self.datastar["type"].upper())) + print(f"'{self.datastar['type'].upper()}' self.datastar ") # ------------ * FLAGS self.flagsstar = copy.deepcopy(self.flagsstack.pop()) # ------------ * FLAGS if debugprint: if oldflags["skiplegs"] != self.flagsstar["skiplegs"]: - print(" # POP 'any' flag now:'{}' was:{} ".format(self.flagsstar["skiplegs"], oldflags["skiplegs"])) + print(f" # POP 'any' flag now:'{self.flagsstar['skiplegs']}' was:{oldflags['skiplegs']} ") def starstatement(star): """Interprets a survex comamnd where * is the first character on the line, e.g. *begin @@ -1263,7 +1263,7 @@ class LoadingSurvex(): self.LoadSurvexFlags(args) if debugprint: if oldflags["skiplegs"] != self.flagsstar["skiplegs"]: - print(" # CHANGE 'any' flag now:'{}' was:{} ".format(self.flagsstar["skiplegs"], oldflags["skiplegs"])) + print(f" # CHANGE 'any' flag now:'{self.flagsstar['skiplegs']}' was:{oldflags['skiplegs']} ") elif self.rx_data.match(cmd): if self.LoadSurvexDataNormal(survexblock, args): @@ -1284,7 +1284,7 @@ class LoadingSurvex(): elif self.rx_set.match(cmd) and self.rx_names.match(cmd): pass elif self.rx_include.match(cmd): - message = " ! -ERROR *include command not expected here {}. Re-run a full Survex import.".format(path) + message = f" ! -ERROR *include command not expected here {path}. Re-run a full Survex import." print(message) print(message,file=sys.stderr) DataIssue.objects.create(parser='survex', message=message, ) @@ -1349,7 +1349,7 @@ class LoadingSurvex(): includestmt =self.rx_include.match(svxline) if not includestmt: - fcollate.write("{}\n".format(svxline.strip())) + fcollate.write(f"{svxline.strip()}\n") sline, comment = self.rx_comment.match(svxline.strip()).groups() star = self.rx_star.match(sline) @@ -1367,8 +1367,8 @@ class LoadingSurvex(): self.depthinclude += 1 # fininclude = open(fullpath,'r') finincludename = fullpath - fcollate.write(";|*include {}\n".format(includepath)) - flinear.write("{:2} {} *include {}\n".format(self.depthinclude, indent, includepath)) + fcollate.write(f";|*include {includepath}\n") + flinear.write(f"{self.depthinclude:2} {indent} *include {includepath}\n") push = includepath.lower() self.includestack.append(push) #----------------- @@ -1381,8 +1381,8 @@ class LoadingSurvex(): print(message,file=flinear) print(message,file=sys.stderr) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(path)) - flinear.write("{:2} {} *edulcni {}\n".format(self.depthinclude, indent, pop)) - fcollate.write(";|*edulcni {}\n".format(pop)) + flinear.write(f"{self.depthinclude:2} {indent} *edulcni {pop}\n") + fcollate.write(f";|*edulcni {pop}\n") # fininclude.close() self.depthinclude -= 1 #-------------------------------------------------------- @@ -1399,16 +1399,16 @@ class LoadingSurvex(): else: pushargs = " " self.stackbegin.append(pushargs.lower()) - flinear.write(" {:2} {} *begin {}\n".format(self.depthbegin, depth, args)) + flinear.write(f" {self.depthbegin:2} {depth} *begin {args}\n") pass elif re.match("(?i)end$", cmd): depth = " " * self.depthbegin - flinear.write(" {:2} {} *end {}\n".format(self.depthbegin, depth, args)) + flinear.write(f" {self.depthbegin:2} {depth} *end {args}\n") if not args: args = " " popargs = self.stackbegin.pop() if popargs != args.lower(): - message = "!! ERROR mismatch in BEGIN/END labels pop!=push '{}'!='{}'\n{}".format(popargs, args, self. stackbegin) + message = f"!! ERROR mismatch in BEGIN/END labels pop!=push '{popargs}'!='{args}'\n{self.stackbegin}" print(message) print(message,file=flinear) print(message,file=sys.stderr) @@ -1418,7 +1418,7 @@ class LoadingSurvex(): pass elif re.match("(?i)title$", cmd): depth = " " * self.depthbegin - flinear.write(" {:2} {} *title {}\n".format(self.depthbegin, depth, args)) + flinear.write(f" {self.depthbegin:2} {depth} *title {args}\n") pass indent = " " * self.depthinclude @@ -1443,7 +1443,7 @@ class LoadingSurvex(): #print(message,file=sys.stderr) DataIssue.objects.create(parser='survex', message=message, url=get_offending_filename(path)) if self.svxfileslist.count(path) > 2: - message = " ! ERROR. Should have been caught before this. Survex file already *included 2x. Probably an infinite loop so fix your *include statements that include this. Aborting. {}".format(path) + message = f" ! ERROR. Should have been caught before this. Survex file already *included 2x. Probably an infinite loop so fix your *include statements that include this. Aborting. {path}" print(message) print(message,file=flinear) #print(message,file=sys.stderr) @@ -1537,7 +1537,7 @@ class LoadingSurvex(): self.caverndate = now - 2*365*24*3600 if not self.caverndate: - sp = subprocess.run(["which", "{}".format(settings.CAVERN)], + sp = subprocess.run(["which", f"{settings.CAVERN}"], capture_output=True, check=False, text=True) if sp.returncode != 0: message = f' ! Error running "which" on {settings.CAVERN}' @@ -1573,7 +1573,7 @@ def FindAndLoadSurvex(survexblockroot): # Redirect sys.stdout to the file sys.stdout = open('svxblks.log', 'w') - print(' - Scanning Survex Blocks tree from {}.svx ...'.format(settings.SURVEX_TOPNAME),file=sys.stderr) + print(f' - Scanning Survex Blocks tree from {settings.SURVEX_TOPNAME}.svx ...',file=sys.stderr) survexfileroot = survexblockroot.survexfile # i.e. SURVEX_TOPNAME only collatefilename = "_" + survexfileroot.path + ".svx" @@ -1582,7 +1582,7 @@ def FindAndLoadSurvex(survexblockroot): svx_scan.depthinclude = 0 fullpathtotop = os.path.join(survexfileroot.survexdirectory.path, survexfileroot.path) - print(" - RunSurvexIfNeeded cavern on '{}'".format(fullpathtotop), file=sys.stderr) + print(f" - RunSurvexIfNeeded cavern on '{fullpathtotop}'", file=sys.stderr) svx_scan.RunSurvexIfNeeded(fullpathtotop, fullpathtotop) svx_scan.checkUniqueness(fullpathtotop) @@ -1590,14 +1590,14 @@ def FindAndLoadSurvex(survexblockroot): fcollate = open(collatefilename, 'w') mem0 = get_process_memory() - print(" - MEM:{:7.2f} MB START".format(mem0),file=sys.stderr) + print(f" - MEM:{mem0:7.2f} MB START",file=sys.stderr) flinear = open('svxlinear.log', 'w') - flinear.write(" - MEM:{:7.2f} MB START {}\n".format(mem0,survexfileroot.path)) + flinear.write(f" - MEM:{mem0:7.2f} MB START {survexfileroot.path}\n") print(" ", file=sys.stderr,end='') finrootname = Path(settings.SURVEX_DATA, survexfileroot.path + ".svx") - fcollate.write(";*include {}\n".format(survexfileroot.path)) - flinear.write("{:2} {} *include {}\n".format(svx_scan.depthinclude, indent, survexfileroot.path)) + fcollate.write(f";*include {survexfileroot.path}\n") + flinear.write(f"{svx_scan.depthinclude:2} {indent} *include {survexfileroot.path}\n") import cProfile, pstats from pstats import SortKey @@ -1612,19 +1612,19 @@ def FindAndLoadSurvex(survexblockroot): ps.sort_stats(SortKey.CUMULATIVE) ps.print_stats() - flinear.write("{:2} {} *edulcni {}\n".format(svx_scan.depthinclude, indent, survexfileroot.path)) - fcollate.write(";*edulcni {}\n".format(survexfileroot.path)) + flinear.write(f"{svx_scan.depthinclude:2} {indent} *edulcni {survexfileroot.path}\n") + fcollate.write(f";*edulcni {survexfileroot.path}\n") mem1 = get_process_memory() - flinear.write("\n - MEM:{:.2f} MB STOP {}\n".format(mem1,survexfileroot.path)) - flinear.write(" - MEM:{:.3f} MB ADDITIONALLY USED\n".format(mem1-mem0)) - flinear.write(" - {:,} survex files in linear include list \n".format(len(svx_scan.svxfileslist))) + flinear.write(f"\n - MEM:{mem1:.2f} MB STOP {survexfileroot.path}\n") + flinear.write(f" - MEM:{mem1 - mem0:.3f} MB ADDITIONALLY USED\n") + flinear.write(f" - {len(svx_scan.svxfileslist):,} survex files in linear include list \n") - print("\n - {:,} runs of survex 'cavern' refreshing .3d files".format(svx_scan.caverncount),file=sys.stderr) - print(" - {:,} survex files from tree in linear include list".format(len(svx_scan.svxfileslist)),file=sys.stderr) + print(f"\n - {svx_scan.caverncount:,} runs of survex 'cavern' refreshing .3d files",file=sys.stderr) + print(f" - {len(svx_scan.svxfileslist):,} survex files from tree in linear include list",file=sys.stderr) mem1 = get_process_memory() - print(" - MEM:{:7.2f} MB END ".format(mem1),file=sys.stderr) - print(" - MEM:{:7.3f} MB ADDITIONALLY USED".format(mem1-mem0),file=sys.stderr) + print(f" - MEM:{mem1:7.2f} MB END ",file=sys.stderr) + print(f" - MEM:{mem1 - mem0:7.3f} MB ADDITIONALLY USED",file=sys.stderr) # # Process all the omitted files in :loser: with some exceptions # @@ -1679,43 +1679,43 @@ def FindAndLoadSurvex(survexblockroot): svx_scan.svxfileslist = [] # free memory svx_scan = None # Hmm. Does this actually delete all the instance variables if they are lists, dicts etc.? - print(" - RunSurvexIfNeeded cavern on '{}'".format(fullpathtotop), file=sys.stderr) + print(f" - RunSurvexIfNeeded cavern on '{fullpathtotop}'", file=sys.stderr) omit_scan.RunSurvexIfNeeded(fullpathtotop, fullpathtotop) omit_scan.checkUniqueness(fullpathtotop) mem0 = get_process_memory() - print(" - MEM:{:7.2f} MB START '_unseens'".format(mem0),file=sys.stderr) + print(f" - MEM:{mem0:7.2f} MB START '_unseens'",file=sys.stderr) #flinear = open('svxlinear.log', 'w') flinear.write(f" - MEM:{mem0:7.2f} MB START '_unseens'\n") print(" ", file=sys.stderr,end='') finrootname = fullpathtotop - fcollate.write(";*include {}\n".format('_unseens.svx')) - flinear.write("{:2} {} *include {}\n".format(omit_scan.depthinclude, indent, '_unseens')) + fcollate.write(";*include _unseens.svx\n") + flinear.write(f"{omit_scan.depthinclude:2} {indent} *include _unseens\n") stop_dup_warning = True #---------------------------------------------------------------- omit_scan.PushdownStackScan(survexblockroot, '_unseens', finrootname, flinear, fcollate) #---------------------------------------------------------------- stop_dup_warning = False - flinear.write("{:2} {} *edulcni {}\n".format(omit_scan.depthinclude, indent, '_unseens')) - fcollate.write(";*edulcni {}\n".format('_unseens.svx')) + flinear.write(f"{omit_scan.depthinclude:2} {indent} *edulcni _unseens\n") + fcollate.write(";*edulcni _unseens.svx\n") mem1 = get_process_memory() - flinear.write("\n - MEM:{:.2f} MB STOP {} OMIT\n".format(mem1,'_unseens.svx')) - flinear.write(" - MEM:{:.3f} MB ADDITIONALLY USED OMIT\n".format(mem1-mem0)) - flinear.write(" - {:,} survex files in linear include list OMIT \n".format(len(omit_scan.svxfileslist))) + flinear.write(f"\n - MEM:{mem1:.2f} MB STOP _unseens.svx OMIT\n") + flinear.write(f" - MEM:{mem1 - mem0:.3f} MB ADDITIONALLY USED OMIT\n") + flinear.write(f" - {len(omit_scan.svxfileslist):,} survex files in linear include list OMIT \n") flinear.close() fcollate.close() - print("\n - {:,} runs of survex 'cavern' refreshing .3d files in the unseen list".format(omit_scan.caverncount),file=sys.stderr) + print(f"\n - {omit_scan.caverncount:,} runs of survex 'cavern' refreshing .3d files in the unseen list",file=sys.stderr) - print(" - {:,} survex files in linear include list including previously unseen ones \n".format(len(omit_scan.svxfileslist)),file=sys.stderr) + print(f" - {len(omit_scan.svxfileslist):,} survex files in linear include list including previously unseen ones \n",file=sys.stderr) omit_scan = None # Hmm. Does this actually delete all the instance variables if they are lists, dicts etc.? mem1 = get_process_memory() - print(" - MEM:{:7.2f} MB END ".format(mem1),file=sys.stderr) - print(" - MEM:{:7.3f} MB ADDITIONALLY USED".format(mem1-mem0),file=sys.stderr) + print(f" - MEM:{mem1:7.2f} MB END ",file=sys.stderr) + print(f" - MEM:{mem1 - mem0:7.3f} MB ADDITIONALLY USED",file=sys.stderr) # Before doing this, it would be good to identify the *equate and *entrance we need that are relevant to the @@ -1741,8 +1741,8 @@ def FindAndLoadSurvex(survexblockroot): # ps.sort_stats(SortKey.CUMULATIVE) # ps.print_stats() mem1 = get_process_memory() - print("\n - MEM:{:7.2f} MB STOP".format(mem1),file=sys.stderr) - print(" - MEM:{:7.3f} MB ADDITIONALLY USED".format(mem1-mem0),file=sys.stderr) + print(f"\n - MEM:{mem1:7.2f} MB STOP",file=sys.stderr) + print(f" - MEM:{mem1 - mem0:7.3f} MB ADDITIONALLY USED",file=sys.stderr) # Close the logging file, Restore sys.stdout to our old saved file handle sys.stdout.close() @@ -1753,7 +1753,7 @@ def FindAndLoadSurvex(survexblockroot): legsnumber = svx_load.legsnumber mem1 = get_process_memory() - print(" - Number of SurvexDirectories: {:,}".format(len(svx_load.survexdict))) + print(f" - Number of SurvexDirectories: {len(svx_load.survexdict):,}") tf=0 for d in svx_load.survexdict: tf += len(svx_load.survexdict[d]) @@ -1790,7 +1790,7 @@ def MakeOmitFileRoot(fn): def LoadSurvexBlocks(): mem1 = get_process_memory() - print(" - MEM:{:7.2f} MB now ".format(mem1),file=sys.stderr) + print(f" - MEM:{mem1:7.2f} MB now ",file=sys.stderr) print(' - Flushing All Survex Blocks...') # why does this increase memory use by 20 MB ?! @@ -1803,7 +1803,7 @@ def LoadSurvexBlocks(): SurvexPersonRole.objects.all().delete() SurvexStation.objects.all().delete() mem1 = get_process_memory() - print(" - MEM:{:7.2f} MB now. Foreign key objects loaded on deletion. ".format(mem1),file=sys.stderr) + print(f" - MEM:{mem1:7.2f} MB now. Foreign key objects loaded on deletion. ",file=sys.stderr) print(" - Flushing survex Data Issues ") DataIssue.objects.filter(parser='survex').delete() @@ -1814,7 +1814,7 @@ def LoadSurvexBlocks(): DataIssue.objects.filter(parser='xEntrances').delete() print(" - survex Data Issues flushed") mem1 = get_process_memory() - print(" - MEM:{:7.2f} MB now ".format(mem1),file=sys.stderr) + print(f" - MEM:{mem1:7.2f} MB now ",file=sys.stderr) survexfileroot = MakeSurvexFileRoot() # this next makes a block_object assciated with a file_object.path = SURVEX_TOPNAME @@ -1838,7 +1838,7 @@ def LoadSurvexBlocks(): FindAndLoadSurvex(survexblockroot) #---------------------------------------------------------------- memend = get_process_memory() - print(" - MEMORY start:{:.3f} MB end:{:.3f} MB increase={:.3f} MB".format(memstart,memend, memend-memstart)) + print(f" - MEMORY start:{memstart:.3f} MB end:{memend:.3f} MB increase={memend - memstart:.3f} MB") survexblockroot.save() @@ -1904,14 +1904,14 @@ def LoadPositions(): print(message) topdata = os.fspath(Path(settings.SURVEX_DATA) / settings.SURVEX_TOPNAME) - print(' - Generating a list of Pos from %s.svx and then loading...' % (topdata)) + print(f' - Generating a list of Pos from {topdata}.svx and then loading...') found = 0 skip = {} print("\n") # extra line because cavern overwrites the text buffer somehow # cavern defaults to using same cwd as supplied input file - completed_process = subprocess.run(["which", "{}".format(settings.CAVERN)], + completed_process = subprocess.run(["which", f"{settings.CAVERN}"], capture_output=True, check=True, text=True) cav_t = os.path.getmtime(completed_process.stdout.strip()) @@ -1976,17 +1976,17 @@ def LoadPositions(): if len(sbqs)==1: sb = sbqs[0] if len(sbqs)>1: - message = " ! MULTIPLE SurvexBlocks {:3} matching Entrance point {} {} '{}'".format(len(sbqs), blockpath, sid, id) + message = f" ! MULTIPLE SurvexBlocks {len(sbqs):3} matching Entrance point {blockpath} {sid} '{id}'" print(message) DataIssue.objects.create(parser='entrances', message=message) sb = sbqs[0] elif len(sbqs)<=0: - message = " ! ZERO SurvexBlocks matching Entrance point {} {} '{}'".format(blockpath, sid, id) + message = f" ! ZERO SurvexBlocks matching Entrance point {blockpath} {sid} '{id}'" print(message) DataIssue.objects.create(parser='entrances', message=message) sb = survexblockroot except: - message = ' ! FAIL in getting SurvexBlock matching Entrance point {} {}'.format(blockpath, sid) + message = f' ! FAIL in getting SurvexBlock matching Entrance point {blockpath} {sid}' print(message) DataIssue.objects.create(parser='entrances', message=message) try: @@ -1997,9 +1997,9 @@ def LoadPositions(): ss.save() found += 1 except: - message = ' ! FAIL to create SurvexStation Entrance point {} {}'.format(blockpath, sid) + message = f' ! FAIL to create SurvexStation Entrance point {blockpath} {sid}' print(message) DataIssue.objects.create(parser='entrances', message=message) raise - print(" - {} SurvexStation entrances found.".format(found)) + print(f" - {found} SurvexStation entrances found.")