Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iio_info.py: update to black and fix pylint issues #504

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prospector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ pep257:
disable: [
D203, # 1 blank line required before class docstring
# conflicts with D0211, No blank lines allowed before class docstring
D402, # First line should not be the function's "signature"
# conflicts with D213, Multi-line docstring summary should start at the second line
]
149 changes: 79 additions & 70 deletions bindings/python/examples/iio_info.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,102 @@
#!/usr/bin/env python
#
# Copyright (C) 2015 Analog Devices, Inc.
# Author: Paul Cercueil <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
Copyright (C) 2015 Analog Devices, Inc.
Author: Paul Cercueil <[email protected]>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""

import iio
from sys import argv
import iio


def main():
print('Library version: %u.%u (git tag: %s)' % iio.version)
"""
Dump iio devices, list all iio attributes.
"""
print("Library version: %u.%u (git tag: %s)" % iio.version)

if len(argv) == 3 and argv[1] == "--uri":
uri = argv[2]
else:
contexts = iio.scan_contexts()
if len(contexts) > 1:
print("Multiple contexts found. Please select one using --uri:")
for index, each in enumerate(contexts):
print("\t%d: %s [%s]" % (index, contexts[each], each))
return

if len(argv) == 3 and argv[1] == '--uri':
uri = argv[2]
else:
contexts = iio.scan_contexts()
if len(contexts) > 1:
print('Multiple contexts found. Please select one using --uri:')
for index, each in enumerate(contexts):
print('\t%d: %s [%s]' % (index, contexts[each], each))
return
uri = next(iter(contexts), None)

uri = next(iter(contexts), None)
ctx = iio.Context(uri)

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

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

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

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

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

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

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

print('\t\t%u channels found:' % len(dev.channels))
for chn in dev.channels:
print(
"\t\t\t%s: %s (%s)"
% (chn.id, chn.name or "", "output" if chn.output else "input")
)

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

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

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

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

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

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

for attr in dev.debug_attrs:
try:
print('\t\t\t' + attr + ', value: ' + dev.debug_attrs[attr].value)
except OSError as e:
print('Unable to read ' + attr + ': ' + e.strerror)

if __name__ == '__main__':
main()
if __name__ == "__main__":
main()