Permalink
Browse files

Support recursive file detection

  • Loading branch information...
1 parent b3da7b3 commit d5ee845aad999aa04181996a754c8a24757342e2 @scottanderson committed Jun 16, 2013
Showing with 11 additions and 2 deletions.
  1. +11 −2 adbsync.py
View
@@ -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)
@xenomachina
xenomachina Jul 5, 2013

Isn't this line redundant? m was assigned the same value just before the "if".

+ yield FileInfo(*m.groups())
+ for subdir in dirs:
+ for value in ListAndroidDir(dir + subdir + '/'):
@xenomachina
xenomachina Jul 5, 2013

It actually shouldn't be too hard to remove the recursion from this, so that we aren't as dependent on a deep stack, but I'm not sure how useful that change would be. Maybe add a "TODO" comment here?

+ value.name = subdir + '/' + value.name
+ yield value
def main():
parser = argparse.ArgumentParser(description='Android file sync tool.')

1 comment on commit d5ee845

@xenomachina

Thanks for making this enhancement, and sorry for taking a while getting back to you.

Please sign in to comment.