# Copyright 2026 Toyota Research Institute.  All rights reserved.

import os
import sys
import argparse
from argparse import Namespace
from glob import glob 

from anydata.converters.utils import clean_metadata, parse_args
from anydata.converters.misc.create_split import parse_create_split
from anydata.sync.sync_utils import get_seqs_subset, create_tar, aws_s3_cp, aws_s3_rm, aws_s3_sync, remove_path

#######################################################

def run():
    """Shared functionality for running the converter"""

    args = parse_args(None)
    split_name = 'split_all'

    from anydata.converters.utils import list_s3
    s3_path = f'{args.s3_path}/{args.folder}/{args.path}'
    local_path = f'{args.dst}'

    s3_files = list_s3(s3_path, suffix='.json')

    local_files = glob(f'{local_path}/*.json')
    # local_files = [os.path.basename(f) for f in local_files]

    for file in local_files:
        remove_path(file)
    for file in s3_files:
        src = f'{s3_path}/{file}'
        dst = f'{local_path}/{file}'
        aws_s3_cp(src, dst)

    print(f'#################################################')
    print(f'################## REFRESH DONE #################')
    print(f'#################################################')
    print(f'### SRC: {s3_path} : ({len(s3_files)} copied)')
    print(f'### DST: {local_path} : ({len(local_files)} deleted)')
    print(f'#################################################')

#######################################################

if __name__ == '__main__':
    run()

#######################################################

