-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_nas_to_dropbox.py
41 lines (35 loc) · 1.44 KB
/
sync_nas_to_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
import argparse
from tools import elastic_arguments, root_arguments
from catalog import CatalogFiles
from elastic import Retrieve
from data import DBoxError
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="""Scan the catalog for entries where the NAS copy is there
but the dropbox copy is not yet available.""")
parser.add_argument('--limit', '-l', type=int, help='Just do it for so many files', default=0)
parser.add_argument('--verbose', '-v', action='store_true', help='Verbose output, print each file name copied')
root_arguments(parser)
elastic_arguments(parser)
args = parser.parse_args()
index = ""
if args.index:
index = args.index
cat_folder = CatalogFiles(args.host, args.port, index=index, dropbox=True)
retrieve = Retrieve(cat_folder.connection)
if args.nas_root:
cat_folder.nas_root = args.nas_root
if args.dropbox_root:
cat_folder.dropbox_root = args.dropbox_root
n = 0
for entry in retrieve.on_nas_but_not_on_dropbox(args.limit):
entry.prepend_original_path(cat_folder.nas_root)
try:
cat_folder.copy_item_to_dropbox(entry)
except DBoxError as e:
print("Ignoring : ", str(e))
else:
cat_folder.update({"dropbox": True}, entry.id)
n += 1
if args.verbose:
print(f"Copied {entry.full_path}")
print(f"Copied {n} entries from NAS to dropbox.")