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