Skip to content

Commit

Permalink
Clean up adb_manager.py
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Nov 10, 2019
1 parent a996e7c commit ee7f978
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions androidtv/adb_manager.py
Expand Up @@ -133,6 +133,7 @@ def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S)
finally:
self._adb_lock.release()

# Lock could not be acquired
self._available = False
return False

Expand All @@ -151,18 +152,18 @@ def shell(self, cmd):
"""
if not self.available:
_LOGGER.debug("ADB command not sent to %s because python-adb connection is not established: %s", self.host, cmd)
_LOGGER.debug("ADB command not sent to %s because adb-shell connection is not established: %s", self.host, cmd)
return None

if self._adb_lock.acquire(**LOCK_KWARGS): # pylint: disable=unexpected-keyword-arg
_LOGGER.debug("Sending command to %s via python-adb: %s", self.host, cmd)
_LOGGER.debug("Sending command to %s via adb-shell: %s", self.host, cmd)
try:
return self._adb.shell(cmd)
finally:
self._adb_lock.release()
else:
_LOGGER.debug("ADB command not sent to %s because python-adb lock not acquired: %s", self.host, cmd)

# Lock could not be acquired
_LOGGER.debug("ADB command not sent to %s via adb-shell because lock not acquired: %s", self.host, cmd)
return None


Expand Down Expand Up @@ -289,6 +290,7 @@ def connect(self, always_log_errors=True):
finally:
self._adb_lock.release()

# Lock could not be acquired
self._available = False
return False

Expand Down Expand Up @@ -316,7 +318,7 @@ def shell(self, cmd):
return self._adb_device.shell(cmd)
finally:
self._adb_lock.release()
else:
_LOGGER.debug("ADB command not sent to %s via ADB server %s:%s because pure-python-adb lock not acquired: %s", self.host, self.adb_server_ip, self.adb_server_port, cmd)

# Lock could not be acquired
_LOGGER.debug("ADB command not sent to %s via ADB server %s:%s because pure-python-adb lock not acquired: %s", self.host, self.adb_server_ip, self.adb_server_port, cmd)
return None

0 comments on commit ee7f978

Please sign in to comment.