blob: d7d7b055fe56fda20c4c3ac27c956de27ea161b4 [file] [log] [blame]
# Copyright (c) 2011 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.
"""Module containing methods and classes to interact with a devserver instance.
import os
import threading
import cros_build_lib as cros_lib
def GenerateUpdateId(target, src, key):
"""Returns a simple representation id of target and src paths."""
update_id = target
if src: update_id = '->'.join([src, update_id])
if key: update_id = '+'.join([update_id, key])
return update_id
class DevServerWrapper(threading.Thread):
"""A Simple wrapper around a dev server instance."""
def __init__(self, test_root):
self.proc = None
self.test_root = test_root
def run(self):
# Kill previous running instance of devserver if it exists.
cros_lib.RunCommand(['sudo', 'pkill', '-f', ''], error_ok=True,
], enter_chroot=True, print_cmd=False,
def Stop(self):
"""Kills the devserver instance."""
cros_lib.RunCommand(['sudo', 'pkill', '-f', ''], error_ok=True,
def GetDevServerURL(cls, port, sub_dir):
"""Returns the dev server url for a given port and sub directory."""
ip_addr = cros_lib.GetIPAddress()
if not port: port = 8080
url = 'http://%(ip)s:%(port)s/%(dir)s' % {'ip': ip_addr,
'port': str(port),
'dir': sub_dir}
return url