From 3b7be97a5ecb9e2a6e60a68560c37d5ee00d8f67 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Sat, 23 Feb 2019 14:52:51 -0600 Subject: [PATCH] starting on refactor this might take a while --- .gitignore | 463 ++++++++++++++++++ pyadb/__init__.py | 1 + adb.py => pyadb/adb.py | 0 config.ini => pyadb/config.ini | 0 pyadb/extras/__init__.py | 1 + .../extras/open_youtube.py | 0 sync_clip.py => pyadb/extras/sync_clip.py | 0 pyadb/internal/__init__.py | 1 + android_db.py => pyadb/internal/android_db.py | 0 pyadb/internal/cli_wrap.py | 52 ++ .../internal/load_config.py | 4 +- test.py => pyadb/test.py | 0 setup.py | 1 + 13 files changed, 521 insertions(+), 2 deletions(-) create mode 100644 pyadb/__init__.py rename adb.py => pyadb/adb.py (100%) rename config.ini => pyadb/config.ini (100%) create mode 100644 pyadb/extras/__init__.py rename open_youtube.py => pyadb/extras/open_youtube.py (100%) rename sync_clip.py => pyadb/extras/sync_clip.py (100%) create mode 100644 pyadb/internal/__init__.py rename android_db.py => pyadb/internal/android_db.py (100%) create mode 100644 pyadb/internal/cli_wrap.py rename load_things.py => pyadb/internal/load_config.py (86%) rename test.py => pyadb/test.py (100%) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 6ccfa62..a1b41b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,467 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ __pycache__ decode_parcel.py decoded.txt parcel_ex.txt +Pipfile +Pipfile.lock diff --git a/pyadb/__init__.py b/pyadb/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/pyadb/__init__.py @@ -0,0 +1 @@ + diff --git a/adb.py b/pyadb/adb.py similarity index 100% rename from adb.py rename to pyadb/adb.py diff --git a/config.ini b/pyadb/config.ini similarity index 100% rename from config.ini rename to pyadb/config.ini diff --git a/pyadb/extras/__init__.py b/pyadb/extras/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/pyadb/extras/__init__.py @@ -0,0 +1 @@ + diff --git a/open_youtube.py b/pyadb/extras/open_youtube.py similarity index 100% rename from open_youtube.py rename to pyadb/extras/open_youtube.py diff --git a/sync_clip.py b/pyadb/extras/sync_clip.py similarity index 100% rename from sync_clip.py rename to pyadb/extras/sync_clip.py diff --git a/pyadb/internal/__init__.py b/pyadb/internal/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/pyadb/internal/__init__.py @@ -0,0 +1 @@ + diff --git a/android_db.py b/pyadb/internal/android_db.py similarity index 100% rename from android_db.py rename to pyadb/internal/android_db.py diff --git a/pyadb/internal/cli_wrap.py b/pyadb/internal/cli_wrap.py new file mode 100644 index 0000000..5a7ea17 --- /dev/null +++ b/pyadb/internal/cli_wrap.py @@ -0,0 +1,52 @@ +import subprocess +import shlex + +class AdbWrapper: + + def __init__(self, + executable_path, + serial = None + ): + self.executable_path = executable_path + self.serial = serial + self.selfrooted = False + + def exec(self,comspec,output_streams = False): + if isinstance(comspec,str): + comspec = shlex.split(comspec) + + comspec.insert(0,self.executable_path) + if self.serial: + comspec = comspec[:1] + ['-s',self.serial] + comspec[1:] + + if output_streams: + res = subprocess.run(comspec,capture_output=True,check=True) + return res.stdout + + else: + ret = subprocess.check_call(comspec,shell=False) + + def shell(self,comspec,output_streams = False): + if isinstance(comspec,str): + comspec = shlex.split(comspec) + comspec.insert(0,'exec-out') + return self.exec(comspec,output_streams) + + def sudo(self,comspec,output_streams = False): + if not self.rooted: + comspec = ['su','--','--'] + comspec + return self.shell(comspec,output_streams) + + def root(self): + self.exec('root') + self.rooted = True + + def unroot(self): + self.exec('unroot') + self.rooted = False + +if __name__ == "__main__": + exec_path = r"C:\Program Files\platform-tools\adb.exe" + wrapper = AdbWrapper(exec_path,'LGD415d60b8c9b') + wrapper.root() + wrapper.sudo(['ls','/']) \ No newline at end of file diff --git a/load_things.py b/pyadb/internal/load_config.py similarity index 86% rename from load_things.py rename to pyadb/internal/load_config.py index af1721e..63615d6 100644 --- a/load_things.py +++ b/pyadb/internal/load_config.py @@ -2,11 +2,11 @@ import json import munch import os import configparser -path = os.path.dirname(__file__) +path = os.path.abspath(os.path.join(os.path.dirname(__file__),'..\\')) parser = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation()) parser.read(os.path.join(path,'config.ini')) with open(os.path.join(path,'keycodes.json')) as k: - + keycodes = munch.munchify(json.load(k)) config = parser.__dict__['_sections'] for key,value in config['local'].items(): diff --git a/test.py b/pyadb/test.py similarity index 100% rename from test.py rename to pyadb/test.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/setup.py @@ -0,0 +1 @@ +