Пример #1
0
def install(robustus, requirement_specifier, rob_file, ignore_index):
    patchelf_cache_dir = os.path.abspath(os.path.join(robustus.cache, 'patchelf-%s' % requirement_specifier.version))

    def in_cache():
        return os.path.isfile(os.path.join(patchelf_cache_dir, 'patchelf'))

    cwd = os.getcwd()
    if not in_cache() and not ignore_index:
        logging.info('Downloading patchelf')
        patchelf_tgz = robustus.download('patchelf', requirement_specifier.version)
        patchelf_archive_name = unpack(patchelf_tgz)

        logging.info('Building patchelf')
        os.chdir(patchelf_archive_name)
        run_shell(['./bootstrap.sh'], verbose=robustus.settings['verbosity'] >= 1)
        run_shell(['./configure'], verbose=robustus.settings['verbosity'] >= 1)
        run_shell(['make'], verbose=robustus.settings['verbosity'] >= 1)

        if os.path.isdir(patchelf_cache_dir):
            shutil.rmtree(patchelf_cache_dir)
        os.mkdir(patchelf_cache_dir)
        cp('./src/patchelf', patchelf_cache_dir)

        os.chdir(os.path.pardir)
        os.remove(patchelf_tgz)
        shutil.rmtree(patchelf_archive_name)
    os.chdir(cwd)

    if in_cache():
        patchelf_install_dir = os.path.join(robustus.env, 'bin')
        cp(os.path.join(patchelf_cache_dir, 'patchelf'), patchelf_install_dir)
    else:
        raise RequirementException('can\'t find patchelf-%s in robustus cache' % requirement_specifier.version)
Пример #2
0
def install(robustus, requirement_specifier, rob_file, ignore_index):
    patchelf_cache_dir = os.path.abspath(
        os.path.join(robustus.cache,
                     'patchelf-%s' % requirement_specifier.version))

    def in_cache():
        return os.path.isfile(os.path.join(patchelf_cache_dir, 'patchelf'))

    cwd = os.getcwd()
    if not in_cache() and not ignore_index:
        logging.info('Downloading patchelf')
        patchelf_tgz = robustus.download('patchelf',
                                         requirement_specifier.version)
        patchelf_archive_name = unpack(patchelf_tgz)

        logging.info('Building patchelf')
        os.chdir(patchelf_archive_name)
        run_shell(['./bootstrap.sh'],
                  verbose=robustus.settings['verbosity'] >= 1)
        run_shell(['./configure'], verbose=robustus.settings['verbosity'] >= 1)
        run_shell(['make'], verbose=robustus.settings['verbosity'] >= 1)

        if os.path.isdir(patchelf_cache_dir):
            shutil.rmtree(patchelf_cache_dir)
        os.mkdir(patchelf_cache_dir)
        cp('./src/patchelf', patchelf_cache_dir)

        os.chdir(os.path.pardir)
        os.remove(patchelf_tgz)
        shutil.rmtree(patchelf_archive_name)
    os.chdir(cwd)

    if in_cache():
        patchelf_install_dir = os.path.join(robustus.env, 'bin')
        cp(os.path.join(patchelf_cache_dir, 'patchelf'), patchelf_install_dir)
    else:
        raise RequirementException(
            'can\'t find patchelf-%s in robustus cache' %
            requirement_specifier.version)
Пример #3
0
def install(robustus, requirement_specifier, rob_file, ignore_index):
    '''
    Opencv has a lot of cmake flags. Here are some examples to play with:
    brew configuration for opencv 2.4.9:
                    '-DCMAKE_OSX_DEPLOYMENT_TARGET=',
                    '-DBUILD_ZLIB=OFF',
                    '-DBUILD_TIFF=OFF',
                    '-DBUILD_PNG=OFF',
                    '-DBUILD_OPENEXR=OFF',
                    '-DBUILD_JASPER=OFF',
                    '-DBUILD_JPEG=OFF',
                    '-DJPEG_INCLUDE_DIR=/usr/local/opt/jpeg/include',
                    '-DJPEG_LIBRARY=/usr/local/opt/jpeg/lib/libjpeg.dylib',
                    '-DPYTHON_LIBRARY=/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/Python',
                    '-DPYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/Headers',
                    '-DBUILD_TESTS=OFF',
                    '-DBUILD_PERF_TESTS=OFF',
                    '-DBUILD_opencv_java=OFF',
                    '-DWITH_QT=OFF',
                    '-DWITH_TBB=OFF',
                    '-DWITH_FFMPEG=OFF',
                    '-DWITH_OPENEXR=OFF',
                    '-DWITH_CUDA=OFF',
                    '-DWITH_OPENCL=OFF',
                    '-DENABLE_SSSE3=ON',
                    '-DENABLE_SSE41=ON',
                    '-DENABLE_SSE42=ON',
                    '-DENABLE_AVX=ON',
    '''
    # Make sure numpy is installed - to avoid weird error when bindings
    # are silently not generated.
    if not check_module_available(robustus.env, 'numpy'):
        raise RequirementException('numpy is required for opencv')
    
    if platform.linux_distribution()[0] == 'CentOS':
        # linking opencv for CentOs
        logging.info('Linking opencv for CentOS')
        os.symlink('/usr/lib64/python2.7/site-packages/cv2.so', os.path.join(robustus.env, 'lib/python2.7/site-packages/cv2.so'))
        os.symlink('/usr/lib64/python2.7/site-packages/cv.py', os.path.join(robustus.env, 'lib/python2.7/site-packages/cv.py'))
    else:
        cv_install_dir = os.path.join(robustus.cache, 'OpenCV-%s' % requirement_specifier.version)
        cv2so = os.path.join(cv_install_dir, 'lib/python2.7/site-packages/cv2.so')

        def in_cache():
            return os.path.isfile(cv2so)

        versions_to_fix_rpath = ['2.4.7', '2.4.8', '2.4.9']

        if not in_cache() and not ignore_index:
            cwd = os.getcwd()
            opencv_archive = None
            opencv_archive_name = None
                
            try:
                opencv_archive = robustus.download_compiled_archive('OpenCV', requirement_specifier.version)

                if opencv_archive is not None:
                    opencv_archive_name = unpack(opencv_archive)

                    logging.info('Initializing compiled OpenCV')
                    # install into wheelhouse
                    safe_move(opencv_archive_name, cv_install_dir)
                else:
                    opencv_archive = robustus.download('OpenCV', requirement_specifier.version)
                    opencv_archive_name = unpack(opencv_archive)

                    logging.info('Building OpenCV')
                    cv_build_dir = os.path.join(opencv_archive_name, 'build')
                    if not os.path.isdir(cv_build_dir):
                        os.mkdir(cv_build_dir)
                    os.chdir(cv_build_dir)

                    opencv_cmake_call_args = [
                        'cmake',
                        '../',
                        '-DPYTHON_EXECUTABLE=%s' % robustus.python_executable,
                        '-DBUILD_NEW_PYTHON_SUPPORT=ON',
                        '-DBUILD_TESTS=OFF',
                        '-DBUILD_PERF_TESTS=OFF',
                        '-DBUILD_DOCS=OFF',
                        '-DBUILD_opencv_apps=OFF',
                        '-DBUILD_opencv_java=OFF',
                        '-DWITH_CUDA=OFF',
                        '-DCMAKE_INSTALL_PREFIX=%s' % cv_install_dir]

                    if sys.platform.startswith('darwin'):
                        python_lib_path = subprocess.check_output(['python-config', '--prefix']).strip()
                        opencv_cmake_call_args.append('-DPYTHON_LIBRARY=%s/Python' % python_lib_path)
                        opencv_cmake_call_args.append('-DPYTHON_INCLUDE_DIR=%s/Headers' % python_lib_path)

                    run_shell(opencv_cmake_call_args,
                              verbose=robustus.settings['verbosity'] >= 1)
                    retcode = run_shell(['make', '-j4'], verbose=robustus.settings['verbosity'] >= 1)
                    if retcode != 0:
                        raise RequirementException('OpenCV build failed')

                    # install into wheelhouse
                    if not os.path.isdir(cv_install_dir):
                        os.mkdir(cv_install_dir)
                    retcode = run_shell(['make', 'install'], verbose=robustus.settings['verbosity'] >= 1)
                    if retcode != 0:
                        raise RequirementException('OpenCV installation failed')

            finally:
                safe_remove(opencv_archive)
                safe_remove(opencv_archive_name)
                os.chdir(cwd)

            if in_cache() and requirement_specifier.version in versions_to_fix_rpath:
                # fix rpath for all dynamic libraries of cv2
                all_cv_dlibs = os.path.abspath(os.path.join(cv_install_dir, 'lib'))
                if sys.platform.startswith('darwin'):
                    libs = glob.glob(os.path.join(all_cv_dlibs, '*.dylib'))
                else:
                    libs = glob.glob(os.path.join(all_cv_dlibs, '*.so'))
                for lib in libs:
                    fix_rpath(robustus, robustus.env, lib, cv_install_dir)

        if in_cache():
            logging.info('Copying OpenCV cv2.so to virtualenv')
            cp(os.path.join(cv_install_dir, 'lib/python2.7/site-packages/*'),
               os.path.join(robustus.env, 'lib/python2.7/site-packages'))
            if requirement_specifier.version in versions_to_fix_rpath:
                # fix rpath for cv2
                cv2lib = os.path.join(robustus.env, 'lib/python2.7/site-packages/cv2.so')
                fix_rpath(robustus, robustus.env, cv2lib, cv_install_dir)  
        else:
            raise RequirementException('can\'t find OpenCV-%s in robustus cache' % requirement_specifier.version)
Пример #4
0
def install(robustus, requirement_specifier, rob_file, ignore_index):
    ni_install_dir = os.path.join(robustus.cache, 'OpenNI2')
    if requirement_specifier.version is not None:
        ni_install_dir += requirement_specifier.version

    def in_cache():
        return os.path.isfile(os.path.join(ni_install_dir, 'libOpenNI2.so'))

    if not in_cache() and not ignore_index:
        cwd = os.getcwd()
        ni_clone_dir = os.path.join(cwd, 'OpenNI2')

        try:
            if os.path.isdir(ni_clone_dir):
                logging.warn(
                    'Directory for cloning OpenNI found, cloning skipped')
            else:
                logging.info('Cloning OpenNI')
                retcode = run_shell([
                    'git', 'clone', 'https://github.com/occipital/OpenNI2.git'
                ])
                if retcode != 0:
                    raise RequirementException('OpenNI2 clone failed')
            os.chdir(ni_clone_dir)

            # checkout requested version
            branch = requirement_specifier.version if requirement_specifier.version is not None else 'master'
            if requirement_specifier.version is not None:
                retcode = run_shell(['git', 'checkout', branch])
                if retcode != 0:
                    raise RequirementException('OpenNI2 checkout failed')

            logging.info('Building OpenNI')
            if platform.machine().startswith('arm'):
                ver = 'Arm'
                # patch flags for arm
                file_to_patch = os.path.join(
                    ni_clone_dir,
                    'ThirdParty/PSCommon/BuildSystem/Platform.Arm')
                with open(file_to_patch, "rt") as f:
                    content = f.read()
                with open(file_to_patch, "wt") as f:
                    f.write(content.replace('-mfloat-abi=softfp', ''))
            elif platform.architecture()[0].startswith('64'):
                ver = 'x64'
            else:
                ver = 'x86'
            retcode = run_shell(['make', 'PLATFORM=' + ver],
                                verbose=robustus.settings['verbosity'] >= 1)
            if retcode != 0:
                raise RequirementException('OpenNI2 build failed')

            # copy release dir and usb rules to wheelhouse
            if os.path.isdir(ni_install_dir):
                shutil.rmtree(ni_install_dir)
            release_dir = os.path.join(ni_clone_dir, 'Bin', ver + '-Release')
            shutil.copytree(release_dir, ni_install_dir)
            cp(
                os.path.join(ni_clone_dir,
                             'Packaging/Linux/primesense-usb.rules'),
                ni_install_dir)
        finally:
            os.chdir(cwd)
            safe_remove(ni_clone_dir)

    # copy files to venv
    if in_cache():
        logging.info('Copying OpenNI2 to virtualenv')
        cp(os.path.join(ni_install_dir, '*.so'),
           os.path.join(robustus.env, 'lib'))
        cp(os.path.join(ni_install_dir, '*.jar'),
           os.path.join(robustus.env, 'lib'))
        ni_drivers_dir = os.path.join(robustus.env, 'lib/OpenNI2')
        if os.path.isdir(ni_drivers_dir):
            shutil.rmtree(ni_drivers_dir)
        shutil.copytree(os.path.join(ni_install_dir, 'OpenNI2'),
                        ni_drivers_dir)
        # copy demo for testing purposes
        cp(os.path.join(ni_install_dir, 'SimpleRead'),
           os.path.join(robustus.env, 'bin'))
        fix_rpath(robustus, robustus.env,
                  os.path.join(robustus.env, 'bin/SimpleRead'),
                  os.path.join(robustus.env, 'lib'))
        # setup usb rules
        logging.info(
            'Configuring udev rules, you may need to reconnect sensor or restart computer'
        )
        retcode = run_shell([
            'sudo', 'cp',
            os.path.join(ni_install_dir, 'primesense-usb.rules'),
            '/etc/udev/rules.d/557-primesense-usb.rules'
        ],
                            verbose=robustus.settings['verbosity'] >= 1)
        if retcode != 0:
            raise RequirementException('Faied to copy udev rules')
        # return nonzero code, but seems to work
        subprocess.call(['sudo', 'udevadm', 'control', '--reload-rules'])
    else:
        raise RequirementException('can\'t find OpenNI2-%s in robustus cache' %
                                   requirement_specifier.version)
Пример #5
0
def install(robustus, requirement_specifier, rob_file, ignore_index):
    ni_install_dir = os.path.join(robustus.cache, 'OpenNI2')
    if requirement_specifier.version is not None:
        ni_install_dir += requirement_specifier.version

    def in_cache():
        return os.path.isfile(os.path.join(ni_install_dir, 'libOpenNI2.so'))

    if not in_cache() and not ignore_index:
        cwd = os.getcwd()
        ni_clone_dir = os.path.join(cwd, 'OpenNI2')

        try:
            if os.path.isdir(ni_clone_dir):
                logging.warn('Directory for cloning OpenNI found, cloning skipped')
            else:
                logging.info('Cloning OpenNI')
                retcode = run_shell(['git', 'clone', 'https://github.com/occipital/OpenNI2.git'])
                if retcode != 0:
                    raise RequirementException('OpenNI2 clone failed')
            os.chdir(ni_clone_dir)

            # checkout requested version
            branch = requirement_specifier.version if requirement_specifier.version is not None else 'master'
            if requirement_specifier.version is not None:
                retcode = run_shell(['git', 'checkout', branch])
                if retcode != 0:
                    raise RequirementException('OpenNI2 checkout failed')

            logging.info('Building OpenNI')
            if platform.machine().startswith('arm'):
                ver = 'Arm'
                # patch flags for arm
                file_to_patch = os.path.join(ni_clone_dir, 'ThirdParty/PSCommon/BuildSystem/Platform.Arm')
                with open(file_to_patch, "rt") as f:
                    content = f.read()
                with open(file_to_patch, "wt") as f:
                    f.write(content.replace('-mfloat-abi=softfp', ''))
            elif platform.architecture()[0].startswith('64'):
                ver = 'x64'
            else:
                ver = 'x86'
            retcode = run_shell(['make', 'PLATFORM=' + ver], verbose=robustus.settings['verbosity'] >= 1)
            if retcode != 0:
                raise RequirementException('OpenNI2 build failed')

            # copy release dir and usb rules to wheelhouse
            if os.path.isdir(ni_install_dir):
                shutil.rmtree(ni_install_dir)
            release_dir = os.path.join(ni_clone_dir, 'Bin', ver + '-Release')
            shutil.copytree(release_dir, ni_install_dir)
            cp(os.path.join(ni_clone_dir, 'Packaging/Linux/primesense-usb.rules'), ni_install_dir)
        finally:
            os.chdir(cwd)
            safe_remove(ni_clone_dir)

    # copy files to venv
    if in_cache():
        logging.info('Copying OpenNI2 to virtualenv')
        cp(os.path.join(ni_install_dir, '*.so'), os.path.join(robustus.env, 'lib'))
        cp(os.path.join(ni_install_dir, '*.jar'), os.path.join(robustus.env, 'lib'))
        ni_drivers_dir = os.path.join(robustus.env, 'lib/OpenNI2')
        if os.path.isdir(ni_drivers_dir):
            shutil.rmtree(ni_drivers_dir)
        shutil.copytree(os.path.join(ni_install_dir, 'OpenNI2'), ni_drivers_dir)
        # copy demo for testing purposes
        cp(os.path.join(ni_install_dir, 'SimpleRead'), os.path.join(robustus.env, 'bin'))
        fix_rpath(robustus, robustus.env, os.path.join(robustus.env, 'bin/SimpleRead'), os.path.join(robustus.env, 'lib'))  
        # setup usb rules
        logging.info('Configuring udev rules, you may need to reconnect sensor or restart computer')
        retcode = run_shell(['sudo', 'cp', os.path.join(ni_install_dir, 'primesense-usb.rules'), '/etc/udev/rules.d/557-primesense-usb.rules'], verbose=robustus.settings['verbosity'] >= 1)
        if retcode != 0:
            raise RequirementException('Faied to copy udev rules')
        # return nonzero code, but seems to work
        subprocess.call(['sudo', 'udevadm', 'control', '--reload-rules'])
    else:
        raise RequirementException('can\'t find OpenNI2-%s in robustus cache' % requirement_specifier.version)
Пример #6
0
def install(robustus, requirement_specifier, rob_file, ignore_index):
    '''
    Opencv has a lot of cmake flags. Here are some examples to play with:
    brew configuration for opencv 2.4.9:
                    '-DCMAKE_OSX_DEPLOYMENT_TARGET=',
                    '-DBUILD_ZLIB=OFF',
                    '-DBUILD_TIFF=OFF',
                    '-DBUILD_PNG=OFF',
                    '-DBUILD_OPENEXR=OFF',
                    '-DBUILD_JASPER=OFF',
                    '-DBUILD_JPEG=OFF',
                    '-DJPEG_INCLUDE_DIR=/usr/local/opt/jpeg/include',
                    '-DJPEG_LIBRARY=/usr/local/opt/jpeg/lib/libjpeg.dylib',
                    '-DPYTHON_LIBRARY=/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/Python',
                    '-DPYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/Headers',
                    '-DBUILD_TESTS=OFF',
                    '-DBUILD_PERF_TESTS=OFF',
                    '-DBUILD_opencv_java=OFF',
                    '-DWITH_QT=OFF',
                    '-DWITH_TBB=OFF',
                    '-DWITH_FFMPEG=OFF',
                    '-DWITH_OPENEXR=OFF',
                    '-DWITH_CUDA=OFF',
                    '-DWITH_OPENCL=OFF',
                    '-DENABLE_SSSE3=ON',
                    '-DENABLE_SSE41=ON',
                    '-DENABLE_SSE42=ON',
                    '-DENABLE_AVX=ON',
    '''
    # Make sure numpy is installed - to avoid weird error when bindings
    # are silently not generated.
    if not check_module_available(robustus.env, 'numpy'):
        raise RequirementException('numpy is required for opencv')
    
    if platform.linux_distribution()[0] == 'CentOS':
        # linking opencv for CentOs
        logging.info('Linking opencv for CentOS')
        os.symlink('/usr/lib64/python2.7/site-packages/cv2.so', os.path.join(robustus.env, 'lib/python2.7/site-packages/cv2.so'))
        os.symlink('/usr/lib64/python2.7/site-packages/cv.py', os.path.join(robustus.env, 'lib/python2.7/site-packages/cv.py'))
    else:
        cv_install_dir = os.path.join(robustus.cache, 'OpenCV-%s' % requirement_specifier.version)
        cv2so = os.path.join(cv_install_dir, 'lib/python2.7/site-packages/cv2.so')

        def in_cache():
            return os.path.isfile(cv2so)

        if not in_cache() and not ignore_index:
            cwd = os.getcwd()
            opencv_archive = None
            opencv_archive_name = None

            try:
                opencv_archive = robustus.download_compiled_archive('OpenCV', requirement_specifier.version)

                if opencv_archive is not None:
                    opencv_archive_name = unpack(opencv_archive)

                    logging.info('Initializing compiled OpenCV')
                    # install into wheelhouse
                    safe_move(opencv_archive_name, cv_install_dir)
                else:
                    opencv_archive = robustus.download('OpenCV', requirement_specifier.version)
                    opencv_archive_name = unpack(opencv_archive)

                    logging.info('Building OpenCV')
                    cv_build_dir = os.path.join(opencv_archive_name, 'build')
                    if not os.path.isdir(cv_build_dir):
                        os.mkdir(cv_build_dir)
                    os.chdir(cv_build_dir)

                    opencv_cmake_call_args = [
                        'cmake',
                        '../',
                        '-DPYTHON_EXECUTABLE=%s' % robustus.python_executable,
                        '-DBUILD_NEW_PYTHON_SUPPORT=ON',
                        '-DBUILD_TESTS=OFF',
                        '-DBUILD_PERF_TESTS=OFF',
                        '-DBUILD_DOCS=OFF',
                        '-DBUILD_opencv_apps=OFF',
                        '-DBUILD_opencv_java=OFF',
                        '-DWITH_CUDA=OFF',
                        '-DCMAKE_INSTALL_PREFIX=%s' % cv_install_dir]

                    if sys.platform.startswith('darwin'):
                        python_lib_path = subprocess.check_output(['python-config', '--prefix']).strip()
                        opencv_cmake_call_args.append('-DPYTHON_LIBRARY=%s/Python' % python_lib_path)
                        opencv_cmake_call_args.append('-DPYTHON_INCLUDE_DIR=%s/Headers' % python_lib_path)

                    run_shell(opencv_cmake_call_args,
                              verbose=robustus.settings['verbosity'] >= 1)
                    retcode = run_shell(['make', '-j4'], verbose=robustus.settings['verbosity'] >= 1)
                    if retcode != 0:
                        raise RequirementException('OpenCV build failed')

                    # install into wheelhouse
                    if not os.path.isdir(cv_install_dir):
                        os.mkdir(cv_install_dir)
                    retcode = run_shell(['make', 'install'], verbose=robustus.settings['verbosity'] >= 1)
                    if retcode != 0:
                        raise RequirementException('OpenCV installation failed')

            finally:
                safe_remove(opencv_archive)
                safe_remove(opencv_archive_name)
                os.chdir(cwd)

            if in_cache():
                # fix rpath for all dynamic libraries of cv2
                all_cv_dlibs = os.path.abspath(os.path.join(cv_install_dir, 'lib'))
                if sys.platform.startswith('darwin'):
                    libs = glob.glob(os.path.join(all_cv_dlibs, '*.dylib'))
                else:
                    libs = glob.glob(os.path.join(all_cv_dlibs, '*.so'))
                for lib in libs:
                    fix_rpath(robustus, robustus.env, lib, cv_install_dir)

        if in_cache():
            logging.info('Copying OpenCV cv2.so to virtualenv')
            cp(os.path.join(cv_install_dir, 'lib/python2.7/site-packages/*'),
               os.path.join(robustus.env, 'lib/python2.7/site-packages'))
            # fix rpath for cv2
            cv2lib = os.path.join(robustus.env, 'lib/python2.7/site-packages/cv2.so')
            fix_rpath(robustus, robustus.env, cv2lib, cv_install_dir)
        else:
            raise RequirementException('can\'t find OpenCV-%s in robustus cache' % requirement_specifier.version)