コード例 #1
0
def install_blender_reqs():
    # http://stackoverflow.com/questions/9956741/how-to-install-multiple-python-packages-at-once-using-pip
    try:
        blender_fol = utils.get_link_dir(utils.get_links_dir(), 'blender')
        resource_fol = utils.get_resources_fol()
        # Get pip
        blender_bin_fol = op.join(utils.get_parent_fol(blender_fol), 'Resources', '2.78', 'python', 'bin') if utils.is_osx() else \
            glob.glob(op.join(blender_fol, '2.7?', 'python'))[0]
        python_exe = 'python.exe' if utils.is_windows() else 'python3.5m'
        current_dir = os.getcwd()
        os.chdir(blender_bin_fol)
        # if utils.is_osx():
        cmd = '{} {}'.format(op.join('bin', python_exe),
                             op.join(resource_fol, 'get-pip.py'))
        # elif utils.is_linux():
        #     cmd = '{} {}'.format(op.join(blender_bin_fol, 'python3.5m'), op.join(resource_fol, 'get-pip.py'))
        # else:
        #     print('No pizco for windows yet...')
        #     return
        utils.run_script(cmd)
        # install blender reqs:
        if not utils.is_windows():
            cmd = '{} install zmq pizco scipy mne joblib tqdm nibabel matplotlib'.format(
                op.join('bin', 'pip'))
            utils.run_script(cmd)
        else:
            print(
                'Sorry, installing external python libs in python will be implemented in the future'
            )
            # from src.mmvt_addon.scripts import install_blender_reqs
            # install_blender_reqs.wrap_blender_call(args.only_verbose)
        os.chdir(current_dir)
    except:
        print(traceback.format_exc())
        print("*** Can't install pizco ***")
コード例 #2
0
ファイル: setup.py プロジェクト: NataliaRozengard/mmvt
def install_blender_reqs(gui=True):
    # http://stackoverflow.com/questions/9956741/how-to-install-multiple-python-packages-at-once-using-pip
    try:
        blender_fol = utils.get_link_dir(utils.get_links_dir(), 'blender')
        resource_fol = utils.get_resources_fol()
        blender_parent_fol = utils.get_parent_fol(blender_fol)

        # Get pip
        bin_template = op.join(utils.get_parent_fol(blender_fol),  'Resources', '2.7?', 'python') if utils.is_osx() else \
            op.join(blender_fol, '2.7?', 'python')
        blender_bin_folders = sorted(glob.glob(bin_template))
        if len(blender_bin_folders) == 0:
            print("Couldn't find Blender's bin folder! ({})".format(
                bin_template))
            blender_bin_fol = ''
            choose_folder = mmvt_input(
                'Please choose the Blender bin folder where python file exists',
                gui) == 'Ok'
            if choose_folder:
                fol = utils.choose_folder_gui(
                    blender_parent_fol,
                    'Blender bin folder') if gui else input()
                if fol != '':
                    blender_bin_fol = glob.glob(op.join(fol, '2.7?',
                                                        'python'))[-1]
            if blender_bin_fol == '':
                return
        else:
            # todo: let the use select the folder if more than one
            blender_bin_fol = blender_bin_folders[-1]
        python_exe = 'python.exe' if utils.is_windows() else 'python3.5m'
        current_dir = os.getcwd()
        os.chdir(blender_bin_fol)
        # if utils.is_osx():
        # install blender reqs:
        pip_cmd = '{} {}'.format(op.join('bin', python_exe),
                                 op.join(resource_fol, 'get-pip.py'))
        reqs = 'matplotlib zmq pizco scipy mne joblib tqdm nibabel pdfkit decorator scikit-learn'
        if not utils.is_windows():
            utils.run_script(pip_cmd)
            install_cmd = '{} install {}'.format(op.join('bin', 'pip'), reqs)
            utils.run_script(install_cmd)
        else:
            # https://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script
            install_cmd = '{} install '.format(op.join('Scripts', 'pip'), reqs)
            print(
                'Sorry, automatically installing external python libs in python will be implemented in the future.\n'
                + 'Meanwhile, you can do the following:\n' +
                '1) Open a terminal window as administrator: ' +
                'Right click on the "Command Prompt" shortcut from the star menu and choose "Run as administrator"\n'
                +
                '2) Change the directory to "{}".\n'.format(blender_bin_fol) +
                '3) Run "{}"\n'.format(pip_cmd) +
                '4) Run "{}"\nGood luck!'.format(install_cmd))
            # from src.mmvt_addon.scripts import install_blender_reqs
            # install_blender_reqs.wrap_blender_call(args.only_verbose)
        os.chdir(current_dir)
    except:
        print(traceback.format_exc())
        print("*** Can't install pizco ***")
コード例 #3
0
ファイル: setup.py プロジェクト: NataliaRozengard/mmvt
def find_blender():
    blender_fol = ''
    if utils.is_windows():
        blender_win_fol = 'Program Files\Blender Foundation\Blender'
        if op.isdir(op.join('C:\\', blender_win_fol)):
            blender_fol = op.join('C:\\', blender_win_fol)
        elif op.isdir(op.join('D:\\', blender_win_fol)):
            blender_fol = op.join('D:\\', blender_win_fol)
    elif utils.is_linux():
        output = utils.run_script("find ~/ -name 'blender' -type d")
        if not isinstance(output, str):
            output = output.decode(sys.getfilesystemencoding(), 'ignore')
        blender_fols = output.split('\n')
        blender_fols = [
            fol for fol in blender_fols
            if op.isfile(op.join(utils.get_parent_fol(fol), 'blender.svg'))
            or 'blender.app' in fol
        ]
        if len(blender_fols) == 1:
            blender_fol = utils.get_parent_fol(blender_fols[0])
    elif utils.is_osx():
        blender_fol = '/Applications/Blender/blender.app/Contents/MacOS'
        # output = utils.run_script("find ~/ -name 'blender' -type d")
        # if not isinstance(output, str):
        #     output = output.decode(sys.getfilesystemencoding(), 'ignore')
        # blender_fols = output.split('\n')
        # blender_fols = [fol for fol in blender_fols if 'blender.app' in fol]
        # if len(blender_fols) == 1:
        #     blender_fol = op.join(blender_fols[0], 'blender.app', 'Contents', 'MacOS', 'blender')
    return blender_fol
コード例 #4
0
def find_blender():
    blender_fol = ''
    if utils.is_windows():
        blender_win_fol = 'Program Files\Blender Foundation\Blender'
        if op.isdir(op.join('C:\\', blender_win_fol)):
            blender_fol = op.join('C:\\', blender_win_fol)
        elif op.isdir(op.join('D:\\', blender_win_fol)):
            blender_fol = op.join('D:\\', blender_win_fol)
    else:
        output = utils.run_script("find ~/ -name 'blender' -type d")
        if not isinstance(output, str):
            output = output.decode(sys.getfilesystemencoding(), 'ignore')
        blender_fols = output.split('\n')
        blender_fols = [
            fol for fol in blender_fols
            if op.isfile(op.join(utils.get_parent_fol(fol), 'blender.svg'))
            or 'blender.app' in fol
        ]
        if len(blender_fols) == 1:
            blender_fol = utils.get_parent_fol(blender_fols[0])
        # if 'users' in sys.executable:
        #     path_split = sys.executable.split(op.sep)
        #     ind = path_split.index('users')
        #     root_path = op.sep.join(path_split[:ind+2])
        #     output = utils.run_script("find {} -name 'blender' -type d".format(root_path))
    return blender_fol
コード例 #5
0
ファイル: setup.py プロジェクト: XujiahuaBNU/mmvt
def find_blender():
    blender_fol = ''
    if utils.is_windows():
        blender_win_fol = 'Program Files\Blender Foundation\Blender*'
        for drive in ['C', 'D']:
            if len(glob.glob(op.join('{}:\\'.format(drive),
                                     blender_win_fol))) > 0:
                blender_fol = select_file(
                    glob.glob(op.join('{}:\\'.format(drive), blender_win_fol)))
                break
    elif utils.is_linux():
        blender_fol = find_blender_in_linux('../', False)
        if blender_fol == '':
            blender_fol = find_blender_in_linux('../../')
        if blender_fol == '':
            blender_fol = find_blender_in_linux('~/')
    elif utils.is_osx():
        blender_fol = '/Applications/Blender/blender.app/Contents/MacOS'
        blender_fol = blender_fol if op.isdir(blender_fol) else ''
        # output = utils.run_script("find ~/ -name 'blender' -type d")
        # if not isinstance(output, str):
        #     output = output.decode(sys.getfilesystemencoding(), 'ignore')
        # blender_fols = output.split('\n')
        # blender_fols = [fol for fol in blender_fols if 'blender.app' in fol]
        # if len(blender_fols) == 1:
        #     blender_fol = op.join(blender_fols[0], 'blender.app', 'Contents', 'MacOS', 'blender')
    return blender_fol
コード例 #6
0
def install_blender_reqs(blender_fol='', gui=True):
    # http://stackoverflow.com/questions/9956741/how-to-install-multiple-python-packages-at-once-using-pip
    try:
        if blender_fol == '':
            blender_fol = utils.get_link_dir(utils.get_links_dir(), 'blender')
        resource_fol = utils.get_resources_fol()
        blender_bin_fol, python_exe = get_blender_python_exe(blender_fol, gui)
        current_dir = os.getcwd()
        os.chdir(blender_bin_fol)
        # install blender reqs:
        pip_cmd = '{} {}'.format(op.join('bin', python_exe),
                                 op.join(resource_fol, 'get-pip.py'))
        reqs = 'matplotlib zmq pizco scipy mne joblib tqdm nibabel pdfkit decorator scikit-learn'
        if not utils.is_windows():
            utils.run_script(pip_cmd)
            install_cmd = '{} install {}'.format(op.join('bin', 'pip'), reqs)
            utils.run_script(install_cmd)
        else:
            # https://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script
            install_cmd = '{} install '.format(op.join('Scripts', 'pip'), reqs)
            print(
                'Sorry, automatically installing external python libs in python will be implemented in the future.\n'
                + 'Meanwhile, you can do the following:\n' +
                '1) Open a terminal window as administrator: ' +
                'Right click on the "Command Prompt" shortcut from the star menu and choose "Run as administrator"\n'
                +
                '2) Change the directory to "{}".\n'.format(blender_bin_fol) +
                '3) Run "{}"\n'.format(pip_cmd) +
                '4) Run "{}"\nGood luck!'.format(install_cmd))
            # from src.mmvt_addon.scripts import install_blender_reqs
            # install_blender_reqs.wrap_blender_call(args.only_verbose)
        os.chdir(current_dir)
    except:
        print(traceback.format_exc())
        print("*** Can't install pizco ***")
コード例 #7
0
ファイル: setup.py プロジェクト: alexrockhill/mmvt
def get_blender_python_exe(blender_fol, gui=True):
    bin_template = op.join(blender_fol, '..', 'Resources', '2.7?', 'python') if utils.is_osx() else \
        op.join(blender_fol, '2.7?', 'python')
    blender_bin_folders = sorted(glob.glob(bin_template))
    if len(blender_bin_folders) == 0:
        print("Couldn't find Blender's bin folder! ({})".format(bin_template))
        blender_bin_fol = ''
        choose_folder = mmvt_input(
            'Please choose the Blender bin folder where python file exists',
            gui) == 'Ok'
        if choose_folder:
            fol = utils.choose_folder_gui(
                blender_parent_fol, 'Blender bin folder') if gui else input()
            if fol != '':
                blender_bin_fol = glob.glob(op.join(fol, '2.7?', 'python'))[-1]
        if blender_bin_fol == '':
            return '', ''
    else:
        # todo: let the use select the folder if more than one
        blender_bin_fol = blender_bin_folders[-1]
    python_exe = 'python.exe' if utils.is_windows() else 'python3.5m'
    return blender_bin_fol, python_exe
コード例 #8
0
ファイル: setup.py プロジェクト: NataliaRozengard/mmvt
def create_links(links_fol_name='links',
                 gui=True,
                 default_folders=False,
                 only_verbose=False,
                 links_file_name='links.csv',
                 overwrite=True):
    links_fol = utils.get_links_dir(links_fol_name)
    if only_verbose:
        print('making links dir {}'.format(links_fol))
    else:
        utils.make_dir(links_fol)
    links_names = [
        'blender', 'mmvt', 'subjects', 'eeg', 'meg', 'fMRI', 'electrodes'
    ]
    # if not utils.is_windows():
    #     links_names.insert(1, 'subjects')
    if not overwrite:
        all_links_exist = utils.all([
            utils.is_link(op.join(links_fol, link_name))
            for link_name in links_names
        ])
        if all_links_exist:
            print('All links exist!')
            links = {
                link_name: utils.get_link_dir(links_fol, link_name)
                for link_name in links_names
            }
            write_links_into_csv_file(links, links_fol, links_file_name)
            return True
    if not utils.is_windows() and not utils.is_link(
            op.join(links_fol, 'freesurfer')):
        if os.environ.get('FREESURFER_HOME', '') == '':
            print(
                'If you are going to use FreeSurfer locally, please source it and rerun'
            )
            # If you choose to continue, you'll need to create a link to FreeSurfer manually")
            cont = input("Do you want to continue (y/n)?")
            if cont.lower() != 'y':
                return
        else:
            freesurfer_fol = os.environ['FREESURFER_HOME']
            if not only_verbose:
                create_real_folder(freesurfer_fol)

    mmvt_message = 'Please select where do you want to put the blend files '
    subjects_message = \
        'Please select where do you want to store the FreeSurfer recon-all files neccessary for MMVT.\n' + \
        '(It is prefered to create a local folder, because MMVT is going to save files to this directory) '
    blender_message = 'Please select where did you install Blender '
    meg_message = 'Please select where do you want to put the MEG files (Cancel if you are not going to use MEG data) '
    eeg_message = 'Please select where do you want to put the EEG files (Cancel if you are not going to use EEG data) '
    fmri_message = 'Please select where do you want to put the fMRI files (Cancel if you are not going to use fMRI data) '
    electrodes_message = 'Please select where do you want to put the electrodes files (Cancel if you are not going to use electrodes data) '

    blender_fol = find_blender()
    if blender_fol != '':
        utils.create_folder_link(blender_fol, op.join(links_fol, 'blender'),
                                 overwrite)
    else:
        ask_and_create_link(links_fol, 'blender', blender_message, gui,
                            overwrite)
    default_message = "Would you like to set default links to the MMVT's folders?\n" + \
        "You can always change that later by running\n" + \
        "python -m src.setup -f create_links"
    create_default_folders = default_folders or mmvt_input(
        default_message, gui, 4) == 'Yes'

    messages = [
        mmvt_message, subjects_message, eeg_message, meg_message, fmri_message,
        electrodes_message
    ]
    deafault_fol_names = [
        'mmvt_blend', 'subjects', 'eeg', 'meg', 'fMRI', 'electrodes'
    ]
    # if not utils.is_windows():
    #     messages.insert(0, subjects_message)
    create_default_dirs = [False] * 3 + [True] * 2 + [False] * 2

    links = {}
    if not only_verbose:
        for link_name, default_fol_name, message, create_default_dir in zip(
                links_names[1:], deafault_fol_names, messages,
                create_default_dirs):
            fol = ''
            if not create_default_folders:
                fol, ret = ask_and_create_link(links_fol,
                                               link_name,
                                               message,
                                               gui,
                                               create_default_dir,
                                               overwrite=overwrite)
            if fol == '' or create_default_folders:
                fol, ret = create_default_link(links_fol,
                                               link_name,
                                               default_fol_name,
                                               create_default_dir,
                                               overwrite=overwrite)
            if ret:
                print('The "{}" link was created to {}'.format(link_name, fol))
            links[link_name] = fol

    links = get_all_links(links, links_fol)
    write_links_into_csv_file(links, links_fol, links_file_name)
    return utils.all([
        utils.is_link(op.join(links_fol, link_name))
        for link_name in links_names
    ])