-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_to_dropbox_from_dropbox.py
42 lines (35 loc) · 1.8 KB
/
upload_to_dropbox_from_dropbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
import argparse
from tools import elastic_arguments, upload_arguments, root_arguments
from catalog import CatalogDropbox
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="""Load the given dropbox path into the catalog.
The dropbox catalog will be used, meaning that all files in the dropbox directory will be copied to
the catalog location on dropbox. It is a dropbox-to-dropbox copy operation.
Files are downloaded to the NAS copy of the catalog only if explicitly requested using the --nas flag.
The nas catalog can be syncronized also later using the sync_dropbox_to_nas tool.""")
parser.add_argument('directory', type=str, help='Full path of dropbox directory to load.')
upload_arguments(parser)
parser.add_argument('--nas', action='store_true', help='Also create the NAS copy. Defaults to FALSE')
parser.add_argument('--limit', '-l', type=int, help='Limit the number of files processed', default=None)
root_arguments(parser)
elastic_arguments(parser)
args = parser.parse_args()
index = ""
if args.index:
index = args.index
cat_folder = CatalogDropbox(args.host, args.port, index=index, nas=args.nas, verbose=not args.quiet,
dryrun=args.dryrun, move_files=args.move)
if args.nas_root:
cat_folder.nas_root = args.nas_root
if args.dropbox_root:
cat_folder.dropbox_root = args.dropbox_root
if not cat_folder.is_valid(args.directory):
print(f"Invalid directory {args.directory}")
sys.exit(-1)
c = cat_folder.catalog_dir(args.directory, recurse=args.recursive, limit=args.limit)
if not args.quiet:
if args.dryrun:
print(f"Would have added {c} files to catalog")
else:
print(f"Added {c} entries to catalog.")