Esempio n. 1
0
def glob(start, file_pattern, exclude_dirs_pattern=None, discard_pattern=None):

    if is_string(file_pattern):
        file_pattern = re.compile(fnmatch.translate(file_pattern))

    if exclude_dirs_pattern:
        if is_string(exclude_dirs_pattern):
            exclude_dirs_pattern = re.compile(
                fnmatch.translate(exclude_dirs_pattern))

    if discard_pattern:
        if is_string(discard_pattern):
            discard_pattern = re.compile(fnmatch.translate(discard_pattern))

    matches = []
    subdir = False

    for root, dirnames, filenames in os.walk(start):

        if exclude_dirs_pattern:
            # remove any directories from the search that match the exclude regex
            dirnames[:] = [
                d for d in dirnames if not exclude_dirs_pattern.match(d)
            ]

        exclude_this_dir = False
        matches_in_this_dir = []

        for filename in filenames:
            if subdir and discard_pattern and discard_pattern.match(filename):
                # if we are in a subdir and it contains a file that matches the discard_pattern
                # set exclude_this_dir to True so later we can discard any local matches we'd
                # already encountered while walking the directory
                exclude_this_dir = True
                break
            if file_pattern.match(filename):
                matches_in_this_dir.append(os.path.join(root, filename))

        if not exclude_this_dir:
            matches += matches_in_this_dir
        else:
            # We are excluding this directory and therefore all of its subdirs
            dirnames[:] = []

        # After the first pass through the loop we will be in a subdirectory
        subdir = True

    return matches
Esempio n. 2
0
    def __call__(self, env, dependencies):

        # Ensure we have a list of dependencies
        dependencies = Flatten(dependencies)

        # We might have string names of dependencies or actual factories
        # so refer to this as an id
        for named_dependency in dependencies:

            name = None
            if is_string(named_dependency):
                name = named_dependency
            else:
                name = named_dependency.name()

            if not name in env['dependencies']:
                raise BuildWithException(
                    "The sconscript [{}] requires the dependency [{}] but it is not available."
                    .format(env['sconscript_file'], name))

            dependency_factory = env['dependencies'][name]
            env.AppendUnique(BUILD_WITH=name)
            dependency = dependency_factory(env)
            if dependency:
                dependency(env, env['toolchain'], env['variant'].name())
            else:
                raise BuildWithException(
                    "The sconscript [{}] requires the dependency [{}] but it cannot be created."
                    .format(env['sconscript_file'], name))
Esempio n. 3
0
    def _normalise_with_defaults(cls, values, default_values, name):

        warning = None
        if isinstance(values, dict):
            warning = "Dictionary passed for {}, this approach has been deprecated, please use a list instead".format(
                name)
            values = [v for v in six.itervalues(values)]

        default_value_objects = []
        default_value_names = []

        for value in default_values:
            if not is_string(value):
                default_value_objects.append(value)
                try:
                    name = getattr(value, 'name')
                    if callable(name):
                        default_value_names.append(name())
                    else:
                        default_value_names.append(value.__name__)
                except:
                    default_value_names.append(value.__name__)
            else:
                default_value_names.append(value)

        default_values = default_value_names
        values = values + default_value_objects

        return values, default_values, warning
Esempio n. 4
0
    def _normalise_with_defaults( cls, values, default_values, name ):

        warning = None
        if isinstance( values, dict ):
            warning = "Dictionary passed for {}, this approach has been deprecated, please use a list instead".format( name )
            values = [ v for v in values.itervalues() ]

        default_value_objects = []
        default_value_names = []

        for value in default_values:
            if not is_string( value ):
                default_value_objects.append( value )
                try:
                    name = getattr( value, 'name' )
                    if callable( name ):
                        default_value_names.append( name() )
                    else:
                        default_value_names.append( value.__name__ )
                except:
                    default_value_names.append( value.__name__ )
            else:
                default_value_names.append( value )

        default_values = default_value_names
        values = values + default_value_objects

        return values, default_values, warning
Esempio n. 5
0
    def __call__( self, env, profiles ):
        # Ensure we have a list of profiles
        profiles = Flatten( profiles )

        # We might have string names of profiles or actual factories
        # so refer to this as an id
        for named_profile in profiles:

            name = None
            if is_string( named_profile ):
                name = named_profile
            else:
                name = named_profile.name()

            if not name in env['profiles']:
                raise BuildProfileException(
                    "The sconscript [{}] requires the profile [{}] but it is not available."
                        .format( env['sconscript_file'], name )
                )

            profile_factory = env['profiles'][name]
            env.AppendUnique( BUILD_PROFILE = name )
            profile = profile_factory( env )
            if profile:
                profile( env, env['toolchain'], env['variant'].name() )
            else:
                raise BuildProfileException(
                    "The sconscript [{}] requires the profile [{}] but it cannot be created."
                        .format( env['sconscript_file'], name )
                )
Esempio n. 6
0
    def __call__(self, env, profiles):
        # Ensure we have a list of profiles
        profiles = Flatten(profiles)

        # We might have string names of profiles or actual factories
        # so refer to this as an id
        for named_profile in profiles:

            name = None
            if is_string(named_profile):
                name = named_profile
            else:
                name = named_profile.name()

            if not name in env['profiles']:
                raise BuildProfileException(
                    "The sconscript [{}] requires the profile [{}] but it is not available."
                    .format(env['sconscript_file'], name))

            profile_factory = env['profiles'][name]
            env.AppendUnique(BUILD_PROFILE=name)
            profile = profile_factory(env)
            if profile:
                profile(env, env['toolchain'], env['variant'].name())
            else:
                raise BuildProfileException(
                    "The sconscript [{}] requires the profile [{}] but it cannot be created."
                    .format(env['sconscript_file'], name))
Esempio n. 7
0
def filter_nodes(nodes, match_patterns, exclude_patterns=[]):

    nodes = Flatten(nodes)

    if not match_patterns and not exclude_patterns:
        return nodes

    if match_patterns:
        match_patterns = Flatten([match_patterns])
        for i, match_pattern in enumerate(match_patterns):
            if is_string(match_pattern):
                match_patterns[i] = re.compile(
                    fnmatch.translate(match_pattern))

    if exclude_patterns:
        exclude_patterns = Flatten([exclude_patterns])
        for i, exclude_pattern in enumerate(exclude_patterns):
            if is_string(exclude_pattern):
                exclude_patterns[i] = re.compile(
                    fnmatch.translate(exclude_pattern))

    filtered_nodes = []

    for node in nodes:
        path = str(node)
        logger.trace("Node in nodes to filter = [{}][{}]".format(
            as_notice(path), as_notice(node.path)))

        if exclude_patterns:
            excluded = False
            for exclude_pattern in exclude_patterns:
                if exclude_pattern.match(path):
                    excluded = True
                    break
            if excluded:
                continue

        if not match_patterns:
            filtered_nodes.append(node)
        else:
            for match_pattern in match_patterns:
                if match_pattern.match(path):
                    filtered_nodes.append(node)

    return filtered_nodes
Esempio n. 8
0
def filter_nodes( nodes, match_patterns, exclude_patterns=[] ):

    nodes = Flatten( nodes )

    if not match_patterns and not exclude_patterns:
        return nodes

    if match_patterns:
        match_patterns = Flatten( [ match_patterns ] )
        for i, match_pattern in enumerate(match_patterns):
            if is_string( match_pattern ):
                match_patterns[i] = re.compile( fnmatch.translate( match_pattern ) )

    if exclude_patterns:
        exclude_patterns = Flatten( [ exclude_patterns ] )
        for i, exclude_pattern in enumerate(exclude_patterns):
            if is_string( exclude_pattern ):
                exclude_patterns[i] = re.compile( fnmatch.translate( exclude_pattern ) )

    filtered_nodes = []

    for node in nodes:
        path = str( node )
        logger.trace( "Node in nodes to filter = [{}][{}]".format( as_notice(path), as_notice(node.path) ) )

        if exclude_patterns:
            excluded = False
            for exclude_pattern in exclude_patterns:
                if exclude_pattern.match( path ):
                    excluded = True
                    break
            if excluded:
                continue

        if not match_patterns:
            filtered_nodes.append( node )
        else:
            for match_pattern in match_patterns:
                if match_pattern.match( path ):
                    filtered_nodes.append( node )

    return filtered_nodes
Esempio n. 9
0
    def __call__(self, env, build_profile):
        for profile in build_profile:
            if is_string(profile):
                name = profile
                if name in env['profiles']:
                    profile = env['profiles'][name]
            else:
                name = str(profile)

            env.AppendUnique(BUILD_PROFILE=name)
            profile(env, env['toolchain'], env['variant'].name())