コード例 #1
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 ***")
コード例 #2
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
コード例 #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_in_linux(fol, look_for_dirs=True):
    blender_fol = ''
    if look_for_dirs:
        output = utils.get_command_output(
            "find {} -name 'blender' -type d".format(fol))
        blender_fols = output.split('\n')
        blender_fols = [
            fol for fol in blender_fols if op.isdir(fol)
            and op.isfile(op.join(utils.get_parent_fol(fol), 'blender.svg'))
            or 'blender.app' in fol
        ]
        if len(blender_fols) >= 1:
            # todo: let the user select which one
            blender_fol = utils.get_parent_fol(blender_fols[0])
    else:
        output = utils.get_command_output(
            "find {} -name 'blender'".format(fol))
        blender_fols = output.split('\n')
        blender_fols = [
            fol for fol in blender_fols
            if utils.is_link(fol) and op.isfile(op.join(fol, 'blender.svg'))
        ]
        if len(blender_fols) >= 1:
            # todo: let the user select which one
            blender_fol = blender_fols[0]
    return blender_fol
コード例 #5
0
ファイル: setup.py プロジェクト: NataliaRozengard/mmvt
def ask_and_create_link(links_fol,
                        link_name,
                        message,
                        gui=True,
                        create_default_dir=False,
                        overwrite=True):
    fol = ''
    ret = False
    if not overwrite and utils.is_link(op.join(links_fol, link_name)):
        fol = utils.get_link_dir(links_fol, link_name)
        ret = True
    else:
        choose_folder = mmvt_input(message, gui) == 'Ok'
        if choose_folder:
            root_fol = utils.get_parent_fol(links_fol)
            fol = utils.choose_folder_gui(root_fol,
                                          message) if gui else input()
            if fol != '':
                create_real_folder(fol)
                ret = utils.create_folder_link(fol,
                                               op.join(links_fol, link_name),
                                               overwrite=overwrite)
                if create_default_dir:
                    utils.make_dir(op.join(fol, 'default'))
    return fol, ret
コード例 #6
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 ***")
コード例 #7
0
def install_reqs(only_verbose=False):
    import pip
    pip.main(['install', '--upgrade', 'pip'])
    retcode = 0
    reqs_fname = op.join(utils.get_parent_fol(levels=2), 'requirements.txt')
    with open(reqs_fname, 'r') as f:
        for line in f:
            if only_verbose:
                print('Trying to install {}'.format(line.strip()))
            else:
                pipcode = pip.main(['install', line.strip()])
                retcode = retcode or pipcode
    return retcode
コード例 #8
0
ファイル: setup.py プロジェクト: NataliaRozengard/mmvt
def create_default_link(links_fol,
                        link_name,
                        default_fol_name,
                        create_default_dir=False,
                        overwrite=True):
    root_fol = utils.get_parent_fol(levels=3)
    fol = op.join(root_fol, default_fol_name)
    create_real_folder(fol)
    ret = utils.create_folder_link(fol,
                                   op.join(links_fol, link_name),
                                   overwrite=overwrite)
    if create_default_dir:
        utils.make_dir(op.join(fol, 'default'))
    return fol, ret
コード例 #9
0
ファイル: setup.py プロジェクト: Bakikii/blender-importer
def get_blender_python_exe(blender_fol, gui=True):
    blender_parent_fol = utils.get_parent_fol(blender_fol)
    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'
    return blender_bin_fol, python_exe
コード例 #10
0
ファイル: setup.py プロジェクト: NataliaRozengard/mmvt
def install_reqs(only_verbose=False):
    import pip
    try:
        from pip import main as pipmain
    except:
        from pip._internal import main as pipmain
    # if utils.is_windows() and not utils.is_admin():
    #     utils.set_admin()
    pipmain(['install', '--upgrade', 'pip'])
    retcode = 0
    reqs_fname = op.join(utils.get_parent_fol(levels=2), 'requirements.txt')
    with open(reqs_fname, 'r') as f:
        for line in f:
            if only_verbose:
                print('Trying to install {}'.format(line.strip()))
            else:
                pipcode = pipmain(['install', '--upgrade', line.strip()])
                retcode = retcode or pipcode
    return retcode