Skip to content

Commit 2abe1a4

Browse files
Frank PaynterFrank Paynter
authored andcommitted
Changed decoding to UTF-8, removed logging code, removed test files
1 parent 0e1083a commit 2abe1a4

File tree

5 files changed

+9
-108
lines changed

5 files changed

+9
-108
lines changed

lib/xcsoar/mapgen/server/server.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ def index(self, **params):
6767
return view.render()
6868

6969
name = params["name"].strip()
70-
# cherrypy.log('params: name = %s, mail = %s, detail = %s' % (name, params["mail"], params["level_of_detail"]))
71-
70+
7271
if name == "":
7372
return view.render(error="No map name given!") | HTMLFormFiller(data=params)
7473

@@ -82,15 +81,6 @@ def index(self, **params):
8281

8382
selection = params["selection"]
8483
waypoint_file = params["waypoint_file"]
85-
# cherrypy.log('waypoint_file = %s, waypoint_filename = %s, selection = %s' % (waypoint_file.file, waypoint_file.filename, selection))
86-
# cherrypy.log('waypoint_file = %s' % waypoint_file.file)
87-
88-
#gfp added to determine 'waypoint_file' type
89-
# cherrypy.log('displaying lines from waypoint_file.file')
90-
# lines = waypoint_file.file.readlines()
91-
# for line in lines:
92-
# cherrypy.log(line)
93-
9484

9585
if selection in ["waypoint", "waypoint_bounds"]:
9686
if not waypoint_file.file or not waypoint_file.filename:
@@ -110,7 +100,7 @@ def index(self, **params):
110100
)
111101
)
112102

113-
# #241212 better way to write this boolean expression (filename already forced to lowercase)
103+
#241212 better way to write this boolean expression (filename already forced to lowercase)
114104
if not filename.endswith(".dat") and not filename.endswith(".cup"):
115105
raise RuntimeError(
116106
"Waypoint file {} has an unsupported format.".format(
@@ -125,7 +115,6 @@ def index(self, **params):
125115
"waypoints.cup" if filename.endswith(".cup") else "waypoints.dat"
126116
)
127117

128-
cherrypy.log(f'in server.py: {filename} bounds: left = {desc.bounds.left:.3f}, right: {desc.bounds.right:.3f}, top: {desc.bounds.top:.3f}, bot {desc.bounds.bottom:.3f}')
129118
return view.render(error=f"left: {desc.bounds.left:.3f}, right: {desc.bounds.right:.3f}, top: {desc.bounds.top:.3f}, bot {desc.bounds.bottom:.3f}")| HTMLFormFiller(data=params)
130119

131120
except:
@@ -165,8 +154,7 @@ def index(self, **params):
165154

166155
if desc.waypoint_file:
167156
waypoint_file.file.seek(0)
168-
cherrypy.log("In the 'desc.waypoint_file' routine")
169-
157+
170158
f = open(job.file_path(desc.waypoint_file), "w")
171159
try:
172160
shutil.copyfileobj(fsrc=waypoint_file.file, fdst=f, length=1024 * 64)

lib/xcsoar/mapgen/server/view.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def wrapper(*args, **kwargs):
3333

3434

3535
def render(*args, **kwargs):
36-
# cherrypy.log(f'In render(): args = {args}, kwargs = {kwargs}')
3736
"""Function to render the given data to the template specified via the
3837
``@output`` decorator.
3938
"""

lib/xcsoar/mapgen/waypoints/parser.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
# -*- coding: utf-8 -*-
22
from xcsoar.mapgen.waypoints.seeyou_reader import parse_seeyou_waypoints
33
from xcsoar.mapgen.waypoints.winpilot_reader import parse_winpilot_waypoints
4-
import cherrypy
5-
6-
#cherrypy.log(data.decode('utf-8'))
74

85
def parse_waypoint_file(filename, file=None):
9-
# cherrypy.log('in parse_waypoint_file: filename = %s' % filename)
10-
lines = 0 #gfp added so 'lines' object stays in scope
11-
if not file:
12-
cherrypy.log('in parse_waypoint_file: if not file block with filename = %s' % filename)
13-
14-
else:
15-
# # #241207 gfp bugfix: parser fcns need 'lines' (list of lines) vs 'file'
16-
lines = file.readlines()
17-
18-
# cherrypy.log('in parse_waypoint_file: %s lines read from %s' %(lines.count, filename))
19-
cherrypy.log('in parse_waypoint_file: %s lines read from %s' %(len(lines), filename))
20-
# wpnum = 0
21-
# for line in lines:
22-
# wpnum+=1
23-
# decoded_line = line.decode('ISO-8859-2')
24-
# cherrypy.log('line%s: %s' % (wpnum, decoded_line))
6+
lines = file.readlines()
257

268
if filename.lower().endswith(".xcw") or filename.lower().endswith(".dat"):
279
return parse_winpilot_waypoints(lines)
2810
elif filename.lower().endswith(".cup"):
29-
# cherrypy.log('in parse_waypoint_file filename.lower().endswith(".cup"): filename = %s' % filename)
3011
return parse_seeyou_waypoints(lines)#241207 gfp bugfix:
3112
else:
3213
raise RuntimeError(

lib/xcsoar/mapgen/waypoints/seeyou_reader.py

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from xcsoar.mapgen.waypoints.waypoint import Waypoint
33
from xcsoar.mapgen.waypoints.list import WaypointList
4-
import cherrypy
54

65

76

@@ -37,7 +36,6 @@ def __next__(self):
3736

3837

3938
def __parse_altitude(str):
40-
# cherrypy.log(f'in parse_altitude({str})')
4139
str = str.lower()
4240
if str.endswith("ft") or str.endswith("f"):
4341
str = str.rstrip("ft")
@@ -78,57 +76,30 @@ def __parse_length(str):
7876

7977
def parse_seeyou_waypoints(lines, bounds=None):
8078
waypoint_list = WaypointList()
81-
# cherrypy.log('in parse_seeyou_waypoints function:')
82-
83-
#gfp 241210: modified to wait for header line before processing
84-
#gfp 241210: added 'ISO-8859-2' decoding for correct cherrypy logging display
85-
86-
#gfp 241208 added to print out all lines in selected .CUP file
87-
# wpnum = 0
88-
# for byteline in lines:
89-
# wpnum = wpnum + 1
90-
# line = byteline.decode('ISO-8859-2')
9179

9280
header = 'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc'
9381

9482
wpnum = 0
9583
for byteline in lines:
9684
wpnum = wpnum + 1
97-
line = byteline.decode('ISO-8859-2') #gfp 241210: added 'ISO-8859-2' decoding for correct cherrypy logging display
98-
line = line.strip()
99-
100-
# cherrypy.log('in for loop: wpnum = %s line = %s' %(wpnum, line))
101-
# cherrypy.log(f'for loop row {wpnum}: {line}')
85+
line = byteline.decode('UTF-8')
10286

10387
#check for blank lines or comments
10488
if line == "" or line.startswith("*"):
10589
continue
10690

10791
if header in line:
108-
# cherrypy.log(f'header line found at row {wpnum}: {line}')
10992
continue #skip to next line (first waypoint line)
11093

11194
if line == "-----Related Tasks-----":
11295
break
11396

114-
# cherrypy.log('in for loop before line = __CSVLine(line): wpnum = %s' %wpnum)
115-
11697
fields = []
11798
CSVline = __CSVLine(line)
118-
# cherrypy.log(f'row {wpnum}: line = __CSVLine(line) ->> {line}')
119-
99+
120100
while CSVline.has_next():
121101
fields.append(next(CSVline))
122102

123-
124-
#display fields for this line
125-
# cherrypy.log('extracted fields for line = %s' %wpnum)
126-
# idx = 0
127-
# for field in fields:
128-
# cherrypy.log(f' field[{idx}] = {field}')
129-
# idx += 1
130-
131-
132103
if len(fields) < 6:
133104
continue
134105

@@ -146,10 +117,7 @@ def parse_seeyou_waypoints(lines, bounds=None):
146117
wp.altitude = __parse_altitude(fields[5])
147118
wp.name = fields[0].strip()
148119
wp.country_code = fields[2].strip()
149-
150-
# cherrypy.log('waypoint %s: name = %s' %(wpnum, wp.name))
151-
152-
120+
153121
if len(fields) > 6 and len(fields[6]) > 0:
154122
wp.cup_type = int(fields[6])
155123

@@ -165,11 +133,7 @@ def parse_seeyou_waypoints(lines, bounds=None):
165133
if len(fields) > 10 and len(fields[10]) > 0:
166134
wp.comment = fields[10].strip()
167135

168-
# cherrypy.log(f'waypoint {wpnum}: {wp.name}, {wp.lat:.3f}, {wp.lon:.3f}')
169136

170-
#gfp print out current 'bounds' params
171-
# cherrypy.log(f'bounds = {bounds}')
172-
173137
waypoint_list.append(wp)
174138

175139

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
# -*- coding: utf-8 -*-
22
from xcsoar.mapgen.waypoints.waypoint import Waypoint
33
from xcsoar.mapgen.waypoints.list import WaypointList
4-
import cherrypy
54

65
def __parse_altitude(str):
7-
# cherrypy.log(f'parse_altitude({str})')
86
str = str.lower()
97
if str.endswith("ft") or str.endswith("f"):
108
str = str.rstrip("ft")
119
return int(str) * 0.3048
1210
else:
1311
str = str.rstrip("m")
14-
# cherrypy.log(f'parse_altitude:str = {str})')
1512
float_alt = float(str)
16-
# cherrypy.log(f'parse_altitude:float_alt = {float_alt})')
1713
int_alt = int(float_alt)
18-
# cherrypy.log(f'parse_altitude:int_alt = {int_alt})')
1914

2015
return int(int_alt)
2116

@@ -27,77 +22,51 @@ def __parse_altitude(str):
2722
# dd:mm.dd (for example: 36:15.33N)
2823
# dd:mm.ddd (for example: 36:15.333N)
2924
def __parse_coordinate(str):
30-
# cherrypy.log(f'winpilot parse_coordinate({str})')
3125

3226
str = str.lower()
3327
negative = str.endswith("s") or str.endswith("w")
3428
str = str.rstrip("sw") if negative else str.rstrip("ne")
3529

36-
# cherrypy.log(f'parse_coordinate before str.split: str = {str}')
37-
3830
strsplit = str.split(":")
39-
# cherrypy.log(f'parse_coordinate after str.split into {len(strsplit)} elements')
4031
if len(strsplit) < 2:
4132
return None
4233

4334
if len(strsplit) == 2:
44-
# cherrypy.log(f'parse_coordinate in 2 element block')
4535
# degrees + minutes / 60
4636
a = int(strsplit[0]) + float(strsplit[1]) / 60
47-
# cherrypy.log(f'parse_coordinate in 2 element block: a = {a}')
4837

4938
if len(strsplit) == 3:
50-
# cherrypy.log(f'parse_coordinate in 3 element block')
5139
# degrees + minutes / 60 + seconds / 3600
5240
a = int(str[0]) + float(str[1]) / 60 + float(str[2]) / 3600
53-
# cherrypy.log(f'parse_coordinate in 3 element block: a = {a}')
5441

5542
if negative:
5643
a *= -1
5744

58-
# cherrypy.log(f'parse_coordinate just before return with a = {a}')
59-
6045
return a
6146

6247

6348
def parse_winpilot_waypoints(lines):
64-
# cherrypy.log('in parse_winpilot_waypoints function:')
6549

6650
waypoint_list = WaypointList()
6751
wpnum = 0
6852
for byteline in lines:
6953
wpnum += 1
70-
# cherrypy.log(f'winpilot line {wpnum}: {byteline}')
7154

72-
line = byteline.decode('ISO-8859-2') #gfp 241210: added 'ISO-8859-2' decoding for correct cherrypy logging display
55+
line = byteline.decode('UTF-8')
7356
line = line.strip()
7457
if line == "" or line.startswith("*"):
7558
continue
76-
# cherrypy.log(f'winpilot line {wpnum}: {line}')
77-
59+
7860
fields = line.split(",")
79-
# cherrypy.log(f'winpilot line {wpnum}: fields = {fields}')
80-
# cherrypy.log(f'winpilot line {wpnum}: line splits into {len(fields)} fields')
8161
if len(fields) < 6:
8262
continue
8363

84-
85-
86-
# fieldnum = 0
87-
# for field in fields:
88-
# cherrypy.log(f'field {fieldnum} = {field}')
89-
# fieldnum += 1
90-
9164
wp = Waypoint()
9265
wp.lat = __parse_coordinate(fields[1])
9366
wp.lon = __parse_coordinate(fields[2])
9467
wp.altitude = __parse_altitude(fields[3])
9568
wp.name = fields[5].strip()
9669

97-
# cherrypy.log(f'waypoint {wpnum}: {wp.name}, {wp.lat:.3f}, {wp.lon:.3f}')
98-
9970
waypoint_list.append(wp)
10071

101-
102-
10372
return waypoint_list

0 commit comments

Comments
 (0)