Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 7546aab

Browse files
committed
Add make_tools.py to generate adb.zip and fastboot.zip.
Change imports to always be relative to the package, e.g. "from adb import ..." make_tools.py creates standalone, easy to distribute executables meant to be used in a continuous integration system via various CPU architecture where having interpreted code is valuable. Make progressbar optional so both adb.zip and fastboot.zip do not have any hard dependency except python-libusb.
1 parent 8ce5ac4 commit 7546aab

11 files changed

Lines changed: 113 additions & 29 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.pyc
2+
/adb.zip
3+
/fastboot.zip

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,52 @@ python-adb
66
This repository contains a pure-python implementation of the ADB and Fastboot
77
protocols, using libusb1 for USB communications.
88

9-
This is a complete replacement and rearchitecture of the Android project's ADB
10-
and fastboot code available at
11-
https://github.com/android/platform_system_core/tree/master/adb
9+
This is a complete replacement and rearchitecture of the Android project's [ADB
10+
and fastboot code](https://github.com/android/platform_system_core/tree/master/adb)
1211

1312
This code is mainly targeted to users that need to communicate with Android
1413
devices in an automated fashion, such as in automated testing. It does not have
1514
a daemon between the client and the device, and therefore does not support
1615
multiple simultaneous commands to the same device. It does support any number of
17-
devices and never communicates with a device that it wasn't intended to, unlike
18-
the Android project's ADB.
16+
devices and _never_ communicates with a device that it wasn't intended to,
17+
unlike the Android project's ADB.
18+
19+
20+
### Using as standalone tool
21+
22+
Running `./make_tools.py` creates two files: `adb.zip` and `fastboot.zip`. They
23+
can be run similar to native `adb` and `fastboot` via the python interpreter:
24+
25+
python adb.zip devices
26+
python adb.zip shell ls /sdcard
27+
28+
29+
### Pros
1930

20-
Pros:
2131
* Simpler code due to use of libusb1 and Python.
2232
* API can be used by other Python code easily.
2333
* Errors are propagated with tracebacks, helping debug connectivity issues.
34+
* No daemon outliving the command.
35+
* Can be packaged as standalone zips that can be run independent of the CPU
36+
architecture (e.g. x86 vs ARM).
37+
38+
39+
### Cons
2440

25-
Cons:
2641
* Technically slower due to Python, mitigated by no daemon.
2742
* Only one command per device at a time.
2843
* More dependencies than Android's ADB.
2944

30-
Dependencies:
45+
46+
### Dependencies
47+
3148
* libusb1 (1.0.16+)
3249
* python-libusb1 (1.2.0+)
33-
* python-progressbar (for fastboot_debug, 2.3+)
34-
* One of:
50+
* `adb.zip`: one of:
3551
* python-m2crypto (0.21.1+)
3652
* python-rsa (3.2+)
53+
* `fastboot.zip` (optional):
54+
* python-progressbar (2.3+)
3755

3856
[coverage_img]: https://coveralls.io/repos/github/google/python-adb/badge.svg?branch=master
3957
[coverage_link]: https://coveralls.io/github/google/python-adb?branch=master

adb/adb_commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import os
2727
import socket
2828

29-
import adb_protocol
30-
import common
31-
import filesync_protocol
29+
from adb import adb_protocol
30+
from adb import common
31+
from adb import filesync_protocol
3232

3333
# From adb.h
3434
CLASS = 0xFF
@@ -40,7 +40,7 @@
4040

4141
try:
4242
# Imported locally to keep compatibility with previous code.
43-
from sign_m2crypto import M2CryptoSigner
43+
from adb.sign_m2crypto import M2CryptoSigner
4444
except ImportError:
4545
# Ignore this error when M2Crypto is not installed, there are other options.
4646
pass

adb/adb_debug.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
import sys
2424
import time
2525

26-
import adb_commands
27-
import common_cli
26+
from adb import adb_commands
27+
from adb import common_cli
2828

2929
try:
30-
import sign_m2crypto
30+
from adb import sign_m2crypto
3131
rsa_signer = sign_m2crypto.M2CryptoSigner
3232
except ImportError:
3333
try:
34-
import sign_pythonrsa
34+
from adb import sign_pythonrsa
3535
rsa_signer = sign_pythonrsa.PythonRSASigner.FromRSAKeyPath
3636
except ImportError:
3737
rsa_signer = None

adb/adb_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import struct
2121
import time
2222

23-
import usb_exceptions
23+
from adb import usb_exceptions
2424

2525

2626
# Maximum amount of data in an ADB packet.

adb/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import libusb1
2424
import usb1
2525

26-
import usb_exceptions
26+
from adb import usb_exceptions
2727

2828
DEFAULT_TIMEOUT_MS = 1000
2929

adb/common_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import textwrap
2929
import types
3030

31-
import usb_exceptions
31+
from adb import usb_exceptions
3232

3333

3434
class _PortPathAction(argparse.Action):

adb/fastboot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import os
2222
import struct
2323

24-
import common
25-
import usb_exceptions
24+
from adb import common
25+
from adb import usb_exceptions
2626

2727

2828
_LOG = logging.getLogger('fastboot')

adb/fastboot_debug.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
import logging
2525
import sys
2626

27-
import progressbar
27+
from adb import common_cli
28+
from adb import fastboot
2829

29-
import common_cli
30-
import fastboot
30+
try:
31+
import progressbar
32+
except ImportError:
33+
# progressbar is optional.
34+
progressbar = None
3135

3236

3337
def Devices(args):
@@ -100,7 +104,7 @@ def main():
100104
argspec = inspect.getargspec(args.method)
101105
if 'info_cb' in argspec.args:
102106
kwargs['info_cb'] = _InfoCb
103-
if 'progress_callback' in argspec.args:
107+
if 'progress_callback' in argspec.args and progressbar:
104108
bar = progressbar.ProgessBar(
105109
widgets=[progressbar.Bar(), progressbar.Percentage()])
106110
bar.start()

adb/filesync_protocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
import libusb1
2626

27-
import adb_protocol
28-
import usb_exceptions
27+
from adb import adb_protocol
28+
from adb import usb_exceptions
2929

3030
# Default mode for pushed files.
3131
DEFAULT_PUSH_MODE = stat.S_IFREG | stat.S_IRWXU | stat.S_IRWXG

0 commit comments

Comments
 (0)