From d5ee845aad999aa04181996a754c8a24757342e2 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 15 Jun 2013 20:39:17 -0400 Subject: [PATCH] Support recursive file detection --- adbsync.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/adbsync.py b/adbsync.py index 0d7578d..e0a8d81 100755 --- a/adbsync.py +++ b/adbsync.py @@ -41,7 +41,7 @@ def touch(fname, dt=None): with file(fname, 'a'): os.utime(fname, dt) -LS_LINE_REGEX = re.compile(r'(..........)\s+(\w+)\s+(\w+)\s+(\d+)\s+(\d\d\d\d-\d\d-\d\d \d\d:\d\d)\s+(.+)$') +LS_LINE_REGEX = re.compile(r'(..........)\s+(\w+)\s+(\w+)\s+(\d*)\s+(\d\d\d\d-\d\d-\d\d \d\d:\d\d)\s+(.+)$') class FileInfo(object): def __init__(self, perms, user, group, size, timestamp, name): @@ -62,10 +62,19 @@ def __repr__(self): self.name))) + ')' def ListAndroidDir(dir): + dirs = [] for line in subprocess.check_output(['adb', 'shell', 'ls', '-la', dir]).split('\r\n'): if line: m = LS_LINE_REGEX.match(line) - yield FileInfo(*m.groups()) + if m.group(0).startswith('d'): + dirs.append(m.group(6)) + else: + m = LS_LINE_REGEX.match(line) + yield FileInfo(*m.groups()) + for subdir in dirs: + for value in ListAndroidDir(dir + subdir + '/'): + value.name = subdir + '/' + value.name + yield value def main(): parser = argparse.ArgumentParser(description='Android file sync tool.')