Browse Source

Made pep8 compliant

refactor
Raphael Roberts 7 years ago
parent
commit
e69757152a
  1. 1
      .gitignore
  2. 1
      pyadb/__init__.py
  3. 27
      pyadb/adb.py
  4. 1
      pyadb/extras/__init__.py
  5. 4
      pyadb/extras/open_youtube.py
  6. 13
      pyadb/extras/sync_clip.py
  7. 1
      pyadb/internal/__init__.py
  8. 10
      pyadb/internal/android_db.py
  9. 2
      pyadb/internal/cli_wrap.py
  10. 3
      pyadb/internal/load_config.py
  11. 8
      pyadb/test.py
  12. 1
      setup.py

1
.gitignore

@ -465,3 +465,4 @@ decoded.txt
parcel_ex.txt parcel_ex.txt
Pipfile Pipfile
Pipfile.lock Pipfile.lock
*#*#

1
pyadb/__init__.py

@ -1 +0,0 @@

27
pyadb/adb.py

@ -14,6 +14,7 @@ config = loaded.config
keycodes = loaded.keycodes keycodes = loaded.keycodes
exe = config.defaults.exe exe = config.defaults.exe
def merge(src, dst, log=False): def merge(src, dst, log=False):
if not os.path.exists(dst): if not os.path.exists(dst):
return False return False
@ -27,7 +28,8 @@ def merge(src, dst,log = False):
destFile = os.path.join(destPath, file) destFile = os.path.join(destPath, file)
if os.path.isfile(destFile): if os.path.isfile(destFile):
if log: if log:
print("Skipping existing file: " + os.path.join(relPath, file))
print("Skipping existing file: " +
os.path.join(relPath, file))
ok = False ok = False
continue continue
srcFile = os.path.join(path, file) srcFile = os.path.join(path, file)
@ -37,6 +39,7 @@ def merge(src, dst,log = False):
os.rmdir(path) os.rmdir(path)
return ok return ok
def _adb(*args, output="shell"): def _adb(*args, output="shell"):
'''Output modes: '''Output modes:
"out": return output "out": return output
@ -53,12 +56,15 @@ def _adb(*args,output = "shell"):
p = subprocess.Popen(args, stdout=subprocess.PIPE) p = subprocess.Popen(args, stdout=subprocess.PIPE)
return p.stdout return p.stdout
def kill_server(): def kill_server():
_adb('kill-server') _adb('kill-server')
def start_server(): def start_server():
_adb('start-server') _adb('start-server')
def get_info(): def get_info():
start_server() start_server()
thing = _adb("devices", "-l", output="out") thing = _adb("devices", "-l", output="out")
@ -70,10 +76,12 @@ def get_info():
"serial": categories[0], "serial": categories[0],
"mode": categories[1] "mode": categories[1]
} }
device_dict.update(dict(category.split(":") for category in categories[2:]))
device_dict.update(dict(category.split(":")
for category in categories[2:]))
main[categories[0]] = device_dict main[categories[0]] = device_dict
return main return main
class ADBWrapper: class ADBWrapper:
root_mode = False root_mode = False
@ -159,6 +167,7 @@ class ADBWrapper:
break break
time.sleep(1) time.sleep(1)
class FSActionWrapper(ADBWrapper): class FSActionWrapper(ADBWrapper):
def stat(self, file): def stat(self, file):
@ -226,7 +235,8 @@ The valid format escape sequences for filesystems:
def move(self, remote, local, del_duplicates=True, ignore_error=False): def move(self, remote, local, del_duplicates=True, ignore_error=False):
if self.exists(remote): if self.exists(remote):
self.copy(remote,local,del_duplicates = del_duplicates,ignore_error=ignore_error)
self.copy(remote, local, del_duplicates=del_duplicates,
ignore_error=ignore_error)
self.delete(remote) self.delete(remote)
else: else:
print("File not found: {}".format(remote)) print("File not found: {}".format(remote))
@ -234,6 +244,7 @@ The valid format escape sequences for filesystems:
def push(self, local, remote): def push(self, local, remote):
self.adb('push', local, remote) self.adb('push', local, remote)
class Input(ADBWrapper): class Input(ADBWrapper):
def send_keycode(self, code): def send_keycode(self, code):
@ -253,6 +264,7 @@ class Input(ADBWrapper):
self.shell("input", "text", str(password)) self.shell("input", "text", str(password))
self.send_keycode('enter') self.send_keycode('enter')
class TWRP(FSActionWrapper): class TWRP(FSActionWrapper):
def backup(self, *partitions, name=None, backupdir=None): def backup(self, *partitions, name=None, backupdir=None):
@ -275,10 +287,12 @@ class TWRP(FSActionWrapper):
} }
options = "".join(options_dict[option] for option in partitions) options = "".join(options_dict[option] for option in partitions)
if not name: if not name:
name = "backup_"+datetime.datetime.today().strftime(defaults['date_format'])
name = "backup_" + \
datetime.datetime.today().strftime(defaults['date_format'])
filename = os.path.join(backupdir, name) filename = os.path.join(backupdir, name)
self.shell("twrp", "backup", options, name) self.shell("twrp", "backup", options, name)
phone_dir = "/data/media/0/TWRP/BACKUPS/{serial}/{name}".format(serial = self.serial,name = name)
phone_dir = "/data/media/0/TWRP/BACKUPS/{serial}/{name}".format(
serial=self.serial, name=name)
self.move(phone_dir, filename) self.move(phone_dir, filename)
def wipe(self, partition): def wipe(self, partition):
@ -301,7 +315,10 @@ class TWRP(FSActionWrapper):
update_path = '{}/{}'.format(config['remote']['updates'], name) update_path = '{}/{}'.format(config['remote']['updates'], name)
self.shell("twrp", "install", update_path) self.shell("twrp", "install", update_path)
class Device(TWRP, Input): class Device(TWRP, Input):
pass pass
if __name__ == "__main__" and debug: if __name__ == "__main__" and debug:
d = Device.prim_device() d = Device.prim_device()

1
pyadb/extras/__init__.py

@ -1 +0,0 @@

4
pyadb/extras/open_youtube.py

@ -1,7 +1,11 @@
from adb import Device from adb import Device
import pyperclip import pyperclip
def open_youtube(Device, link): def open_youtube(Device, link):
Device.shell(*('am start -a android.intent.action.VIEW'.split(' ')), link) Device.shell(*('am start -a android.intent.action.VIEW'.split(' ')), link)
if __name__ == "__main__": if __name__ == "__main__":
d = Device.prim_device() d = Device.prim_device()
open_youtube(d, pyperclip.paste()) open_youtube(d, pyperclip.paste())

13
pyadb/extras/sync_clip.py

@ -1,18 +1,25 @@
import pyperclip import pyperclip
import time import time
import re import re
def sync_clipboard(dev): def sync_clipboard(dev):
db_file = '/data/data/com.catchingnow.tinyclipboardmanager/databases/clippingnow.db' db_file = '/data/data/com.catchingnow.tinyclipboardmanager/databases/clippingnow.db'
try: try:
pid = dev.shell('pidof','com.catchingnow.tinyclipboardmanager',output="out")
pid = dev.shell(
'pidof', 'com.catchingnow.tinyclipboardmanager', output="out")
dev.sudo('kill', pid, output='shell') dev.sudo('kill', pid, output='shell')
except: except:
pass pass
t = time.time() t = time.time()
text = pyperclip.paste() text = pyperclip.paste()
conn = dev.db_connect(db_file) conn = dev.db_connect(db_file)
out = conn.execute("INSERT INTO cliphistory VALUES (?,?,?);",[int(1000*t),text,False])
dev.shell('am', 'start', '-n', 'com.catchingnow.tinyclipboardmanager/.activity.ActivityMain')
out = conn.execute("INSERT INTO cliphistory VALUES (?,?,?);", [
int(1000*t), text, False])
dev.shell('am', 'start', '-n',
'com.catchingnow.tinyclipboardmanager/.activity.ActivityMain')
if __name__ == "__main__": if __name__ == "__main__":
import adb import adb
d = adb.Device.prim_device() d = adb.Device.prim_device()

1
pyadb/internal/__init__.py

@ -1 +0,0 @@

10
pyadb/internal/android_db.py

@ -5,6 +5,8 @@ import sys
csv.field_size_limit(2**31-1) csv.field_size_limit(2**31-1)
dict_params = re.compile(r':([^\ \,\.\\\(\)\=]+)') dict_params = re.compile(r':([^\ \,\.\\\(\)\=]+)')
list_params = re.compile(r'\?') list_params = re.compile(r'\?')
class AndroidSQLConn: class AndroidSQLConn:
def __init__(self, device, filepath, use_root=True): def __init__(self, device, filepath, use_root=True):
self.device = device self.device = device
@ -20,6 +22,7 @@ class AndroidSQLConn:
return 'NULL' return 'NULL'
else: else:
return str(param) return str(param)
def _sub_params_(SQL, params): def _sub_params_(SQL, params):
params = iter(params) params = iter(params)
try: try:
@ -44,9 +47,12 @@ class AndroidSQLConn:
shell = self.device.sudo shell = self.device.sudo
else: else:
shell = self.device.shell shell = self.device.shell
out = shell('sqlite3','-header','-csv',shlex.quote(self.filepath),SQL,output="out")
out = shell('sqlite3', '-header', '-csv',
shlex.quote(self.filepath), SQL, output="out")
if out: if out:
return csv.DictReader(out.splitlines()) return csv.DictReader(out.splitlines())
if __name__ == "__main__": if __name__ == "__main__":
print(AndroidSQLConn._sub_params_("SELECT * FROM table WHERE name=?,age=?;",["boby;DROP TABLE table",1]))
print(AndroidSQLConn._sub_params_(
"SELECT * FROM table WHERE name=?,age=?;", ["boby;DROP TABLE table", 1]))

2
pyadb/internal/cli_wrap.py

@ -1,6 +1,7 @@
import subprocess import subprocess
import shlex import shlex
class AdbWrapper: class AdbWrapper:
def __init__(self, def __init__(self,
@ -45,6 +46,7 @@ class AdbWrapper:
self.exec('unroot') self.exec('unroot')
self.rooted = False self.rooted = False
if __name__ == "__main__": if __name__ == "__main__":
exec_path = r"C:\Program Files\platform-tools\adb.exe" exec_path = r"C:\Program Files\platform-tools\adb.exe"
wrapper = AdbWrapper(exec_path, 'LGD415d60b8c9b') wrapper = AdbWrapper(exec_path, 'LGD415d60b8c9b')

3
pyadb/internal/load_config.py

@ -3,7 +3,8 @@ import munch
import os import os
import configparser import configparser
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..\\')) path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..\\'))
parser = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
parser = configparser.ConfigParser(
interpolation=configparser.ExtendedInterpolation())
parser.read(os.path.join(path, 'config.ini')) parser.read(os.path.join(path, 'config.ini'))
with open(os.path.join(path, 'keycodes.json')) as k: with open(os.path.join(path, 'keycodes.json')) as k:

8
pyadb/test.py

@ -1,6 +1,8 @@
import time
from adb import Device from adb import Device
d = Device.prim_device() d = Device.prim_device()
import time
d.root() d.root()
conn = d.db_connect('/data/data/com.catchingnow.tinyclipboardmanager/databases/clippingnow.db')
out = conn.execute('INSERT INTO cliphistory (date,history,star) values (?,?,?)',[int(time.time()*1000),"test_test",False])
conn = d.db_connect(
'/data/data/com.catchingnow.tinyclipboardmanager/databases/clippingnow.db')
out = conn.execute('INSERT INTO cliphistory (date,history,star) values (?,?,?)', [
int(time.time()*1000), "test_test", False])

1
setup.py

@ -1 +0,0 @@
Loading…
Cancel
Save