Skip to content

Commit 3a494ba

Browse files
committed
fix list method
1 parent 7958f17 commit 3a494ba

File tree

1 file changed

+40
-45
lines changed

1 file changed

+40
-45
lines changed

roboticstoolbox/models/list.py

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def list(keywords=None, dof=None, mtype=None):
3434
# module = importlib.import_module(
3535
# '.' + os.path.splitext(file)[0], package='bdsim.blocks')
3636

37-
try:
37+
def make_table(border):
3838
table = ANSITable(
3939
Column("class", headalign="^", colalign="<"),
4040
Column("model", headalign="^", colalign="<"),
@@ -45,51 +45,46 @@ def list(keywords=None, dof=None, mtype=None):
4545
Column("keywords", headalign="^", colalign="<"),
4646
border="thin"
4747
)
48-
except UnicodeEncodeError:
49-
table = ANSITable(
50-
Column("class", headalign="^", colalign="<"),
51-
Column("model", headalign="^", colalign="<"),
52-
Column("manufacturer", headalign="^", colalign="<"),
53-
Column("model type", headalign="^", colalign="<"),
54-
Column("DoF", colalign="<"),
55-
Column("config", colalign="<"),
56-
Column("keywords", headalign="^", colalign="<"),
57-
border="ascii"
58-
)
5948

60-
if mtype is not None:
61-
categories = [mtype]
62-
else:
63-
categories = ['DH', 'URDF', 'ETS']
64-
for category in categories:
65-
group = m.__dict__[category]
66-
for cls in group.__dict__.values():
67-
if isinstance(cls, type) and issubclass(cls, Robot):
68-
# we found a Robot subclass, instantiate it
69-
robot = cls()
70-
try:
71-
config = robot.config()
72-
except Exception: # pragma nocover
73-
config = ""
74-
75-
# apply filters
76-
if keywords is not None:
77-
if len(set(keywords) & set(robot.keywords)) == 0:
78-
continue
79-
if dof is not None and robot.n != dof:
80-
continue # pragma nocover
81-
82-
# add the row
83-
table.row(
84-
cls.__name__,
85-
robot.name,
86-
robot.manufacturer,
87-
category,
88-
robot.n,
89-
config,
90-
', '.join(robot.keywords)
91-
)
92-
print(str(table).encode('utf8', errors='replace').decode('utf8'))
49+
if mtype is not None:
50+
categories = [mtype]
51+
else:
52+
categories = ['DH', 'URDF', 'ETS']
53+
for category in categories:
54+
group = m.__dict__[category]
55+
for cls in group.__dict__.values():
56+
if isinstance(cls, type) and issubclass(cls, Robot):
57+
# we found a Robot subclass, instantiate it
58+
robot = cls()
59+
try:
60+
config = robot.config()
61+
except Exception: # pragma nocover
62+
config = ""
63+
64+
# apply filters
65+
if keywords is not None:
66+
if len(set(keywords) & set(robot.keywords)) == 0:
67+
continue
68+
if dof is not None and robot.n != dof:
69+
continue # pragma nocover
70+
71+
# add the row
72+
table.row(
73+
cls.__name__,
74+
robot.name,
75+
robot.manufacturer,
76+
category,
77+
robot.n,
78+
config,
79+
', '.join(robot.keywords)
80+
)
81+
82+
print(str(table).encode('utf8', errors='replace').decode('utf8'))
83+
84+
try:
85+
make_table('thin')
86+
except UnicodeEncodeError:
87+
make_table('ascii')
9388

9489

9590
if __name__ == "__main__": # pragma nocover

0 commit comments

Comments
 (0)