Skip to content

Commit 008a099

Browse files
committed
iio_info.py: update to black and fix pylint issues
convert tabs to spaces run black fix pylint issues - variable name too short - import order - docstring missing run black again Signed-off-by: Robin Getz <[email protected]>
1 parent c7d589f commit 008a099

File tree

1 file changed

+79
-70
lines changed

1 file changed

+79
-70
lines changed
Lines changed: 79 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,102 @@
11
#!/usr/bin/env python
2-
#
3-
# Copyright (C) 2015 Analog Devices, Inc.
4-
# Author: Paul Cercueil <[email protected]>
5-
#
6-
# This program is free software; you can redistribute it and/or
7-
# modify it under the terms of the GNU General Public License
8-
# as published by the Free Software Foundation; either version 2
9-
# of the License, or (at your option) any later version.
10-
#
11-
# This program is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU General Public License for more details.
15-
#
16-
# You should have received a copy of the GNU General Public License
17-
# along with this program; if not, write to the Free Software
18-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2+
"""
3+
Copyright (C) 2015 Analog Devices, Inc.
4+
Author: Paul Cercueil <[email protected]>
5+
6+
This program is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU General Public License
8+
as published by the Free Software Foundation; either version 2
9+
of the License, or (at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
"""
1920

20-
import iio
2121
from sys import argv
22+
import iio
23+
2224

2325
def main():
24-
print('Library version: %u.%u (git tag: %s)' % iio.version)
26+
"""
27+
Dump iio devices, list all iio attributes.
28+
"""
29+
print("Library version: %u.%u (git tag: %s)" % iio.version)
30+
31+
if len(argv) == 3 and argv[1] == "--uri":
32+
uri = argv[2]
33+
else:
34+
contexts = iio.scan_contexts()
35+
if len(contexts) > 1:
36+
print("Multiple contexts found. Please select one using --uri:")
37+
for index, each in enumerate(contexts):
38+
print("\t%d: %s [%s]" % (index, contexts[each], each))
39+
return
2540

26-
if len(argv) == 3 and argv[1] == '--uri':
27-
uri = argv[2]
28-
else:
29-
contexts = iio.scan_contexts()
30-
if len(contexts) > 1:
31-
print('Multiple contexts found. Please select one using --uri:')
32-
for index, each in enumerate(contexts):
33-
print('\t%d: %s [%s]' % (index, contexts[each], each))
34-
return
41+
uri = next(iter(contexts), None)
3542

36-
uri = next(iter(contexts), None)
43+
ctx = iio.Context(uri)
3744

38-
ctx = iio.Context(uri)
45+
if uri is not None:
46+
print('Using auto-detected IIO context at URI "%s"' % uri)
3947

40-
if uri is not None:
41-
print('Using auto-detected IIO context at URI \"%s\"' % uri)
48+
print("IIO context created: " + ctx.name)
49+
print("Backend version: %u.%u (git tag: %s)" % ctx.version)
50+
print("Backend description string: " + ctx.description)
4251

43-
print('IIO context created: ' + ctx.name)
44-
print('Backend version: %u.%u (git tag: %s)' % ctx.version)
45-
print('Backend description string: ' + ctx.description)
52+
if len(ctx.attrs) > 0:
53+
print("IIO context has %u attributes:" % len(ctx.attrs))
54+
for attr, value in ctx.attrs.items():
55+
print("\t" + attr + ": " + value)
4656

47-
if len(ctx.attrs) > 0:
48-
print('IIO context has %u attributes:' % len(ctx.attrs))
49-
for attr, value in ctx.attrs.items():
50-
print('\t' + attr + ': ' + value)
57+
print("IIO context has %u devices:" % len(ctx.devices))
5158

52-
print('IIO context has %u devices:' % len(ctx.devices))
59+
for dev in ctx.devices:
60+
print("\t" + dev.id + ": " + dev.name)
5361

54-
for dev in ctx.devices:
55-
print('\t' + dev.id + ': ' + dev.name)
62+
if dev is iio.Trigger:
63+
print("Found trigger! Rate: %u Hz" % dev.frequency)
5664

57-
if dev is iio.Trigger:
58-
print('Found trigger! Rate: %u Hz' % dev.frequency)
65+
print("\t\t%u channels found:" % len(dev.channels))
5966

60-
print('\t\t%u channels found:' % len(dev.channels))
67+
for chn in dev.channels:
68+
print(
69+
"\t\t\t%s: %s (%s)"
70+
% (chn.id, chn.name or "", "output" if chn.output else "input")
71+
)
6172

62-
for chn in dev.channels:
63-
print('\t\t\t%s: %s (%s)' % (chn.id, chn.name or "", 'output' if chn.output else 'input'))
73+
if len(chn.attrs) != 0:
74+
print("\t\t\t%u channel-specific attributes found:" % len(chn.attrs))
6475

65-
if len(chn.attrs) != 0:
66-
print('\t\t\t%u channel-specific attributes found:' % len(chn.attrs))
76+
for attr in chn.attrs:
77+
try:
78+
print("\t\t\t\t" + attr + ", value: " + chn.attrs[attr].value)
79+
except OSError as err:
80+
print("Unable to read " + attr + ": " + err.strerror)
6781

68-
for attr in chn.attrs:
69-
try:
70-
print('\t\t\t\t' + attr + ', value: ' + chn.attrs[attr].value)
71-
except OSError as e:
72-
print('Unable to read ' + attr + ': ' + e.strerror)
82+
if len(dev.attrs) != 0:
83+
print("\t\t%u device-specific attributes found:" % len(dev.attrs))
7384

74-
if len(dev.attrs) != 0:
75-
print('\t\t%u device-specific attributes found:' % len(dev.attrs))
85+
for attr in dev.attrs:
86+
try:
87+
print("\t\t\t" + attr + ", value: " + dev.attrs[attr].value)
88+
except OSError as err:
89+
print("Unable to read " + attr + ": " + err.strerror)
7690

77-
for attr in dev.attrs:
78-
try:
79-
print('\t\t\t' + attr + ', value: ' + dev.attrs[attr].value)
80-
except OSError as e:
81-
print('Unable to read ' + attr + ': ' + e.strerror)
91+
if len(dev.debug_attrs) != 0:
92+
print("\t\t%u debug attributes found:" % len(dev.debug_attrs))
8293

83-
if len(dev.debug_attrs) != 0:
84-
print('\t\t%u debug attributes found:' % len(dev.debug_attrs))
94+
for attr in dev.debug_attrs:
95+
try:
96+
print("\t\t\t" + attr + ", value: " + dev.debug_attrs[attr].value)
97+
except OSError as err:
98+
print("Unable to read " + attr + ": " + err.strerror)
8599

86-
for attr in dev.debug_attrs:
87-
try:
88-
print('\t\t\t' + attr + ', value: ' + dev.debug_attrs[attr].value)
89-
except OSError as e:
90-
print('Unable to read ' + attr + ': ' + e.strerror)
91100

92-
if __name__ == '__main__':
93-
main()
101+
if __name__ == "__main__":
102+
main()

0 commit comments

Comments
 (0)