#!/usr/bin/env python # # Copyright 2016 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Script functions as a web app and wrapper for the cras_router program.""" import re import subprocess import logging import cherrypy # Node Format: [Stable_Id, ID, Vol, Plugged, L/R_swapped, Time, Type, Name] ID_INDEX = 1 PLUGGED_INDEX = 3 TYPE_INDEX = 6 NAME_INDEX = 7 def get_plugged_nodes(plugged_nodes, lines, is_input): start_str = 'Input Nodes:' if is_input else 'Output Nodes:' end_str = 'Attached clients:' if is_input else 'Input Devices:' for i in range(lines.index(start_str) + 2, lines.index(end_str)): node = filter(None, re.split(r'\s+|\*+', lines[i])) # check for nodes that are plugged nodes and loopback if node[PLUGGED_INDEX] == 'yes' and node[TYPE_INDEX][:4] != 'POST': key = node[TYPE_INDEX] + ' ' + node[NAME_INDEX] plugged_nodes[key] = node[ID_INDEX] class CrasRouterTest(object): """Cherrypy class that builds and runs the HTML for audio testing tool.""" @cherrypy.expose def index(self): """Builds up and displays the html for the audio testing tool. Returns: html that was built up based on plugged audio devices. """ # Stop program if currently being run. if 'process' in cherrypy.session: print 'Existing process' # If return code is None process is still running if cherrypy.session['process'].poll() is None: print 'Killing existing process' cherrypy.session['process'].kill() else: print 'Process already finished' html = """