From 8f63ff822d0102dd13b92bcc30491b5d48170663 Mon Sep 17 00:00:00 2001 From: Chen John L Date: Tue, 12 Sep 2017 23:34:02 +0800 Subject: [PATCH] Added support for toybox ls --- src/Aafm.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Aafm.py b/src/Aafm.py index 2b0412f..b1c5c4f 100644 --- a/src/Aafm.py +++ b/src/Aafm.py @@ -9,7 +9,7 @@ def __init__(self, adb='adb', host_cwd=None, device_cwd='/', device_serial=None) self.host_cwd = host_cwd self.device_cwd = device_cwd self.device_serial = device_serial - self.busybox = False + self.ls_type = '' self.connected_devices = [] # The Android device should always use POSIX path style separators (/), @@ -50,7 +50,7 @@ def set_device_cwd(self, cwd): def set_device_serial(self, serial): self.device_serial = serial - self.probe_for_busybox() + self.probe_for_ls_type() def get_device_serial(self): return self.device_serial @@ -94,14 +94,23 @@ def get_free_space(self): mountpoint, size, used, free, blksize = splitted return free - def probe_for_busybox(self): - self.busybox = any(line.startswith('BusyBox') - for line in self.adb_shell('ls', '--help')) + def probe_for_ls_type(self): + if any(line.startswith('BusyBox') + for line in self.adb_shell('ls', '--help')): + self.ls_type = 'busybox' + elif any((line.find('toybox') != -1) + for line in self.adb_shell('stat', '/system/bin/ls')): + self.ls_type = 'toybox' + else: + self.ls_type = '' def device_list_files_parsed(self, device_dir): - if self.busybox: + if self.ls_type == 'busybox': command = ['ls', '-l', '-A', '-e', '--color=never', device_dir] pattern = re.compile(r"^(?P[dl\-][rwx\-]+)\s+(?P\d+)\s+(?P[\w_]+)\s+(?P[\w_]+)\s+(?P\d+)\s+(?P\w{3} \w{3}\s+\d+\s+\d{2}:\d{2}:\d{2} \d{4}) (?P.+)$") + elif self.ls_type == 'toybox': + command = ['ls', '-l', '-A', device_dir] + pattern = re.compile(r"^(?P[dl\-][rwx\-]+)\s+(?P\d+)\s+(?P[\w_]+)\s+(?P[\w_]+)\s+(?P\d+)\s+(?P\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (?P.+)$") else: command = ['ls', '-l', '-a', device_dir] pattern = re.compile(r"^(?P[dl\-][rwx\-]+) (?P\w+)\W+(?P[\w_]+)\W*(?P\d+)?\W+(?P\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (?P.+)$") @@ -121,7 +130,7 @@ def device_list_files_parsed(self, device_dir): fsize = 0 filename = match.group('name') - if self.busybox: + if self.ls_type == 'busybox': date_format = "%a %b %d %H:%M:%S %Y" else: date_format = "%Y-%m-%d %H:%M"