| 74 | |
| 75 | |
| 76 | class SourceFiles: |
| 77 | def __init__(self): |
| 78 | self.files = {} |
| 79 | self.prefix = None |
| 80 | |
| 81 | def get_file(self, path): |
| 82 | if path not in self.files: |
| 83 | self.files[path] = SourceFile(path) |
| 84 | if self.prefix is None: |
| 85 | self.prefix = path |
| 86 | else: |
| 87 | self.prefix = os.path.commonpath([self.prefix, path]) |
| 88 | return self.files[path] |
| 89 | |
| 90 | def clean_path(self, path): |
| 91 | path = path[len(self.prefix):] |
| 92 | return re.sub(r"[^A-Za-z0-9\.]", '_', path) |
| 93 | |
| 94 | def write_text(self, root): |
| 95 | for path, source in self.files.items(): |
| 96 | with open(os.path.join(root, self.clean_path(path)), "w") as fd: |
| 97 | source.write_text(fd) |
| 98 | |
| 99 | def write_html(self, root): |
| 100 | for path, source in self.files.items(): |
| 101 | with open( |
| 102 | os.path.join(root, self.clean_path(path) + ".html"), "w" |
| 103 | ) as fd: |
| 104 | source.write_html(fd) |
| 105 | |
| 106 | with open(os.path.join(root, 'index.html'), 'w') as fd: |
| 107 | fd.write("<html>") |
| 108 | paths = sorted(self.files.keys()) |
| 109 | for path in paths: |
| 110 | href = self.clean_path(path) |
| 111 | label = escape(path[len(self.prefix):]) |
| 112 | fd.write(f'<p><a href="{href}.html">{label}</a></p>') |
| 113 | fd.write("</html>") |
| 114 | |
| 115 | |
| 116 | def collect_stats(files, fd, pattern): |
no outgoing calls
no test coverage detected
searching dependent graphs…