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