list-ports.py 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. # PYTHON_ARGCOMPLETE_OK
  3. import sys
  4. import jack
  5. import time
  6. import pprint
  7. import argparse
  8. def run():
  9. client = jack.Client("list ports example");
  10. for port in client.get_ports():
  11. print port.get_name()
  12. print '\tclient: ' + port.get_client_name()
  13. print '\tshort: ' + port.get_short_name()
  14. for alias in port.get_aliases():
  15. print '\talias: ' + alias
  16. print '\ttype: %s %s' % (
  17. port.get_type(),
  18. 'input' if port.is_input() else ('output' if port.is_output() else ''),
  19. )
  20. def _init_argparser():
  21. argparser = argparse.ArgumentParser(description = None)
  22. return argparser
  23. def main(argv):
  24. argparser = _init_argparser()
  25. try:
  26. import argcomplete
  27. argcomplete.autocomplete(argparser)
  28. except ImportError:
  29. pass
  30. args = argparser.parse_args(argv)
  31. run(**vars(args))
  32. return 0
  33. if __name__ == "__main__":
  34. sys.exit(main(sys.argv[1:]))