Skip to content

Commit

Permalink
Merge pull request #973 from aginika/add-expect-num-of-usb
Browse files Browse the repository at this point in the history
add expect of usb to check
  • Loading branch information
k-okada committed Jun 3, 2015
2 parents 5cbaf0a + 5181a39 commit 341c0e3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions jsk_tools/src/jsk_tools/sanity_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,27 @@ def checkNodeState(target_node_name, needed, sub_success="", sub_fail=""):
if sub_success:
print Fore.GREEN+" "+sub_success+ Fore.RESET

def checkUSBExist(vendor_id, product_id, success_msg = "", error_msg = ""):
def checkUSBExist(vendor_id, product_id, expect_usb_nums = 1, success_msg = "", error_msg = ""):
"""check USB Exists
vendor_string -- vendor string (e.g. if 8087:0024, 8087)
product_string -- product string (e.g. if 8087:0024, 0024)
expect_usb_nums -- number of usbs (default is 1)
"""
output_lines = subprocess.check_output("lsusb", shell=True).split("\n")
vendor_product = str(vendor_id) + ":" + str(product_id)
usb_counter = 0
for output in output_lines:
if vendor_product in output:
okMessage(vendor_product + " " + success_msg if success_msg else vendor_product + " Found")
return True
usb_counter += 1
if usb_counter >= expect_usb_nums:
okMessage(vendor_product + " " + success_msg if success_msg else vendor_product + " Found enough ( "+str(usb_counter)+"/"+str(expect_usb_nums)+" ) Detected")
return True
elif usb_counter == 0:
errorMessage(vendor_product + " " + error_msg if error_msg else vendor_product + " NOT Found !! ( 0 / " + str(expect_usb_nums) + " ) Detected")
return False
else:
errorMessage(vendor_product + " " + error_msg if error_msg else vendor_product + " NOT Found !!")
errorMessage(vendor_product + " " + error_msg if error_msg else vendor_product + " IS FEW !! Only ( "+str(usb_counter)+"/"+str(expect_usb_nums)+" ) Detected")
return False

def checkROSMasterCLOSE_WAIT(host, username=""):
Expand Down

0 comments on commit 341c0e3

Please sign in to comment.