works on windows now

This commit is contained in:
Martin Brodbeck 2021-08-12 14:29:15 +02:00
parent 77e9130fa1
commit 0a3e14c881
1 changed files with 23 additions and 9 deletions

View File

@ -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()