Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Unified Diff: build/android/pylib/device/decorators.py

Issue 265743002: [Android] Switch to new interfaces of GetAVDs and RestartAdbServer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/device/adb_wrapper_test.py ('k') | build/android/pylib/device/decorators_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/decorators.py
diff --git a/build/android/pylib/device/decorators.py b/build/android/pylib/device/decorators.py
new file mode 100644
index 0000000000000000000000000000000000000000..29e46ff18b9fadc2e96a398c9e7c0a3e108678fe
--- /dev/null
+++ b/build/android/pylib/device/decorators.py
@@ -0,0 +1,71 @@
+# 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.
+
+"""
+Function/method decorators that provide timeout and retry logic.
+"""
+
+import functools
+
+from pylib.device import device_errors
+from pylib.utils import reraiser_thread
+from pylib.utils import timeout_retry
+
+
+def _TimeoutRetryWrapper(f, timeout_func, retries_func):
+ @functools.wraps(f)
+ def TimeoutRetryWrapper(*args, **kwargs):
+ timeout = timeout_func(*args, **kwargs)
+ retries = retries_func(*args, **kwargs)
+ def impl():
+ return f(*args, **kwargs)
+ try:
+ return timeout_retry.Run(impl, timeout, retries)
+ except reraiser_thread.TimeoutError as e:
+ raise device_errors.CommandTimeoutError(str(e))
+ return TimeoutRetryWrapper
+
+
+def WithTimeoutAndRetries(f):
+ """A decorator that handles timeouts and retries."""
+ get_timeout = lambda *a, **kw: kw['timeout']
+ get_retries = lambda *a, **kw: kw['retries']
+ return _TimeoutRetryWrapper(f, get_timeout, get_retries)
+
+
+def WithExplicitTimeoutAndRetries(timeout, retries):
+ """
+ A decorator that handles timeouts and retries using the provided values.
+ """
+ def decorator(f):
+ get_timeout = lambda *a, **kw: timeout
+ get_retries = lambda *a, **kw: retries
+ return _TimeoutRetryWrapper(f, get_timeout, get_retries)
+ return decorator
+
+
+def WithTimeoutAndRetriesDefaults(default_timeout, default_retries):
+ """
+ A decorator that handles timeouts and retries using the provided defaults.
+ """
+ def decorator(f):
+ get_timeout = lambda *a, **kw: kw.get('timeout', default_timeout)
+ get_retries = lambda *a, **kw: kw.get('retries', default_retries)
+ return _TimeoutRetryWrapper(f, get_timeout, get_retries)
+ return decorator
+
+
+def WithTimeoutAndRetriesFromInstance(
+ default_timeout_name, default_retries_name):
+ """
+ A decorator that handles timeouts and retries using instance defaults.
+ """
+ def decorator(f):
+ def get_timeout(inst, *_args, **kwargs):
+ return kwargs.get('timeout', getattr(inst, default_timeout_name))
+ def get_retries(inst, *_args, **kwargs):
+ return kwargs.get('retries', getattr(inst, default_retries_name))
+ return _TimeoutRetryWrapper(f, get_timeout, get_retries)
+ return decorator
+
« no previous file with comments | « build/android/pylib/device/adb_wrapper_test.py ('k') | build/android/pylib/device/decorators_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698