Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude param #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
30 changes: 26 additions & 4 deletions adb-sync
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ from __future__ import print_function
from __future__ import unicode_literals
import argparse
import glob
import fnmatch
import os
import re
import stat
Expand Down Expand Up @@ -305,6 +306,20 @@ def BuildFileList(fs, path, prefix=b''):
print('Note: unsupported file: %s' % path.decode('utf-8', errors='replace'))


def FilterFileList(file_iter, excludes):
if not excludes:
excludes = []
for f in file_iter:
excluded = False
for pat in excludes:
if fnmatch.fnmatch(f[0], pat):

Choose a reason for hiding this comment

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

Not sure if f[0] is right?

Copy link

Choose a reason for hiding this comment

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

thats correct, since its a tuple:

('/file/abc', posix.stat_result(st_mode=16877, st_ino=1, st_dev=0, st_nlink=1, st_uid=-2, st_gid=-2, st_size=None, st_atime=1528642980.0, st_mtime=1528642980.0, st_ctime=1528642980.0))

f[0] is the '/file/abc'

excluded = True
break
if excluded:
continue
yield f


def DiffLists(a, b):
"""Compares two lists.

Expand Down Expand Up @@ -377,7 +392,7 @@ class FileSyncer(object):

def __init__(self, adb, local_path, remote_path, local_to_remote,
remote_to_local, preserve_times, delete_missing, allow_overwrite,
allow_replace, dry_run):
allow_replace, dry_run, exclude):
self.local = local_path
self.remote = remote_path
self.adb = adb
Expand All @@ -388,6 +403,7 @@ class FileSyncer(object):
self.allow_overwrite = allow_overwrite
self.allow_replace = allow_replace
self.dry_run = dry_run
self.exclude = exclude
self.local_only = None
self.both = None
self.remote_only = None
Expand All @@ -403,8 +419,10 @@ class FileSyncer(object):
print('Scanning and diffing...')
locallist = BuildFileList(os, self.local)
remotelist = BuildFileList(self.adb, self.remote)
self.local_only, self.both, self.remote_only = DiffLists(locallist,
remotelist)
locallist_fil = FilterFileList(locallist, self.exclude)
remotelist_fil = FilterFileList(remotelist, self.exclude)
self.local_only, self.both, self.remote_only = DiffLists(locallist_fil,
remotelist_fil)
if not self.local_only and not self.both and not self.remote_only:
print('No files seen. User error?')
self.src_to_dst = (self.local_to_remote, self.remote_to_local)
Expand Down Expand Up @@ -666,6 +684,8 @@ def main(*args):
parser.add_argument('--dry-run',action='store_true',
help='Do not do anything - just show what would '+
'be done.')
parser.add_argument('-x', '--exclude', action='append', type=str,
metavar='PATTERN', help='Exclude files matching PATTERN')
args = parser.parse_args()

localpatterns = [x.encode('utf-8') for x in args.source]
Expand Down Expand Up @@ -703,6 +723,7 @@ def main(*args):
allow_replace = args.force
allow_overwrite = not args.no_clobber
dry_run = args.dry_run
exclude = args.exclude
local_to_remote = True
remote_to_local = False
if args.two_way:
Expand Down Expand Up @@ -734,7 +755,8 @@ def main(*args):
print('Sync: local %s, remote %s' % (localpaths[i], remotepaths[i]))
syncer = FileSyncer(adb, localpaths[i], remotepaths[i],
local_to_remote, remote_to_local, preserve_times,
delete_missing, allow_overwrite, allow_replace, dry_run)
delete_missing, allow_overwrite, allow_replace, dry_run,
exclude)
if not syncer.IsWorking():
print('Device not connected or not working.')
return
Expand Down