Skip to content

Commit

Permalink
Support recursive file detection
Browse files Browse the repository at this point in the history
  • Loading branch information
scottanderson committed Jun 16, 2013
1 parent b3da7b3 commit d5ee845
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions adbsync.py
Expand Up @@ -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):
Expand All @@ -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)

This comment has been minimized.

Copy link
@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 + '/'):

This comment has been minimized.

Copy link
@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.')
Expand Down

1 comment on commit d5ee845

@xenomachina
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.