def process(self, cursor, include_patterns): try: cwd = Path.cwd() filepath = PurePath(cursor.location.file.name) if filepath.is_relative_to(cwd): filepath = filepath.relative_to(cwd) filepath = str(filepath) if not any( pattern.search(filepath) for pattern in include_patterns): return if not self.skip_defines and filepath not in self.parsed_headers: self.mark_macros(filepath) self.parsed_headers.add(filepath) except AttributeError: return if cursor.kind == clang.CursorKind.VAR_DECL: new_definition = Variable(cursor) self.defs.append(new_definition) if cursor.kind in (clang.CursorKind.TYPEDEF_DECL, clang.CursorKind.ENUM_DECL, clang.CursorKind.STRUCT_DECL, clang.CursorKind.UNION_DECL): self.process_type(cursor.type) elif cursor.kind == clang.CursorKind.FUNCTION_DECL: self.defs.append(Function(cursor))
def iter_launchers(self) -> Iterator[ROMLauncher]: file_list = [] #rom_list: list[tuple[ROM, Sequence[str]]] = [] for rom_dir in self.platform_config.paths: if not rom_dir.is_dir(): print('Oh no', self.name, 'has invalid ROM dir', rom_dir) continue #used_m3u_filenames = [] for root, dirs, files in os.walk(rom_dir): root_path = PurePath(root) if any(root_path.is_relative_to(ignored_directory) for ignored_directory in main_config.ignored_directories): continue subfolders = root_path.relative_to(rom_dir).parts if subfolders: if any(subfolder in main_config.skipped_subfolder_names for subfolder in subfolders): continue folder_check = self.platform.folder_check if folder_check: remaining_subdirs = [] #The subdirectories of rom_dir that aren't folder ROMs for d in dirs: folder_path = Path(root, d) if not main_config.full_rescan: if has_been_done('ROM', str(folder_path)): continue folder_rom = FolderROM(folder_path) media_type = folder_check(folder_rom) if media_type: folder_rom.media_type = media_type #rom_list.append((folder_rom, subfolders)) launcher = self._process_rom(folder_rom, subfolders) if launcher: yield launcher #file_list.append((folder_path, subfolders)) #Avoid descending further, even if we get a NotARomException #This will not work well if we have multiple emulators for these folder-having systems and one supports folders and one doesn't, but eh, worry about that later I think continue remaining_subdirs.append(d) dirs[:] = remaining_subdirs dirs.sort() for name in sorted(files): path = Path(root, name) #TODO: We might actually want to do something with associated documents later, but for now, we know we aren't doing anything with them if (not self.platform.is_valid_file_type(path.suffix[1:].lower())) and path.suffix[1:].lower() in {'txt', 'md', 'jpg', 'nfo', 'gif', 'bmp'}: continue if not main_config.full_rescan: if has_been_done('ROM', str(path)): continue file_list.append((path, subfolders)) yield from self._process_file_list(file_list)
list( filter(lambda ln: ln and not ln.startswith(comment_char), map(str.strip, lines)))) # very basic, ignores C++ style /* ... */ and other non-newline-terminated comment styles comment_types = { '.h': '//', # C/C++ headers '.cpp': '//', # C++ source '.pl': '%', # C source '.txt': '#', # CMakeLists.txt '.frn': '//', # Fern '.py': '#', # Python } excluded_dirs = [PurePath('./build')] total_count = 0 for path, _, filenames in os.walk('.'): path = PurePath(path) if any(map(lambda ex: path.is_relative_to(ex), excluded_dirs)): continue for filename in map(lambda name: os.path.join(path, name), filenames): _, ext = os.path.splitext(filename) if ext in comment_types: with open(filename) as file: file_count = count_semantic_lines(file, comment_types[ext]) print(f'\t{filename}: {file_count} SLOC') total_count += file_count print(f'TOTAL: {total_count} SLOC')