Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/Aafm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (/),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<permissions>[dl\-][rwx\-]+)\s+(?P<hardlinks>\d+)\s+(?P<owner>[\w_]+)\s+(?P<group>[\w_]+)\s+(?P<size>\d+)\s+(?P<datetime>\w{3} \w{3}\s+\d+\s+\d{2}:\d{2}:\d{2} \d{4}) (?P<name>.+)$")
elif self.ls_type == 'toybox':
command = ['ls', '-l', '-A', device_dir]
pattern = re.compile(r"^(?P<permissions>[dl\-][rwx\-]+)\s+(?P<hardlinks>\d+)\s+(?P<owner>[\w_]+)\s+(?P<group>[\w_]+)\s+(?P<size>\d+)\s+(?P<datetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (?P<name>.+)$")
else:
command = ['ls', '-l', '-a', device_dir]
pattern = re.compile(r"^(?P<permissions>[dl\-][rwx\-]+) (?P<owner>\w+)\W+(?P<group>[\w_]+)\W*(?P<size>\d+)?\W+(?P<datetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (?P<name>.+)$")
Expand All @@ -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"
Expand Down