| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Module containing methods and classes to interact with a devserver instance. | |
| 6 """ | |
| 7 | |
| 8 import os | |
| 9 import threading | |
| 10 | |
| 11 import cros_build_lib as cros_lib | |
| 12 | |
| 13 def GenerateUpdateId(target, src, key): | |
| 14 """Returns a simple representation id of target and src paths.""" | |
| 15 update_id = target | |
| 16 if src: update_id = '->'.join([src, update_id]) | |
| 17 if key: update_id = '+'.join([update_id, key]) | |
| 18 return update_id | |
| 19 | |
| 20 class DevServerWrapper(threading.Thread): | |
| 21 """A Simple wrapper around a dev server instance.""" | |
| 22 | |
| 23 def __init__(self, test_root): | |
| 24 self.proc = None | |
| 25 self.test_root = test_root | |
| 26 threading.Thread.__init__(self) | |
| 27 | |
| 28 def run(self): | |
| 29 # Kill previous running instance of devserver if it exists. | |
| 30 cros_lib.RunCommand(['sudo', 'pkill', '-f', 'devserver.py'], error_ok=True, | |
| 31 print_cmd=False) | |
| 32 cros_lib.RunCommand(['sudo', | |
| 33 'start_devserver', | |
| 34 '--archive_dir=./static', | |
| 35 '--client_prefix=ChromeOSUpdateEngine', | |
| 36 '--production', | |
| 37 ], enter_chroot=True, print_cmd=False, | |
| 38 log_to_file=os.path.join(self.test_root, | |
| 39 'dev_server.log')) | |
| 40 | |
| 41 def Stop(self): | |
| 42 """Kills the devserver instance.""" | |
| 43 cros_lib.RunCommand(['sudo', 'pkill', '-f', 'devserver.py'], error_ok=True, | |
| 44 print_cmd=False) | |
| 45 | |
| 46 @classmethod | |
| 47 def GetDevServerURL(cls, port, sub_dir): | |
| 48 """Returns the dev server url for a given port and sub directory.""" | |
| 49 ip_addr = cros_lib.GetIPAddress() | |
| 50 if not port: port = 8080 | |
| 51 url = 'http://%(ip)s:%(port)s/%(dir)s' % {'ip': ip_addr, | |
| 52 'port': str(port), | |
| 53 'dir': sub_dir} | |
| 54 return url | |
| OLD | NEW |