File tree 1 file changed +27
-0
lines changed 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -215,6 +215,33 @@ def from_adb_output(line):
215
215
216
216
return AdbDevice (serial , type , ** kwargs )
217
217
218
+ def __wrapped (self , function ):
219
+ """Wrapps a callable in a scope which selects the current device."""
220
+ @functools .wraps (function )
221
+ def wrapper (* a , ** kw ):
222
+ with context .local (device = self ):
223
+ return function (* a ,** kw )
224
+ return wrapper
225
+
226
+ def __getattr__ (self , name ):
227
+ """Provides scoped access to ``adb`` module propertise, in the context
228
+ of this device.
229
+
230
+ >>> property = 'ro.build.fingerprint'
231
+ >>> device = adb.current_device()
232
+ >>> adb.getprop(property) == device.getprop(property)
233
+ True
234
+ """
235
+ with context .local (device = self ):
236
+ g = globals ()
237
+
238
+ if name not in g :
239
+ return super (AdbDevice , self ).__getattr__ (name )
240
+
241
+ value = g [name ]
242
+
243
+ return self .__wrapped (value )
244
+
218
245
@LocalContext
219
246
def wait_for_device (kick = False ):
220
247
"""Waits for a device to be connected.
You can’t perform that action at this time.
0 commit comments