def execute(cls, source, destination, tasks):
        """Execute tasks on directories

        :param source: Native libraries source directory
        :type source: str

        :param destination: Native libraries cache directory
        :type destination: str

        :param tasks: Tasks to execute
        :type tasks: list

        :rtype: bool
        """
        success = True

        for action, path in tasks:
            if action in ['add', 'update']:
                action_success = StorageHelper.copy(os.path.join(source, path), os.path.join(destination, path))
            elif action == 'delete':
                action_success = StorageHelper.delete(os.path.join(destination, path))
            else:
                log.warn('Unknown task: %r - %r', action, path)
                action_success = False

            if not action_success:
                success = False

        return success
    def setup(cls, cache=False):
        """Setup native library directories

        :param cache: Enable native library caching
        :type cache: bool
        """

        # Use `cache` value from advanced configuration
        cache = Configuration.advanced['libraries'].get_boolean('cache', cache)

        # Retrieve libraries path (and cache libraries, if enabled)
        libraries_path = cls._libraries_path(cache)

        if not libraries_path:
            return

        log.info('Using native libraries at %r',
                 StorageHelper.to_relative_path(libraries_path))

        # Remove current native library directories from `sys.path`
        cls.reset()

        # Insert platform specific library paths
        cls._insert_paths(libraries_path)

        # Display library paths in logfile
        for path in sys.path:
            path = os.path.abspath(path)

            if StorageHelper.is_framework_path(path):
                continue

            log.info('[PATH] %s', StorageHelper.to_relative_path(path))
    def setup(cls, cache=False):
        """Setup native library directories

        :param cache: Enable native library caching
        :type cache: bool
        """

        # Read distribution metadata
        distribution = cls._read_distribution_metadata()

        # Use `cache` value from advanced configuration
        cache = Configuration.advanced['libraries'].get_boolean('cache', cache)

        # Retrieve libraries path (and cache libraries, if enabled)
        libraries_path = cls._libraries_path(cache)

        if not libraries_path:
            return

        log.info('Using native libraries at %r', StorageHelper.to_relative_path(libraries_path))

        # Remove current native library directories from `sys.path`
        cls.reset()

        # Insert platform specific library paths
        cls._insert_paths(distribution, libraries_path)

        # Display library paths in logfile
        for path in sys.path:
            path = os.path.abspath(path)

            if StorageHelper.is_framework_path(path):
                continue

            log.info('[PATH] %s', StorageHelper.to_relative_path(path))
    def _libraries_path(cls, cache=False):
        """Retrieve the native libraries base directory (and cache the libraries if enabled)

        :param cache: Enable native library caching
        :type cache: bool
        """

        # Use specified libraries path (from "advanced.ini')
        libraries_path = Configuration.advanced['libraries'].get(
            'libraries_path')

        if libraries_path and os.path.exists(libraries_path):
            log.info('Using libraries at %r',
                     StorageHelper.to_relative_path(libraries_path))
            RAVEN.tags.update({'libraries.source': 'custom'})
            return libraries_path

        # Use system libraries (if bundled libraries have been disabled in "advanced.ini")
        if not Configuration.advanced['libraries'].get_boolean(
                'bundled', True):
            log.info(
                'Bundled libraries have been disabled, using system libraries')
            RAVEN.tags.update({'libraries.source': 'system'})
            return None

        # Cache libraries (if enabled)
        if cache:
            RAVEN.tags.update({'libraries.source': 'cache'})
            return cls._cache_libraries()

        RAVEN.tags.update({'libraries.source': 'bundle'})
        return Environment.path.libraries
Exemple #5
0
    def _libraries_path(cls, cache=False):
        """Retrieve the native libraries base directory (and cache the libraries if enabled)

        :param cache: Enable native library caching
        :type cache: bool
        """

        # Use specified libraries path (from "advanced.ini')
        libraries_path = Configuration.advanced['libraries'].get('libraries_path')

        if libraries_path and os.path.exists(libraries_path):
            log.info('Using libraries at %r', StorageHelper.to_relative_path(libraries_path))
            RAVEN.tags.update({'libraries.source': 'custom'})
            return libraries_path

        # Use system libraries (if bundled libraries have been disabled in "advanced.ini")
        if not Configuration.advanced['libraries'].get_boolean('bundled', True):
            log.info('Bundled libraries have been disabled, using system libraries')
            RAVEN.tags.update({'libraries.source': 'system'})
            return None

        # Cache libraries (if enabled)
        if cache:
            RAVEN.tags.update({'libraries.source': 'cache'})
            return cls._cache_libraries()

        RAVEN.tags.update({'libraries.source': 'bundle'})
        return Environment.path.libraries
    def _cache_libraries(cls):
        cache_path = Configuration.advanced['libraries'].get('cache_path')

        # Try cache libraries to `cache_path`
        libraries_path = CacheManager.sync(cache_path)

        if not libraries_path:
            log.info('Unable to cache libraries, using bundled libraries directly')
            return Environment.path.libraries

        log.info('Cached libraries to %r', StorageHelper.to_relative_path(libraries_path))
        return libraries_path
    def _cache_libraries(cls):
        cache_path = Configuration.advanced['libraries'].get('cache_path')

        # Try cache libraries to `cache_path`
        libraries_path = CacheManager.sync(cache_path)

        if not libraries_path:
            log.info(
                'Unable to cache libraries, using bundled libraries directly')
            return Environment.path.libraries

        log.info('Cached libraries to %r',
                 StorageHelper.to_relative_path(libraries_path))
        return libraries_path
    def setup(cls, cache=False):
        """Setup native library directories

        :param cache: Enable native library caching
        :type cache: bool
        """

        # Retrieve libraries path (and cache libraries, if enabled)
        libraries_path = cls._libraries_path(cache)

        log.info('Using native libraries at %r', StorageHelper.to_relative_path(libraries_path))

        # Insert platform specific library paths
        cls._insert_paths(libraries_path)

        # Display library paths in logfile
        for path in sys.path:
            path = os.path.abspath(path)

            if not StorageHelper.is_relative_path(path):
                continue

            log.info('[PATH] %s', StorageHelper.to_relative_path(path))
    def get_paths(cache_path):
        """Retrieve system-specific native libraries source + destination path

        :param cache_path: Directory to store cached libraries
        :type cache_path: str

        :rtype: (str, str)
        """
        # Retrieve system details
        system = SystemHelper.name()
        architecture = SystemHelper.architecture()

        if not architecture:
            return None, None

        # Build list of acceptable architectures
        architectures = [architecture]

        if architecture == 'i686':
            # Fallback to i386
            architectures.append('i386')

        # Look for matching libraries
        for arch in architectures + ['universal']:
            # Build source path
            source = os.path.join(CONTENTS_PATH, 'Libraries', system, arch)

            # Ensure `source` directory exists
            if not os.path.exists(source):
                continue

            # Build path for native dependencies
            destination = os.path.join(cache_path, system, arch)

            # Ensure `destination` directory has been created
            if not StorageHelper.create_directories(destination):
                # Directory couldn't be created
                return None, None

            return source, destination

        # No libraries could be found
        log.error('Unable to find native libraries for platform (name: %r, architecture: %r)', system, architecture)
        return None, None