From 0a3e14c8817ceba6615b9ddc0b1818c2d49ff6a4 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 12 Aug 2021 14:29:15 +0200 Subject: [PATCH] works on windows now --- sp_replace_typ.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/sp_replace_typ.py b/sp_replace_typ.py index b73e93a..27b7433 100755 --- a/sp_replace_typ.py +++ b/sp_replace_typ.py @@ -17,15 +17,24 @@ def get_famid_name_from_imgfile(imgfile_path): # shell=True, capture_output=True, text=True).stdout.strip() # name = subprocess.run(f'{GMT} -i {imgfile_path} | grep ", FID " | cut -d\',\' -f 3 | sed -e \'s/ //\'', # shell=True, capture_output=True, text=True).stdout.strip() - output = subprocess.run( - [f'{GMT} -i {imgfile_path}'], shell=True, capture_output=True, text=True).stdout - pattern = ".* FID (\d+), (.*)" + + # output = subprocess.run( + # [f'{GMT} -i "{imgfile_path}"'], shell=True, capture_output=True, text=True).stdout + + session = subprocess.Popen( + [GMT, '-i', imgfile_path], stdout=subprocess.PIPE) + output, _ = session.communicate() + pattern = b".* FID (\d+), (.*)" + + #pattern = ".* FID (\d+), (.*)" match = re.search(pattern, output) if not match: sys.exit( f"Keine gültige gmapsupp-Datei: {imgfile_path}\nBitte geben Sie eine gültige Datei an.") - return (match.group(1), match.group(2)) + fid = str(match.group(1), 'UTF-8').strip() + name = str(match.group(2), 'UTF-8').strip() + return (fid, name) def ask_for_visualization(): @@ -117,9 +126,13 @@ def main(): parser = argparse.ArgumentParser( description='Das Programm passt die Darstellung der Garmin-"Speichenkarte" an. ') parser.add_argument('imgfile', type=str, help='Garmin gmapsupp-Datei') - parser.add_argument() + parser.add_argument('-t', '--typdir', type=str, + help='Verzeichnis mit den TYP-Dateien') args = parser.parse_args() imgfile = args.imgfile + typ_dir = os.getcwd() + if args.typdir: + typ_dir = args.typdir (fid, name) = get_famid_name_from_imgfile(imgfile) @@ -127,13 +140,14 @@ def main(): typ_file = f'TYP_{name}_{fid}{basic}{srtm}{text}_gmapsupp.typ' - print(f'\nGewählte TYP Datei: {typ_file}\n') + print(f'\nGewählte TYP Datei: {typ_file}') + print(f'Verzeichnis mit den TYP-Dateien: {typ_dir}\n') - if not os.path.isfile(typ_file): + if not os.path.isfile(typ_dir + os.sep + typ_file): sys.exit('FEHLER: Die Typdatei ist nicht vorhanden.') print('Wende die Typ-Datei an…') - subprocess.run([GMT, '-wx', imgfile, typ_file]) + subprocess.run([GMT, '-wx', imgfile, typ_dir + os.sep + typ_file]) print('\nFertig.') @@ -141,5 +155,5 @@ if __name__ == "__main__": if platform.system() == 'Linux': GMT = './gmt' else: # Windows… - GMT = './gmt.exe' + GMT = 'gmt.exe' main()