Skip to content

Commit

Permalink
common: python 2 to 3 for modules/tools (ApolloAuto#10627)
Browse files Browse the repository at this point in the history
* 2to3 batch update

* remove unnecessary changes

* take care of division
  • Loading branch information
michael4338 authored Jan 14, 2020
1 parent 062fe77 commit 2a65a24
Show file tree
Hide file tree
Showing 200 changed files with 314 additions and 316 deletions.
2 changes: 1 addition & 1 deletion modules/tools/common/logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
4 changes: 2 additions & 2 deletions modules/tools/common/message_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down Expand Up @@ -29,7 +29,7 @@
from modules.map.relative_map.proto import navigation_pb2
from modules.guardian.proto import guardian_pb2

import proto_utils
from . import proto_utils


class MessageType:
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/common/proto_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
6 changes: 3 additions & 3 deletions modules/tools/configurator/ModuleConf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down Expand Up @@ -110,10 +110,10 @@ def prefetch(self, entity, descriptor, row, col, descript_path):
descriptor.type == descriptor.TYPE_MESSAGE:
for descript, item in entity.ListFields():
if row >= self.winy - 1:
if col >= (self.winx / 3) * 2:
if col >= (self.winx // 3) * 2:
return row, col
row = self.basex
col = col + self.winx / 3
col = col + self.winx // 3

descript_path.append(descript.name)
if descript.label == descript.LABEL_REPEATED:
Expand Down
6 changes: 3 additions & 3 deletions modules/tools/configurator/configurator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down Expand Up @@ -89,7 +89,7 @@ def setup(self):
self.stdscr.addstr(1, 50, "Class", curses.A_BOLD)
self.stdscr.addstr(1, 65, "Configuration File", curses.A_BOLD)

for idx in xrange(len(self.moduleconf)):
for idx in range(len(self.moduleconf)):
lidx = idx + 2
if idx == self.select:
self.stdscr.addstr(lidx, 2, self.moduleconf[idx].name,
Expand Down Expand Up @@ -128,7 +128,7 @@ def show(self):
"""
Update Main Screen
"""
for idx in xrange(len(self.moduleconf)):
for idx in range(len(self.moduleconf)):
lidx = idx + 2
if idx == self.select:
self.stdscr.addstr(lidx, 2, self.moduleconf[idx].name,
Expand Down
6 changes: 3 additions & 3 deletions modules/tools/control_info/control_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down Expand Up @@ -27,7 +27,7 @@
import matplotlib
import matplotlib.pyplot as plt
import numpy
import tkFileDialog
import tkinter.filedialog
from matplotlib import patches
from matplotlib import lines
from cyber_py import cyber
Expand Down Expand Up @@ -379,7 +379,7 @@ def press(self, event):
canbussub = node.create_reader('/apollo/canbus/chassis',
chassis_pb2.Chassis,
controlinfo.callback_canbus)
raw_input("Press Enter To Stop")
input("Press Enter To Stop")

mng = plt.get_current_fig_manager()
controlinfo.longitudinal()
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/create_map/convert_map_txt2bin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/create_map/create_map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/create_map/lane_recorder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/dump_gpsbin/dump_gpsbin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2018 The Apollo Authors. All Rights Reserved.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2019 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/gen_vehicle_protocol/extract_dbc_meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/gen_vehicle_protocol/gen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/gen_vehicle_protocol/gen_proto_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
6 changes: 3 additions & 3 deletions modules/tools/gen_vehicle_protocol/gen_protocols.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down Expand Up @@ -215,7 +215,7 @@ def get_byte_info(var):
bit = var["bit"]
byte_info = []
left_len = var["len"]
byte_idx = bit / 8
byte_idx = bit // 8
bit_start = bit % 8
if var["order"] == "motorola":
while left_len > 0:
Expand Down Expand Up @@ -399,7 +399,7 @@ def gen_control_cpp(car_type, protocol, output_dir):
) + "::" + var["enum"][0].upper()
else:
init_val = protocol["name"].capitalize(
) + "::" + var["enum"].values()[0].upper()
) + "::" + list(var["enum"].values())[0].upper()

set_private_var_init_list.append(" %s_ = %s;" %
(var["name"].lower(), init_val))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/map_gen/add_signal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/map_gen/extract_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/map_gen/map_gen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/map_gen/map_gen_single_lane.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/map_gen/map_gen_two_lanes_right_ext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/map_gen/plot_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/mapshow/libs/localization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down
24 changes: 12 additions & 12 deletions modules/tools/mapshow/libs/map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down Expand Up @@ -35,7 +35,7 @@ def __init__(self):
def init_colors(self):
color_num = 6
self.colors = []
values = range(color_num)
values = list(range(color_num))
jet = plt.get_cmap('brg')
color_norm = mcolors.Normalize(vmin=0, vmax=values[-1])
scalar_map = cmx.ScalarMappable(norm=color_norm, cmap=jet)
Expand Down Expand Up @@ -180,30 +180,30 @@ def _draw_label(label_id, point, ax, color_val):

@staticmethod
def _find_lane_central_point(lane):
segment_idx = len(lane.left_boundary.curve.segment) / 2
segment_idx = len(lane.left_boundary.curve.segment) // 2
median_segment = lane.left_boundary.curve.segment[segment_idx]
left_point_idx = len(median_segment.line_segment.point) / 2
left_point_idx = len(median_segment.line_segment.point) // 2
left_median_point = median_segment.line_segment.point[left_point_idx]

segment_idx = len(lane.right_boundary.curve.segment) / 2
segment_idx = len(lane.right_boundary.curve.segment) // 2
median_segment = lane.right_boundary.curve.segment[segment_idx]
right_point_idx = len(median_segment.line_segment.point) / 2
right_point_idx = len(median_segment.line_segment.point) // 2
right_median_point = median_segment.line_segment.point[right_point_idx]

x = (left_median_point.x + right_median_point.x) / 2
y = (left_median_point.y + right_median_point.y) / 2
x = (left_median_point.x + right_median_point.x) // 2
y = (left_median_point.y + right_median_point.y) // 2

return x, y

@staticmethod
def _get_median_point(points):
"""get_median_point"""
if len(points) % 2 == 1:
point = points[len(points) / 2]
point = points[len(points) // 2]
return point.x, point.y
else:
point1 = points[len(points) / 2 - 1]
point2 = points[len(points) / 2]
point1 = points[len(points) // 2 - 1]
point2 = points[len(points) // 2]
return (point1.x + point2.x) / 2.0, (point1.y + point2.y) / 2.0

@staticmethod
Expand Down Expand Up @@ -280,7 +280,7 @@ def _draw_stop_line(line_segment, label, ax, label_color_val):
ax.plot(px, py, 'o-')
lxy = [random.randint(20, 80) * random.sample([-1, 1], 1)[0],
random.randint(20, 80) * random.sample([-1, 1], 1)[0]]
xy = (sum(px) / len(px), sum(py) / len(py))
xy = (sum(px) // len(px), sum(py) // len(py))
plt.annotate(
label,
xy=xy, xytext=lxy,
Expand Down
2 changes: 1 addition & 1 deletion modules/tools/mapshow/libs/path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2018 The Apollo Authors. All Rights Reserved.
Expand Down
6 changes: 3 additions & 3 deletions modules/tools/mapshow/libs/planning.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand Down Expand Up @@ -109,12 +109,12 @@ def compute_sl_data(self):
sl_sampled_s.append(s)
for l in sl_frame.map_lower_bound:
if (l > 10 or l < -10):
sl_map_lower_boundary.append(100 * l / abs(l))
sl_map_lower_boundary.append(100 * l // abs(l))
else:
sl_map_lower_boundary.append(l)
for l in sl_frame.map_upper_bound:
if (l > 10 or l < -10):
sl_map_upper_boundary.append(100 * l / abs(l))
sl_map_upper_boundary.append(100 * l // abs(l))
else:
sl_map_upper_boundary.append(l)
for l in sl_frame.static_obstacle_lower_bound:
Expand Down
16 changes: 8 additions & 8 deletions modules/tools/mapshow/libs/plot_planning.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand All @@ -21,13 +21,13 @@
import matplotlib.animation as animation
from cyber_py import cyber
from modules.planning.proto import planning_pb2
from subplot_st_main import StMainSubplot
from subplot_path import PathSubplot
from subplot_sl_main import SlMainSubplot
from subplot_st_speed import StSpeedSubplot
from subplot_speed import SpeedSubplot
from localization import Localization
from planning import Planning
from .subplot_st_main import StMainSubplot
from .subplot_path import PathSubplot
from .subplot_sl_main import SlMainSubplot
from .subplot_st_speed import StSpeedSubplot
from .subplot_speed import SpeedSubplot
from .localization import Localization
from .planning import Planning

planning = Planning()
localization = Localization()
Expand Down
10 changes: 5 additions & 5 deletions modules/tools/mapshow/libs/plot_smoothness.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand All @@ -19,11 +19,11 @@
from cyber_py import cyber
from modules.planning.proto import planning_pb2
import matplotlib.pyplot as plt
from planning import Planning
from .planning import Planning
import matplotlib.animation as animation
from subplot_traj_speed import TrajSpeedSubplot
from subplot_traj_acc import TrajAccSubplot
from subplot_traj_path import TrajPathSubplot
from .subplot_traj_speed import TrajSpeedSubplot
from .subplot_traj_acc import TrajAccSubplot
from .subplot_traj_path import TrajPathSubplot

planning = Planning()

Expand Down
8 changes: 4 additions & 4 deletions modules/tools/mapshow/libs/plot_st.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand All @@ -17,11 +17,11 @@
###############################################################################

from cyber_py import cyber
from planning import Planning
from .planning import Planning
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from subplot_st_main import StMainSubplot
from subplot_st_speed import StSpeedSubplot
from .subplot_st_main import StMainSubplot
from .subplot_st_speed import StSpeedSubplot
from modules.planning.proto import planning_pb2

planning = Planning()
Expand Down
4 changes: 2 additions & 2 deletions modules/tools/mapshow/libs/subplot_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
Expand All @@ -16,7 +16,7 @@
# limitations under the License.
###############################################################################

from map import Map
from .map import Map


class PathSubplot:
Expand Down
Loading

0 comments on commit 2a65a24

Please sign in to comment.