Add after date command flag
This commit is contained in:
6
main.py
6
main.py
@@ -25,7 +25,9 @@ def main():
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("itemId", nargs='?', default=None, help="Item ID to download, use 0 for root")
|
parser.add_argument("itemId", nargs='?', default=None, help="Item ID to download, use 0 for root")
|
||||||
parser.add_argument("localDirectory", nargs='?', default='.', help="Local path of the item")
|
parser.add_argument("localDirectory", nargs='?', default='.', help="Local path of the item")
|
||||||
parser.add_argument("-y", "--yes", help="skip confirmation dialogue", action="store_true")
|
parser.add_argument('-a', '--after', default='0', help='Only sync items after the specified date, compared by '
|
||||||
|
'simple string comparison against such as '
|
||||||
|
'"2019-12-25T17:45:45-07:00"')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
client = Client(init_oauth())
|
client = Client(init_oauth())
|
||||||
@@ -45,7 +47,7 @@ def main():
|
|||||||
|
|
||||||
threads = []
|
threads = []
|
||||||
interrupt_flag = {'exit': False}
|
interrupt_flag = {'exit': False}
|
||||||
worker_object = Worker(q, client, settings.get('blacklist', []), interrupt_flag)
|
worker_object = Worker(q, client, settings.get('blacklist', []), interrupt_flag, args.after)
|
||||||
|
|
||||||
thread_count = settings.get('thread_count', 4)
|
thread_count = settings.get('thread_count', 4)
|
||||||
logging.info('Launching %s threads', thread_count)
|
logging.info('Launching %s threads', thread_count)
|
||||||
|
|||||||
@@ -26,11 +26,12 @@ def human_readable_bytes(b):
|
|||||||
|
|
||||||
|
|
||||||
class Worker:
|
class Worker:
|
||||||
def __init__(self, queue, client: Client, blacklist, interrupt_flag):
|
def __init__(self, queue, client: Client, blacklist, interrupt_flag, after_date):
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.client = client
|
self.client = client
|
||||||
self.blacklist = blacklist or []
|
self.blacklist = blacklist or []
|
||||||
self.interrupt_flag = interrupt_flag
|
self.interrupt_flag = interrupt_flag
|
||||||
|
self.after_date = after_date
|
||||||
self.downloaded = set()
|
self.downloaded = set()
|
||||||
self.errors = []
|
self.errors = []
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ class Worker:
|
|||||||
def do_folder(self, job: Job):
|
def do_folder(self, job: Job):
|
||||||
try:
|
try:
|
||||||
logging.info('Fetching folder [%s]', job.remote_path)
|
logging.info('Fetching folder [%s]', job.remote_path)
|
||||||
children = job.box_item.get_items(limit=5000, fields=['name', 'id', 'size', 'modified_at', 'path_collection'])
|
children = list(job.box_item.get_items(limit=5000, fields=['name', 'id', 'size', 'modified_at', 'path_collection']))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error('Fail to ls [%s]: %s: %s', job.remote_path, type(e).__name__, e)
|
logging.error('Fail to ls [%s]: %s: %s', job.remote_path, type(e).__name__, e)
|
||||||
self.errors.append(job.remote_path)
|
self.errors.append(job.remote_path)
|
||||||
@@ -60,6 +61,8 @@ class Worker:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
for child in children:
|
for child in children:
|
||||||
|
if child.modified_at < self.after_date:
|
||||||
|
continue
|
||||||
self.queue.put(Job(child, job.local_path / child.name))
|
self.queue.put(Job(child, job.local_path / child.name))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(
|
logging.error(
|
||||||
|
|||||||
Reference in New Issue
Block a user