adbshellexecuter


Nameadbshellexecuter JSON
Version 0.11 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/adbshellexecuter
SummaryA class to execute ADB (Android Debug Bridge) commands on multiple operating systems.
upload_time2024-08-29 04:00:48
maintainerNone
docs_urlNone
authorJohannes Fischer
requires_pythonNone
licenseMIT
keywords android adb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# A class to execute ADB (Android Debug Bridge) commands on multiple operating systems.

### Tested against Windows 10/Android/Linux / Python 3.11 / Anaconda

### pip install adbshellexecuter


```PY

A class to execute ADB (Android Debug Bridge) commands on multiple operating systems.

This class provides methods to run ADB commands with and without capturing stdout and stderr,
as well as creating non-blocking subprocesses. It handles different operating system environments
such as Windows, Linux, macOS, and Android, providing a unified interface for ADB command execution.
Òn Android, the "adb shell" part is completely ignored, instead a subshell (sh) is used to execute commands

Args:
    adb_path (str): The path to the adb executable.
    device_serial (str): The serial number of the device.
    standard_kwargs_windows (tuple): Standard kwargs for Windows.
    standard_kwargs_linux (tuple): Standard kwargs for Linux.
    standard_kwargs_darwin (tuple): Standard kwargs for macOS.
    standard_kwargs_android (tuple): Standard kwargs for Android.
# Example usage
import shutil
from adbshellexecuter import UniversalADBExecutor
device_serial = "127.0.0.1:5645"
adb_path = shutil.which("adb")

adbshell = UniversalADBExecutor(
    adb_path=adb_path,
    device_serial=device_serial,
    standard_kwargs_windows=(
        ("env", os.environ),
        ("shell", False),
        ("startupinfo", startupinfo),
        (
            "creationflags",
            creationflags,
        ),
        ("start_new_session", True),
    ),
    standard_kwargs_linux=(
        ("env", os.environ),
        ("shell", True),
    ),
    standard_kwargs_darwin=(
        ("env", os.environ),
        ("shell", True),
    ),
    standard_kwargs_android=(
        ("env", os.environ),
        ("shell", True),
    ),
)

adbshell.non_shell_adb_commands_without_s_serial(
    [
        "connect",
        device_serial,
    ],
)

p1 = adbshell.shell_without_capturing_stdout_and_stderr(
    "mkdir -p '/sdcard/testfiles'", cwd="c:\\windows"
)
p2 = adbshell.shell_with_capturing_import_stdout_and_stderr("ls /sdcard", check=True)
p3 = adbshell.non_shell_adb_commands_with_s_serial(
    r'push "C:\writetext.txt" /sdcard/testfiles'
)

nonblock = adbshell.create_non_blocking_proc(
    debug=True, ignore_exceptions=False, bufsize=1
)
nonblock.extra_data_to_print_stderr = "stderr: "
nonblock.extra_data_to_print_stdout = "stdout: "
nonblock.stdinwrite("ls")
nonblock.stdinwrite("ls /sdcard/testfiles")
print(nonblock.stdout_results)
nonblock.stdinwrite("ls /sdcardbbbbbbbb/testfiles")
print(nonblock.stderr_results)
nonblock.stdinwrite("su")
commandok = nonblock.stdinwrite("ls /system")
print(f"{commandok=}")
print(nonblock.stderr_results)
commandok = nonblock.stdinwrite("ls /system")
nonblock.print_stdout = False
nonblock.print_stderr = False
print(nonblock.stderr_results)
nonblock.kill()
commandok2 = nonblock.stdinwrite("ls /system")

p4 = adbshell.shell_without_capturing_stdout_and_stderr(
    command="while true;do ls;sleep 1;done",
    debug=True,
    ignore_exceptions=True,
    timeout=10,
)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/adbshellexecuter",
    "name": "adbshellexecuter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "android, adb",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/88/e1/4e714ac8658d1a430cc710c6b37e258f22a0581bf6a6103d1e46964bc871/adbshellexecuter-0.11.tar.gz",
    "platform": null,
    "description": "\r\n# A class to execute ADB (Android Debug Bridge) commands on multiple operating systems.\r\n\r\n### Tested against Windows 10/Android/Linux / Python 3.11 / Anaconda\r\n\r\n### pip install adbshellexecuter\r\n\r\n\r\n```PY\r\n\r\nA class to execute ADB (Android Debug Bridge) commands on multiple operating systems.\r\n\r\nThis class provides methods to run ADB commands with and without capturing stdout and stderr,\r\nas well as creating non-blocking subprocesses. It handles different operating system environments\r\nsuch as Windows, Linux, macOS, and Android, providing a unified interface for ADB command execution.\r\n\u00d2n Android, the \"adb shell\" part is completely ignored, instead a subshell (sh) is used to execute commands\r\n\r\nArgs:\r\n    adb_path (str): The path to the adb executable.\r\n    device_serial (str): The serial number of the device.\r\n    standard_kwargs_windows (tuple): Standard kwargs for Windows.\r\n    standard_kwargs_linux (tuple): Standard kwargs for Linux.\r\n    standard_kwargs_darwin (tuple): Standard kwargs for macOS.\r\n    standard_kwargs_android (tuple): Standard kwargs for Android.\r\n# Example usage\r\nimport shutil\r\nfrom adbshellexecuter import UniversalADBExecutor\r\ndevice_serial = \"127.0.0.1:5645\"\r\nadb_path = shutil.which(\"adb\")\r\n\r\nadbshell = UniversalADBExecutor(\r\n    adb_path=adb_path,\r\n    device_serial=device_serial,\r\n    standard_kwargs_windows=(\r\n        (\"env\", os.environ),\r\n        (\"shell\", False),\r\n        (\"startupinfo\", startupinfo),\r\n        (\r\n            \"creationflags\",\r\n            creationflags,\r\n        ),\r\n        (\"start_new_session\", True),\r\n    ),\r\n    standard_kwargs_linux=(\r\n        (\"env\", os.environ),\r\n        (\"shell\", True),\r\n    ),\r\n    standard_kwargs_darwin=(\r\n        (\"env\", os.environ),\r\n        (\"shell\", True),\r\n    ),\r\n    standard_kwargs_android=(\r\n        (\"env\", os.environ),\r\n        (\"shell\", True),\r\n    ),\r\n)\r\n\r\nadbshell.non_shell_adb_commands_without_s_serial(\r\n    [\r\n        \"connect\",\r\n        device_serial,\r\n    ],\r\n)\r\n\r\np1 = adbshell.shell_without_capturing_stdout_and_stderr(\r\n    \"mkdir -p '/sdcard/testfiles'\", cwd=\"c:\\\\windows\"\r\n)\r\np2 = adbshell.shell_with_capturing_import_stdout_and_stderr(\"ls /sdcard\", check=True)\r\np3 = adbshell.non_shell_adb_commands_with_s_serial(\r\n    r'push \"C:\\writetext.txt\" /sdcard/testfiles'\r\n)\r\n\r\nnonblock = adbshell.create_non_blocking_proc(\r\n    debug=True, ignore_exceptions=False, bufsize=1\r\n)\r\nnonblock.extra_data_to_print_stderr = \"stderr: \"\r\nnonblock.extra_data_to_print_stdout = \"stdout: \"\r\nnonblock.stdinwrite(\"ls\")\r\nnonblock.stdinwrite(\"ls /sdcard/testfiles\")\r\nprint(nonblock.stdout_results)\r\nnonblock.stdinwrite(\"ls /sdcardbbbbbbbb/testfiles\")\r\nprint(nonblock.stderr_results)\r\nnonblock.stdinwrite(\"su\")\r\ncommandok = nonblock.stdinwrite(\"ls /system\")\r\nprint(f\"{commandok=}\")\r\nprint(nonblock.stderr_results)\r\ncommandok = nonblock.stdinwrite(\"ls /system\")\r\nnonblock.print_stdout = False\r\nnonblock.print_stderr = False\r\nprint(nonblock.stderr_results)\r\nnonblock.kill()\r\ncommandok2 = nonblock.stdinwrite(\"ls /system\")\r\n\r\np4 = adbshell.shell_without_capturing_stdout_and_stderr(\r\n    command=\"while true;do ls;sleep 1;done\",\r\n    debug=True,\r\n    ignore_exceptions=True,\r\n    timeout=10,\r\n)\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A class to execute ADB (Android Debug Bridge) commands on multiple operating systems.",
    "version": "0.11",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/adbshellexecuter"
    },
    "split_keywords": [
        "android",
        " adb"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7020d71edaf157997c5f94aaa696d097f28f93f73745b2970fb98de429d1a58b",
                "md5": "6c221ca8011705ee096120dd017b2557",
                "sha256": "7795120ba8487a1b9f3790c688d1088b793626b3d2f74e64e33f474919bdc740"
            },
            "downloads": -1,
            "filename": "adbshellexecuter-0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6c221ca8011705ee096120dd017b2557",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10061,
            "upload_time": "2024-08-29T04:00:46",
            "upload_time_iso_8601": "2024-08-29T04:00:46.839214Z",
            "url": "https://files.pythonhosted.org/packages/70/20/d71edaf157997c5f94aaa696d097f28f93f73745b2970fb98de429d1a58b/adbshellexecuter-0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "88e14e714ac8658d1a430cc710c6b37e258f22a0581bf6a6103d1e46964bc871",
                "md5": "6d5fa7031219b682ef443c305667fb7e",
                "sha256": "628a302a4c44b1adb5f301c0d2732149a4990323e60903dc8368b7df4ac332e8"
            },
            "downloads": -1,
            "filename": "adbshellexecuter-0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "6d5fa7031219b682ef443c305667fb7e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8196,
            "upload_time": "2024-08-29T04:00:48",
            "upload_time_iso_8601": "2024-08-29T04:00:48.302248Z",
            "url": "https://files.pythonhosted.org/packages/88/e1/4e714ac8658d1a430cc710c6b37e258f22a0581bf6a6103d1e46964bc871/adbshellexecuter-0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-29 04:00:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "adbshellexecuter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "adbshellexecuter"
}
        
Elapsed time: 0.81089s