1"""Provides utilities to support bluetooth adapter tests""" 2 3from debug_linux_keymap import linux_input_keymap 4 5from autotest_lib.client.bin.input.linux_input import EV_KEY 6from ast import literal_eval as make_tuple 7import logging 8 9 10def reconstruct_string(events): 11 """ Tries to reconstruct a string from linux input in a simple way 12 13 @param events: list of event objects received over the BT channel 14 15 @returns: reconstructed string 16 """ 17 recon = [] 18 19 for ev in events: 20 # If it's a key pressed event 21 if ev.type == EV_KEY and ev.value == 1: 22 recon.append(linux_input_keymap.get(ev.code, "_")) 23 24 return "".join(recon) 25 26 27def parse_trace_file(filename): 28 """ Reads contents of trace file 29 30 @param filename: location of trace file on disk 31 32 @returns: structure containing contents of filename 33 """ 34 35 contents = [] 36 37 try: 38 with open(filename, 'r') as mf: 39 for line in mf: 40 # Reconstruct tuple and add to trace 41 contents.append(make_tuple(line)) 42 except EnvironmentError: 43 logging.error('Unable to open file %s', filename) 44 return None 45 46 return contents