Exemplo n.º 1
0
def get_all_links(links={}, links_fol=None, links_fol_name='links'):
    if links_fol is None:
        links_fol = utils.get_links_dir(links_fol_name)
    all_links = [
        utils.namebase(f) for f in glob.glob(op.join(links_fol, '*'))
        if utils.is_link(f)
    ]
    all_links = {
        link_name: utils.get_link_dir(links_fol, link_name)
        for link_name in all_links if link_name not in links
    }
    links = utils.merge_two_dics(links, all_links)
    return links
Exemplo n.º 2
0
def copy_resources_files(mmvt_root_dir, overwrite=True, only_verbose=False):
    resource_dir = utils.get_resources_fol()
    utils.make_dir(op.join(op.join(mmvt_root_dir, 'color_maps')))
    files = [
        'aparc.DKTatlas40_groups.csv', 'atlas.csv', 'sub_cortical_codes.txt',
        'FreeSurferColorLUT.txt', 'empty_subject.blend', 'high_level_atlas.csv'
    ]
    cm_files = glob.glob(op.join(resource_dir, 'color_maps', '*.npy'))
    all_files_exist = utils.all(
        [op.isfile(op.join(mmvt_root_dir, file_name)) for file_name in files])
    all_cm_files_exist = utils.all([
        op.isfile(
            op.join(mmvt_root_dir, 'color_maps',
                    '{}.npy'.format(utils.namebase(fname))))
        for fname in cm_files
    ])
    if all_files_exist and all_cm_files_exist and not overwrite:
        if only_verbose:
            print('All files exist!')
        return True
    if not all_cm_files_exist or overwrite:
        for color_map_file in glob.glob(
                op.join(resource_dir, 'color_maps', '*.npy')):
            new_file_name = op.join(mmvt_root_dir, 'color_maps',
                                    color_map_file.split(op.sep)[-1])
            # print('Copy {} to {}'.format(color_map_file, new_file_name))
            print('Coping {} to {}'.format(color_map_file, new_file_name))
            if not only_verbose:
                try:
                    shutil.copy(color_map_file, new_file_name)
                except:
                    print('Can\'t copy {} to {}!'.format(
                        color_map_file, new_file_name))
    if not all_files_exist or overwrite:
        for file_name in files:
            print('Copying {} to {}'.format(op.join(resource_dir, file_name),
                                            op.join(mmvt_root_dir, file_name)))
            if not only_verbose:
                local_fname = op.join(resource_dir, file_name)
                if op.isfile(op.join(resource_dir, file_name)):
                    try:
                        shutil.copy(local_fname,
                                    op.join(mmvt_root_dir, file_name))
                    except:
                        print('Can\'t copy {}'.format(file_name))
                else:
                    print(
                        '{} is missing, please update your code from github (git pull)'
                        .format(op.join(resource_dir, file_name)))
    return utils.all(
        [op.isfile(op.join(mmvt_root_dir, file_name)) for file_name in files])
Exemplo n.º 3
0
def copy_resources_files(mmvt_root_dir, only_verbose=False):
    resource_dir = utils.get_resources_fol()
    utils.make_dir(op.join(op.join(mmvt_root_dir, 'color_maps')))
    files = [
        'aparc.DKTatlas40_groups.csv', 'atlas.csv', 'sub_cortical_codes.txt',
        'FreeSurferColorLUT.txt', 'empty_subject.blend', 'high_level_atlas.csv'
    ]
    cm_files = glob.glob(op.join(resource_dir, 'color_maps', '*.npy'))
    all_files_exist = utils.all(
        [op.isfile(op.join(mmvt_root_dir, file_name)) for file_name in files])
    all_cm_files_exist = utils.all([
        op.isfile(
            op.join(mmvt_root_dir, 'color_maps',
                    '{}.npy'.format(utils.namebase(fname))))
        for fname in cm_files
    ])
    if all_files_exist and all_cm_files_exist:
        if only_verbose:
            print('All files exist!')
        return True
    if not all_cm_files_exist:
        for color_map_file in glob.glob(
                op.join(resource_dir, 'color_maps', '*.npy')):
            new_file_name = op.join(mmvt_root_dir, 'color_maps',
                                    color_map_file.split(op.sep)[-1])
            # print('Copy {} to {}'.format(color_map_file, new_file_name))
            if only_verbose:
                print('Coping {} to {}'.format(color_map_file, new_file_name))
            else:
                shutil.copy(color_map_file, new_file_name)
    if not all_files_exist:
        for file_name in files:
            if only_verbose:
                print('Copying {} to {}'.format(
                    op.join(resource_dir, file_name),
                    op.join(mmvt_root_dir, file_name)))
            else:
                shutil.copy(op.join(resource_dir, file_name),
                            op.join(mmvt_root_dir, file_name))
    return utils.all(
        [op.isfile(op.join(mmvt_root_dir, file_name)) for file_name in files])