Change in osmo-gsm-tester[master]: utils: Introduce show_usb_device.py

2018-10-31 Thread Pau Espin Pedrol
Pau Espin Pedrol has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/11460 )

Change subject: utils: Introduce show_usb_device.py
..

utils: Introduce show_usb_device.py

This is a small script written by Alexander Couzens that is useful to
list modems and its properties in a quick and easy way in
osmo-gsm-tester setup.

Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
---
A utils/show_usb_device.py
1 file changed, 97 insertions(+), 0 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/utils/show_usb_device.py b/utils/show_usb_device.py
new file mode 100755
index 000..9136234
--- /dev/null
+++ b/utils/show_usb_device.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python3
+# Alexander Couzens 
+# MIT
+
+# show usb device with their net and serial devices
+
+import os
+import usb.core
+import usb.util
+from pprint import pprint
+
+def get_path_ids(bus, port_numbers):
+port_numbers = [str(port) for port in port_numbers]
+ports = '.'.join(port_numbers)
+return '{}-{}'.format(bus, ports)
+
+def get_usb_dir(bus, port_numbers):
+return '/sys/bus/usb/devices/' + get_path_ids(bus, port_numbers) + '/'
+
+def get_usbmisc_from_usb(bus, port_numbers):
+usbmisc_ifaces = []
+path = get_usb_dir(bus, port_numbers)
+path_ids = get_path_ids(bus, port_numbers)
+
+usb_interfaces = [f for f in os.listdir(path) if f.startswith(path_ids)]
+for usb_iface in usb_interfaces:
+listdir = [f for f in os.listdir(path + usb_iface) if f == ('usbmisc')]
+if listdir:
+# found a net iface
+usbmisc_ifaces += os.listdir(path + usb_iface + '/usbmisc/')
+return usbmisc_ifaces
+
+def get_net_from_usb(bus, port_numbers):
+net_ifaces = []
+path = get_usb_dir(bus, port_numbers)
+path_ids = get_path_ids(bus, port_numbers)
+
+usb_interfaces = [f for f in os.listdir(path) if f.startswith(path_ids)]
+for usb_iface in usb_interfaces:
+listdir = [f for f in os.listdir(path + usb_iface) if f == ('net')]
+if listdir:
+# found a net iface
+net_ifaces += os.listdir(path + usb_iface + '/net/')
+return net_ifaces
+
+def get_serial_from_usb(bus, port_numbers):
+serial_ifaces = []
+path = get_usb_dir(bus, port_numbers)
+path_ids = get_path_ids(bus, port_numbers)
+
+usb_interfaces = [f for f in os.listdir(path) if f.startswith(path_ids)]
+for usb_iface in usb_interfaces:
+serial_ifaces += [f for f in os.listdir(path + usb_iface) if 
f.startswith('tty')]
+return serial_ifaces
+
+def get_product(bus, port_numbers):
+usb_dir = get_usb_dir(bus, port_numbers)
+try:
+product = open(os.path.join(usb_dir, 'product')).read().strip()
+except OSError as exp:
+product = "Unknown"
+return product
+
+def get_manuf(bus, port_numbers):
+usb_dir = get_usb_dir(bus, port_numbers)
+try:
+manuf = open(os.path.join(usb_dir, 'manufacturer')).read().strip()
+except OSError:
+manuf = "Unknown"
+return manuf
+
+def get_name(bus, port_numbers):
+manuf = get_manuf(bus, port_numbers)
+product = get_product(bus, port_numbers)
+return "%s %s" % (manuf, product)
+
+if __name__ == '__main__':
+USB_DEVS = [dev for dev in usb.core.find(find_all=True)]
+RESULT = {}
+for device in USB_DEVS:
+result = {}
+if not device.port_numbers:
+continue
+
+# retrieve manuf + product from /sys because non-root user can not ask 
the usb device
+result['name'] = get_name(device.bus, device.port_numbers)
+result['path'] = get_usb_dir(device.bus, device.port_numbers)
+result['net'] = get_net_from_usb(device.bus, device.port_numbers)
+result['cdc'] = get_usbmisc_from_usb(device.bus, device.port_numbers)
+result['serial'] = get_serial_from_usb(device.bus, device.port_numbers)
+
+# only show device which have serial or net devices
+if result['net'] or result['serial']:
+RESULT[device] = result
+
+pprint(RESULT)
+

--
To view, visit https://gerrit.osmocom.org/11460
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
Gerrit-Change-Number: 11460
Gerrit-PatchSet: 4
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: lynxis lazus 


Change in osmo-gsm-tester[master]: utils: Introduce show_usb_device.py

2018-10-30 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/11460 )

Change subject: utils: Introduce show_usb_device.py
..


Patch Set 3: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/11460
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
Gerrit-Change-Number: 11460
Gerrit-PatchSet: 3
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: lynxis lazus 
Gerrit-Comment-Date: Tue, 30 Oct 2018 21:17:43 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in osmo-gsm-tester[master]: utils: Introduce show_usb_device.py

2018-10-30 Thread Pau Espin Pedrol
Pau Espin Pedrol has posted comments on this change. ( 
https://gerrit.osmocom.org/11460 )

Change subject: utils: Introduce show_usb_device.py
..


Patch Set 3:

I changed the Author of this commit as requested, so I guess it can be +1 or +2 
now.


--
To view, visit https://gerrit.osmocom.org/11460
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
Gerrit-Change-Number: 11460
Gerrit-PatchSet: 3
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: lynxis lazus 
Gerrit-Comment-Date: Tue, 30 Oct 2018 12:28:35 +
Gerrit-HasComments: No
Gerrit-HasLabels: No


Change in osmo-gsm-tester[master]: utils: Introduce show_usb_device.py

2018-10-29 Thread Pau Espin Pedrol
Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/11460

to look at the new patch set (#3).

Change subject: utils: Introduce show_usb_device.py
..

utils: Introduce show_usb_device.py

This is a small script written by Alexander Couzens that is useful to
list modems and its properties in a quick and easy way in
osmo-gsm-tester setup.

Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
---
A utils/show_usb_device.py
1 file changed, 97 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester 
refs/changes/60/11460/3
--
To view, visit https://gerrit.osmocom.org/11460
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
Gerrit-Change-Number: 11460
Gerrit-PatchSet: 3
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: lynxis lazus 


Change in osmo-gsm-tester[master]: utils: Introduce show_usb_device.py

2018-10-26 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/11460 )

Change subject: utils: Introduce show_usb_device.py
..


Patch Set 2: Code-Review-1

actually, if it's written by somebody else, please simply use GIT_AUTHOR_EMAIL 
and GIT_AUTHOR_NAME to fix the attribution.  There's only one time to get this 
right, which is in the initial merge. Thanks!


--
To view, visit https://gerrit.osmocom.org/11460
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
Gerrit-Change-Number: 11460
Gerrit-PatchSet: 2
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Fri, 26 Oct 2018 17:50:17 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in osmo-gsm-tester[master]: utils: Introduce show_usb_device.py

2018-10-26 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/11460 )

Change subject: utils: Introduce show_usb_device.py
..


Patch Set 2: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/11460
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
Gerrit-Change-Number: 11460
Gerrit-PatchSet: 2
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Fri, 26 Oct 2018 17:49:31 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in osmo-gsm-tester[master]: utils: Introduce show_usb_device.py

2018-10-26 Thread Pau Espin Pedrol
Pau Espin Pedrol has posted comments on this change. ( 
https://gerrit.osmocom.org/11460 )

Change subject: utils: Introduce show_usb_device.py
..


Set Ready For Review


--
To view, visit https://gerrit.osmocom.org/11460
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
Gerrit-Change-Number: 11460
Gerrit-PatchSet: 2
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Fri, 26 Oct 2018 16:24:24 +
Gerrit-HasComments: No
Gerrit-HasLabels: No


Change in osmo-gsm-tester[master]: utils: Introduce show_usb_device.py

2018-10-25 Thread Pau Espin Pedrol
Pau Espin Pedrol has uploaded this change for review. ( 
https://gerrit.osmocom.org/11460


Change subject: utils: Introduce show_usb_device.py
..

utils: Introduce show_usb_device.py

This is a small script written by Alexander Couzens that is useful to
list modems and its properties in a quick and easy way in
osmo-gsm-tester setup.

Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
---
A utils/show_usb_device.py
1 file changed, 97 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester 
refs/changes/60/11460/1

diff --git a/utils/show_usb_device.py b/utils/show_usb_device.py
new file mode 100755
index 000..9136234
--- /dev/null
+++ b/utils/show_usb_device.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python3
+# Alexander Couzens 
+# MIT
+
+# show usb device with their net and serial devices
+
+import os
+import usb.core
+import usb.util
+from pprint import pprint
+
+def get_path_ids(bus, port_numbers):
+port_numbers = [str(port) for port in port_numbers]
+ports = '.'.join(port_numbers)
+return '{}-{}'.format(bus, ports)
+
+def get_usb_dir(bus, port_numbers):
+return '/sys/bus/usb/devices/' + get_path_ids(bus, port_numbers) + '/'
+
+def get_usbmisc_from_usb(bus, port_numbers):
+usbmisc_ifaces = []
+path = get_usb_dir(bus, port_numbers)
+path_ids = get_path_ids(bus, port_numbers)
+
+usb_interfaces = [f for f in os.listdir(path) if f.startswith(path_ids)]
+for usb_iface in usb_interfaces:
+listdir = [f for f in os.listdir(path + usb_iface) if f == ('usbmisc')]
+if listdir:
+# found a net iface
+usbmisc_ifaces += os.listdir(path + usb_iface + '/usbmisc/')
+return usbmisc_ifaces
+
+def get_net_from_usb(bus, port_numbers):
+net_ifaces = []
+path = get_usb_dir(bus, port_numbers)
+path_ids = get_path_ids(bus, port_numbers)
+
+usb_interfaces = [f for f in os.listdir(path) if f.startswith(path_ids)]
+for usb_iface in usb_interfaces:
+listdir = [f for f in os.listdir(path + usb_iface) if f == ('net')]
+if listdir:
+# found a net iface
+net_ifaces += os.listdir(path + usb_iface + '/net/')
+return net_ifaces
+
+def get_serial_from_usb(bus, port_numbers):
+serial_ifaces = []
+path = get_usb_dir(bus, port_numbers)
+path_ids = get_path_ids(bus, port_numbers)
+
+usb_interfaces = [f for f in os.listdir(path) if f.startswith(path_ids)]
+for usb_iface in usb_interfaces:
+serial_ifaces += [f for f in os.listdir(path + usb_iface) if 
f.startswith('tty')]
+return serial_ifaces
+
+def get_product(bus, port_numbers):
+usb_dir = get_usb_dir(bus, port_numbers)
+try:
+product = open(os.path.join(usb_dir, 'product')).read().strip()
+except OSError as exp:
+product = "Unknown"
+return product
+
+def get_manuf(bus, port_numbers):
+usb_dir = get_usb_dir(bus, port_numbers)
+try:
+manuf = open(os.path.join(usb_dir, 'manufacturer')).read().strip()
+except OSError:
+manuf = "Unknown"
+return manuf
+
+def get_name(bus, port_numbers):
+manuf = get_manuf(bus, port_numbers)
+product = get_product(bus, port_numbers)
+return "%s %s" % (manuf, product)
+
+if __name__ == '__main__':
+USB_DEVS = [dev for dev in usb.core.find(find_all=True)]
+RESULT = {}
+for device in USB_DEVS:
+result = {}
+if not device.port_numbers:
+continue
+
+# retrieve manuf + product from /sys because non-root user can not ask 
the usb device
+result['name'] = get_name(device.bus, device.port_numbers)
+result['path'] = get_usb_dir(device.bus, device.port_numbers)
+result['net'] = get_net_from_usb(device.bus, device.port_numbers)
+result['cdc'] = get_usbmisc_from_usb(device.bus, device.port_numbers)
+result['serial'] = get_serial_from_usb(device.bus, device.port_numbers)
+
+# only show device which have serial or net devices
+if result['net'] or result['serial']:
+RESULT[device] = result
+
+pprint(RESULT)
+

--
To view, visit https://gerrit.osmocom.org/11460
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec049e2d56d61ecd50b65b64d95d69641fa0f8be
Gerrit-Change-Number: 11460
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol