From c6a24b75d1d6ce614c4def95f9a7935fc3246502 Mon Sep 17 00:00:00 2001 From: Luke Adams Date: Fri, 21 Jul 2017 13:47:09 -0400 Subject: [PATCH 1/6] added support for list of excluded paths --- pydbxcli.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pydbxcli.py b/pydbxcli.py index 5f05429..55ea144 100755 --- a/pydbxcli.py +++ b/pydbxcli.py @@ -5,6 +5,7 @@ import argparse import signal import dropbox +import numpy __version__ = 0.1 @@ -47,6 +48,10 @@ def main(): type=str, default='/', help='which path from which to list') + parser_ls.add_argument('--excludePaths', + nargs='*', + default=[], + help="a list of folder paths to ignore. example: --excludePaths '/Team Folders/IgnoreThisFolder' '/Team Folders/IgnoreThisFolderToo'") parser_ls.set_defaults(func=ls) # create the parser for the "get" command @@ -64,6 +69,10 @@ def main(): type=str, default='.', help='which path on the local machine to store downloads') + parser_ls.add_argument('--excludePaths', + nargs='*', + default=[], + help="a list of folder paths to ignore. example: --excludePaths '/Team Folders/IgnoreThisFolder' '/Team Folders/IgnoreThisFolderToo'") parser_ls.set_defaults(func=get) # parse the args and call the selected command function default to help and version @@ -98,6 +107,9 @@ def ls(args): while True: files = dbx.files_list_folder(path=args.path, recursive=args.r) for entry in files.entries: + if any(exclude.startswith(getattr(entry, 'path_display', '-')) for exclude in args.excludePaths): + continue; + print('{:>8} {:>20} {}'.format(sizeof_fmt(getattr(entry, 'size', 0)), str(getattr(entry, 'client_modified', '-')), getattr(entry, 'path_display', '-'))) @@ -116,6 +128,10 @@ def get(args): files = dbx.files_list_folder(path=args.src_path, recursive=args.r) while True: for entry in files.entries: + #skip any paths specified in --excludePaths + if any(exclude.startswith(getattr(entry, 'path_display', '-')) for exclude in args.excludePaths): + continue; + size = getattr(entry, 'size', None) # skip empty files and directories if not size: From f77dc8f2b8b1ccc08949e490cc5e0f024b70dd27 Mon Sep 17 00:00:00 2001 From: Luke Adams Date: Fri, 21 Jul 2017 13:48:43 -0400 Subject: [PATCH 2/6] removed unused lib --- pydbxcli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pydbxcli.py b/pydbxcli.py index 55ea144..81efe73 100755 --- a/pydbxcli.py +++ b/pydbxcli.py @@ -5,7 +5,6 @@ import argparse import signal import dropbox -import numpy __version__ = 0.1 From fa50174242912077510b3a51d2e0a84f842be103 Mon Sep 17 00:00:00 2001 From: Luke Adams Date: Fri, 21 Jul 2017 13:49:38 -0400 Subject: [PATCH 3/6] removed unused lib --- pydbxcli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pydbxcli.py b/pydbxcli.py index 81efe73..dd9cadf 100755 --- a/pydbxcli.py +++ b/pydbxcli.py @@ -106,6 +106,7 @@ def ls(args): while True: files = dbx.files_list_folder(path=args.path, recursive=args.r) for entry in files.entries: + #skip any paths specified in --excludePaths if any(exclude.startswith(getattr(entry, 'path_display', '-')) for exclude in args.excludePaths): continue; From d32b5d8cc2c1365667c31c22baed2374724791df Mon Sep 17 00:00:00 2001 From: Luke Adams Date: Fri, 21 Jul 2017 13:53:10 -0400 Subject: [PATCH 4/6] add usage to readme --- README.md | 5 +++++ pydbxcli.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c9a2a2b..2c00b0e 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,11 @@ Recursively list all files in Dropbox: ./pydbxcli.py ls -r / ``` +Recursively list all files in Dropbox excluding certian folders: +```bash +./pydbxcli.py ls -r '/' --excludePaths '/Team Folder/IgnoreThisFolder' '/Team Folder/IgnoreThisFolderToo' +``` + Recursively download specific Dropbox directory to local directory ```bash ./pydbxcli.py get -r /mystuff/dropbox/dir ./localdir diff --git a/pydbxcli.py b/pydbxcli.py index dd9cadf..2d0a0bb 100755 --- a/pydbxcli.py +++ b/pydbxcli.py @@ -107,7 +107,7 @@ def ls(args): files = dbx.files_list_folder(path=args.path, recursive=args.r) for entry in files.entries: #skip any paths specified in --excludePaths - if any(exclude.startswith(getattr(entry, 'path_display', '-')) for exclude in args.excludePaths): + if any(exclude.startswith(getattr(entry, 'path_display')) for exclude in args.excludePaths): continue; print('{:>8} {:>20} {}'.format(sizeof_fmt(getattr(entry, 'size', 0)), @@ -129,7 +129,7 @@ def get(args): while True: for entry in files.entries: #skip any paths specified in --excludePaths - if any(exclude.startswith(getattr(entry, 'path_display', '-')) for exclude in args.excludePaths): + if any(exclude.startswith(getattr(entry, 'path_display')) for exclude in args.excludePaths): continue; size = getattr(entry, 'size', None) From 5f7183d067d2a36bb38f6df95396f9b66635d7db Mon Sep 17 00:00:00 2001 From: John Leimgruber Date: Fri, 21 Jul 2017 16:00:01 -0400 Subject: [PATCH 5/6] Fixup excludePaths matching --- pydbxcli.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pydbxcli.py b/pydbxcli.py index 2d0a0bb..8d8abe5 100755 --- a/pydbxcli.py +++ b/pydbxcli.py @@ -48,9 +48,12 @@ def main(): default='/', help='which path from which to list') parser_ls.add_argument('--excludePaths', - nargs='*', - default=[], - help="a list of folder paths to ignore. example: --excludePaths '/Team Folders/IgnoreThisFolder' '/Team Folders/IgnoreThisFolderToo'") + nargs='*', + default=[], + help=("a list of folder paths to ignore. " + "example: --excludePaths '/Team Folders/IgnoreThisFolder' " + "'/Team Folders/IgnoreThisFolderToo'") + ) parser_ls.set_defaults(func=ls) # create the parser for the "get" command @@ -71,7 +74,10 @@ def main(): parser_ls.add_argument('--excludePaths', nargs='*', default=[], - help="a list of folder paths to ignore. example: --excludePaths '/Team Folders/IgnoreThisFolder' '/Team Folders/IgnoreThisFolderToo'") + help=("a list of folder paths to ignore. " + "example: --excludePaths '/Team Folders/IgnoreThisFolder' " + "'/Team Folders/IgnoreThisFolderToo'") + ) parser_ls.set_defaults(func=get) # parse the args and call the selected command function default to help and version @@ -106,9 +112,10 @@ def ls(args): while True: files = dbx.files_list_folder(path=args.path, recursive=args.r) for entry in files.entries: - #skip any paths specified in --excludePaths - if any(exclude.startswith(getattr(entry, 'path_display')) for exclude in args.excludePaths): - continue; + # skip any paths specified in --excludePaths + if any([path in getattr(entry, 'path_display') for path in args.excludePaths]): + print('Excluding {}'.format(getattr(entry, 'path_display'))) + continue print('{:>8} {:>20} {}'.format(sizeof_fmt(getattr(entry, 'size', 0)), str(getattr(entry, 'client_modified', '-')), @@ -128,9 +135,10 @@ def get(args): files = dbx.files_list_folder(path=args.src_path, recursive=args.r) while True: for entry in files.entries: - #skip any paths specified in --excludePaths - if any(exclude.startswith(getattr(entry, 'path_display')) for exclude in args.excludePaths): - continue; + # skip any paths specified in --excludePaths + if any([path in getattr(entry, 'path_display') for path in args.excludePaths]): + print('Excluding {}'.format(getattr(entry, 'path_display'))) + continue size = getattr(entry, 'size', None) # skip empty files and directories From 6de26ba22b06d8bdc54a25140b914c97942f4433 Mon Sep 17 00:00:00 2001 From: Luke Adams Date: Sat, 22 Jul 2017 11:02:55 -0400 Subject: [PATCH 6/6] updates to excludes folders --- pydbxcli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pydbxcli.py b/pydbxcli.py index 8d8abe5..863acf4 100755 --- a/pydbxcli.py +++ b/pydbxcli.py @@ -112,8 +112,8 @@ def ls(args): while True: files = dbx.files_list_folder(path=args.path, recursive=args.r) for entry in files.entries: - # skip any paths specified in --excludePaths - if any([path in getattr(entry, 'path_display') for path in args.excludePaths]): + #skip any paths specified in --excludePaths + if any(map(getattr(entry, 'path_display').startswith, args.excludePaths)): print('Excluding {}'.format(getattr(entry, 'path_display'))) continue @@ -136,7 +136,7 @@ def get(args): while True: for entry in files.entries: # skip any paths specified in --excludePaths - if any([path in getattr(entry, 'path_display') for path in args.excludePaths]): + if any(map(getattr(entry, 'path_display').startswith, args.excludePaths)): print('Excluding {}'.format(getattr(entry, 'path_display'))) continue