Index: build/android/pylib/base/remote_device_environment.py |
diff --git a/build/android/pylib/base/remote_device_environment.py b/build/android/pylib/base/remote_device_environment.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c40e473c46c69aeabd1477a09719655c0920be4f |
--- /dev/null |
+++ b/build/android/pylib/base/remote_device_environment.py |
@@ -0,0 +1,69 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Environment setup and teardown for remote devices.""" |
+ |
+import os |
+ |
+# TODO(rnephew): Change these when api lands in 3rd party |
+from pylib import appurify_api |
+from pylib import appurify_constants |
+from pylib.base import environment |
+ |
+ |
+class RemoteDeviceEnvironment(environment.Environment): |
+ """An environment for running on remote devics.""" |
+ |
+ def __init__(self, options, error_func): |
+ super(RemoteDeviceEnvironment, self).__init__() |
+ self.options = options |
jbudorick
2014/11/21 00:17:24
Don't copy the whole options object. Store what yo
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ self.error_func = error_func |
jbudorick
2014/11/21 00:17:24
error_func should only be used for options errors.
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ self._devices = '' |
+ self._access_token = '' |
+ |
+ def SetUp(self): |
+ os.environ['APPURIFY_API_PROTO'] = 'http' |
jbudorick
2014/11/21 00:17:25
these should be passable via command line.
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ os.environ['APPURIFY_API_HOST'] = '172.22.21.180' |
+ self.GetAccessToken() |
+ self.GetDeviceList() |
+ |
+ def TearDown(self): |
+ self.RevokeAccessToken() |
+ |
+ def __enter__(self): |
+ self.SetUp() |
+ return self |
+ |
+ def __exit__(self, exc_type, exc_val, exc_tb): |
+ self.TearDown() |
+ |
+ def GetAccessToken(self): |
+ if not self.options.api_key: |
+ self.error_func('Must set api key') |
+ if not self.options.api_secret: |
+ self.error_func('Must set api secret') |
+ access_token_results = appurify_api.access_token_generate( |
+ self.options.api_key, self.options.api_secret) |
+ if access_token_results.status_code != 200: |
+ self.error_func('Unable to generate access token.') |
jbudorick
2014/11/21 00:17:24
Should be an exception -- probably a new exception
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ self._access_token = access_token_results.json()['response']['access_token'] |
+ |
+ def RevokeAccessToken(self): |
+ revoke_token_results = appurify_api.access_token_revoke(self._access_token) |
+ if revoke_token_results.status_code != 200: |
+ self.error_func('Unable to revoke access token.') |
jbudorick
2014/11/21 00:17:24
Same.
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ |
+ def GetDeviceList(self): |
+ dev_list_res = appurify_api.devices_list(self._access_token) |
+ if dev_list_res.status_code != 200: |
+ self.error_func('Unable to get device list.') |
jbudorick
2014/11/21 00:17:24
Same.
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ self._devices = dev_list_res.json()['response'] |
+ |
+ @property |
+ def devices(self): |
+ return self._devices |
+ |
+ @property |
+ def token(self): |
+ return self._access_token |