import argparse
import os
from psf.file.psf_file import PsfFile
from manas.model2 import repository
from manas.aisample.dataset import mfile
from manas.pipeline.sdk.utils import json_utils
from manas.dataset.path_util import real_path

    
def download_model_weight(weight_path, target_path):
    hdfs_real_path = real_path(weight_path)
    if weight_path and target_path:
        mfile.copy_to_local(hdfs_real_path, target_path)
    else:
        raise Exception('model parameters is empty!')
    

def download_dataset(data_path, data_save_path):
    if data_path and data_save_path:
        try:
            hdfs_real_path = real_path(data_path)
            mfile.copy_to_local(hdfs_real_path, data_save_path)
        except Exception as exception:
            raise Exception('model weight download error !')
    else:
        raise Exception('The dataset path does not exist!')

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Download a model parameters.')
    parser.add_argument('--weight-path', type=str, help='huggingface weight path.')
    parser.add_argument('--target-path', type=str, help='The path to download the model to.')
    parser.add_argument('--data-path', type=str, help='Dataset path.')
    parser.add_argument('--data-save-path', type=str, help='Dataset file save path')
    args = parser.parse_args()
    download_model_weight(args.weight_path, args.target_path)
    download_dataset(args.data_path, args.data_save_path)