예제 #1
0
 def test_get_matches(self):
     patterns = {'*/.svn/*': '.scanignore'}
     assert fileset.get_matches('home/common/tools/elf/.svn/', patterns)
     assert fileset.get_matches('home/common/tools/.svn/this', patterns)
     assert not fileset.get_matches('home/common/.git/this', patterns)
예제 #2
0
    def test_get_matches_accepts_a_list_or_tuple(self):
        patterns = ['*/.svn/*']
        assert fileset.get_matches('home/common/tools/elf/.svn/', patterns)

        patterns = '*/.svn/*',
        assert fileset.get_matches('home/common/tools/elf/.svn/', patterns)
예제 #3
0
    def process_codebase(self, codebase, classify, **kwargs):
        """
        Tag resource as key or top level files based on Package type-specific
        rules.
        """
        if not classify:
            logger_debug('PackageTopAndKeyFilesTagger: return')
            return

        from packagedcode import get_package_class

        if codebase.has_single_resource:
            # What if we scanned a single file and we do not have a root proper?
            return

        root_path = codebase.root.path

        has_packages = hasattr(codebase.root, 'packages')
        if not has_packages:
            # FIXME: this is not correct... we may still have cases where this
            # is wrong: e.g. a META-INF directory and we may not have a package 
            return


        for resource in codebase.walk(topdown=True):
            packages_info = resource.packages or []

            if not packages_info:
                continue
            if not resource.has_children():
                continue

            descendants = None

            for package_info in packages_info:
                package_class = get_package_class(package_info)
                extra_root_dirs = package_class.extra_root_dirs()
                extra_key_files = package_class.extra_key_files()
                if TRACE:
                    logger_debug('PackageTopAndKeyFilesTagger: extra_root_dirs:', extra_root_dirs)
                    logger_debug('PackageTopAndKeyFilesTagger: extra_key_files:', extra_key_files)

                if not (extra_root_dirs or extra_key_files):
                    # FIXME: this is not correct!
                    # we may still have other files under the actual root.
                    continue

                if not descendants:
                    descendants = {
                        get_relative_path(root_path, r.path): r
                                   for r in resource.descendants(codebase)}

                    if TRACE:
                        logger_debug('PackageTopAndKeyFilesTagger: descendants')
                        for rpath, desc in descendants.items():
                            logger_debug('rpath:', rpath, 'desc:', desc)

                for rpath, desc in descendants.items():
                    if extra_root_dirs and get_matches(rpath, extra_root_dirs):
                        if TRACE:
                            logger_debug('PackageTopAndKeyFilesTagger: get_matches for:', rpath, desc)
                        desc.is_top_level = True
                        if desc.is_file:
                            set_classification_flags(desc)
                        desc.save(codebase)

                        for child in desc.children(codebase):
                            if TRACE:
                                logger_debug('PackageTopAndKeyFilesTagger: set is_top_level for:', child)

                            child.is_top_level = True
                            if child.is_file:
                                set_classification_flags(child)
                            child.save(codebase)

                    if extra_key_files and get_matches(rpath, extra_key_files):
                        desc.is_key_file = True
                        desc.save(codebase)