1 #!/usr/bin/env python 2 # 3 # Copyright (C) 2012 The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the 'License'); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an 'AS IS' BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 18 #detect USB sound card from sound card lists under sys/class/sound/soundX 19 20 import os, re, sys 21 22 AUDIO_CLASS_DIR = "/sys/class/sound" 23 24 def main(argv): 25 if len(argv) < 2: 26 print "Usage: detect_usb_audio.py (product)+" 27 print " ex: detect_usb_audio.py MobilePre" 28 sys.exit(1) 29 current_argv = 1 30 product_list = [] 31 while current_argv < len(argv): 32 product_list.append(argv[current_argv]) 33 current_argv = current_argv + 1 34 #print product_list 35 sound_dev_list = os.listdir(AUDIO_CLASS_DIR) 36 for sound_dev in sound_dev_list: 37 m = re.search("card(\d+)$", sound_dev) 38 if m != None: 39 card_full_path = os.path.realpath(AUDIO_CLASS_DIR + "/" + sound_dev) 40 if "usb" in card_full_path: 41 f = open(card_full_path + "/id") 42 line = f.readline().strip() 43 if line in product_list: 44 print "___CTS_AUDIO_PASS___ " + line + " " + m.group(1) 45 sys.exit(0) 46 f.close() 47 # card not found 48 sys.exit(1) 49 50 if __name__ == '__main__': 51 main(sys.argv) 52