Make app list recommendations ignore KnownResults.
[chromium-blink-merge.git] / testing / legion / rpc_methods.py
blob95da9ef558140189c78b7918c15b95990a1c51f1
1 # Copyright 2015 The Chromium 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.
5 """Defines the task RPC methods."""
7 import logging
8 import os
9 import platform
10 import socket
11 import sys
12 import threading
14 #pylint: disable=relative-import
15 import common_lib
16 import process
19 class RPCMethods(object):
20 """Class exposing RPC methods."""
22 _dotted_whitelist = ['subprocess']
24 def __init__(self, server):
25 self._server = server
26 self.subprocess = process.Process
28 def _dispatch(self, method, params):
29 obj = self
30 if '.' in method:
31 # Allow only white listed dotted names
32 name, method = method.split('.')
33 assert name in self._dotted_whitelist
34 obj = getattr(self, name)
35 return getattr(obj, method)(*params)
37 def Echo(self, message):
38 """Simple RPC method to print and return a message."""
39 logging.info('Echoing %s', message)
40 return 'echo %s' % str(message)
42 def AbsPath(self, path):
43 """Returns the absolute path."""
44 return os.path.abspath(path)
46 def Quit(self):
47 """Call _server.shutdown in another thread.
49 This is needed because server.shutdown waits for the server to actually
50 quit. However the server cannot shutdown until it completes handling this
51 call. Calling this in the same thread results in a deadlock.
52 """
53 t = threading.Thread(target=self._server.shutdown)
54 t.start()
56 def GetOutputDir(self):
57 """Returns the isolated output directory on the task machine."""
58 return common_lib.GetOutputDir()
60 def WriteFile(self, path, text, mode='wb+'):
61 """Writes a file on the task machine."""
62 with open(path, mode) as fh:
63 fh.write(text)
65 def ReadFile(self, path, mode='rb'):
66 """Reads a file from the local task machine."""
67 with open(path, mode) as fh:
68 return fh.read()
70 def PathJoin(self, *parts):
71 """Performs an os.path.join on the task machine.
73 This is needed due to the fact that there is no guarantee that os.sep will
74 be the same across all machines in a particular test. This method will
75 join the path parts locally to ensure the correct separator is used.
76 """
77 return os.path.join(*parts)
79 def ListDir(self, path):
80 """Returns the results of os.listdir."""
81 return os.listdir(path)
83 def GetIpAddress(self):
84 """Returns the local IPv4 address."""
85 return socket.gethostbyname(socket.gethostname())
87 def GetHostname(self):
88 """Returns the hostname."""
89 return socket.gethostname()
91 def GetPlatform(self):
92 """Returns the value of platform.platform()."""
93 return platform.platform()
95 def GetExecutable(self):
96 """Returns the value of sys.executable."""
97 return sys.executable
99 def GetCwd(self):
100 """Returns the value of os.getcwd()."""
101 return os.getcwd()