NZRS/wavetrace

Code review ideas: python xml libs instead of grep/echo/sed code

Opened this issue · 1 comments

kml2wld.sh contains this code

imgcoord=$(grep -A 10 "$imgname" "$path/$bn.kml") north=$(echo $imgcoord | sed 's/^.*<north>\([0-9-][0-9\.]*\)<\/north>.*/\1/') south=$(echo $imgcoord | sed 's/^.*<south>\([0-9-][0-9\.]*\)<\/south>.*/\1/') east=$(echo $imgcoord | sed 's/^.*<east>\([0-9-][0-9\.]*\)<\/east>.*/\1/') west=$(echo $imgcoord | sed 's/^.*<west>\([0-9-][0-9\.]*\)<\/west>.*/\1/')

Fast, full of zen, fairly self documenting, but a nightmare for a python dev to debug.

The kml could be opened with an xml parser (ElementTree XML API has been build into python since 2.5 AFAIK) and much of the manipulation could be done in pure python.