Skip to content

Commit

Permalink
Prepare usb-support branch for merging into master
Browse files Browse the repository at this point in the history
* Fix linting checks (#77)

  * Fix linting checks

  * Linting

* Change 'Close' to 'close' (#94)

* Add copyright notice, exclude from coverage, and fix docs (#95)

  * Add copyright notice and exclude from coverage

  * Add warning that USB support is experimental

  * Add libusb1 to docs requirements

  * Create adb_shell.handle.usb_handle.rst

  * Update docs RST files

* Remove 'rb' from the open calls in the README

* Fix ReadTheDocs failed import of 'usb1'
  • Loading branch information
JeffLIrion committed May 31, 2020
1 parent 904ea48 commit a13ac91
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -35,14 +35,14 @@ Example Usage
device1.connect(auth_timeout_s=0.1)
# Connect (authentication required)
with open('path/to/adbkey', 'rb') as f:
with open('path/to/adbkey') as f:
priv = f.read()
signer = PythonRSASigner('', priv)
device2 = AdbDeviceTcp('192.168.0.222', 5555, default_timeout_s=9.)
device2.connect(rsa_keys=[signer], auth_timeout_s=0.1)
# Connect via USB (package must be installed via `pip install adb-shell[usb])`
with open('path/to/adbkey', 'rb') as f:
with open('path/to/adbkey') as f:
priv = f.read()
signer = PythonRSASigner('', priv)
device3 = AdbDeviceUsb('ab78c6ef')
Expand Down
35 changes: 28 additions & 7 deletions adb_shell/handle/usb_handle.py
@@ -1,9 +1,30 @@
# Copyright (c) 2020 Jeff Irion and contributors
#
# This file is part of the adb-shell package.
# This file is part of the adb-shell package. It incorporates work
# covered by the following license notice:
#
#
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A class for creating a USB connection with the device and sending and receiving data.
.. warning::
USB support is an experimental feature.
* :func:`get_interface`
* :func:`interface_matcher`
* :class:`UsbHandle`
Expand Down Expand Up @@ -54,7 +75,7 @@
PROTOCOL = 0x01


def get_interface(setting):
def get_interface(setting): # pragma: no cover
"""Get the class, subclass, and protocol for the given USB setting.
Parameters
Expand All @@ -75,7 +96,7 @@ def get_interface(setting):
return (setting.getClass(), setting.getSubClass(), setting.getProtocol())


def interface_matcher(clazz, subclass, protocol):
def interface_matcher(clazz, subclass, protocol): # pragma: no cover
"""Returns a matcher that returns the setting with the given interface.
Parameters
Expand Down Expand Up @@ -117,7 +138,7 @@ def matcher(device):
return matcher


class UsbHandle(BaseHandle):
class UsbHandle(BaseHandle): # pragma: no cover
"""USB communication object. Not thread-safe.
Handles reading and writing over USB with the proper endpoints, exceptions,
Expand Down Expand Up @@ -307,7 +328,7 @@ def _open(self):

for endpoint in self._setting.iterEndpoints():
address = endpoint.getAddress()
if address & usb1.USB_ENDPOINT_DIR_MASK:
if address & usb1.USB_ENDPOINT_DIR_MASK: # pylint: disable=no-member
self._read_endpoint = address
self._max_read_packet_len = endpoint.getMaxPacketSize()
else:
Expand All @@ -321,7 +342,7 @@ def _open(self):
try:
if (platform.system() != 'Windows' and handle.kernelDriverActive(iface_number)):
handle.detachKernelDriver(iface_number)
except usb1.USBErrorNotFound as e: # pylint: disable=no-member
except usb1.USBErrorNotFound: # pylint: disable=no-member
warnings.warn('Kernel driver not found for interface: %s.', iface_number)
handle.claimInterface(iface_number)
self._handle = handle
Expand All @@ -330,7 +351,7 @@ def _open(self):
with self._HANDLE_CACHE_LOCK:
self._HANDLE_CACHE[port_path] = self
# When this object is deleted, make sure it's closed.
weakref.ref(self, self.Close)
weakref.ref(self, self.close)

def _timeout_ms(self, timeout_s):
"""TODO
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Expand Up @@ -2,3 +2,4 @@ sphinx==2.1.2
adb-shell
cryptography
pycryptodome
libusb1
1 change: 1 addition & 0 deletions docs/source/adb_shell.handle.rst
Expand Up @@ -8,6 +8,7 @@ Submodules

adb_shell.handle.base_handle
adb_shell.handle.tcp_handle
adb_shell.handle.usb_handle

Module contents
---------------
Expand Down
7 changes: 7 additions & 0 deletions docs/source/adb_shell.handle.usb_handle.rst
@@ -0,0 +1,7 @@
adb\_shell.handle.usb\_handle module
====================================

.. automodule:: adb_shell.handle.usb_handle
:members:
:undoc-members:
:show-inheritance:
7 changes: 0 additions & 7 deletions docs/source/adb_shell.tcp_handle.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -75,7 +75,7 @@
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

autodoc_mock_imports = []
autodoc_mock_imports = ['libusb1', 'usb1']

autodoc_default_options = {'members': True, 'undoc-members': True, 'private-members': True, 'show-inheritance': True}

Expand Down

0 comments on commit a13ac91

Please sign in to comment.