(readme, session_name, path)
| 41 | |
| 42 | |
| 43 | def generate_entry(readme, session_name, path): |
| 44 | def get_author_from_filename(path): |
| 45 | author_regex = re.compile(".* - (.*) - CppCon " + str(CPPCON_YEAR) + |
| 46 | "\\.[^.]*$") |
| 47 | |
| 48 | author = author_regex.search(path) |
| 49 | |
| 50 | if author: |
| 51 | return author.group(1) |
| 52 | |
| 53 | return "" |
| 54 | |
| 55 | def get_author_from_readme_md(path): |
| 56 | readme_header_regex = re.compile(r"\*\*(.*)\*\* by \*\*(.*)\*\*") |
| 57 | |
| 58 | with open(path, mode='rb') as readme_md: |
| 59 | header = readme_md.readline().decode() |
| 60 | match = readme_header_regex.match(header) |
| 61 | |
| 62 | if match: |
| 63 | return match.group(2) |
| 64 | |
| 65 | return "" |
| 66 | |
| 67 | def md_path(path): |
| 68 | return quote(normpath(path).replace('\\', '/')) |
| 69 | |
| 70 | presentation_regex = re.compile("- CppCon " + str(CPPCON_YEAR) + |
| 71 | "\\.[^.]*$") |
| 72 | pdf_regex = re.compile("\\.pdf$", flags=re.I) |
| 73 | readme_md_regex = re.compile("README\\.md$") |
| 74 | |
| 75 | readme_md_file = "" |
| 76 | presentation_file = "" |
| 77 | all_presentation_files = [] |
| 78 | all_other_files = [] |
| 79 | author = "" |
| 80 | |
| 81 | dir_contents = listdir(path) |
| 82 | |
| 83 | for name in dir_contents: |
| 84 | if presentation_regex.search(name): |
| 85 | # Pick the first file we found, but prefer a PDF file if there |
| 86 | # is one |
| 87 | if (not presentation_file) or pdf_regex.search(name): |
| 88 | presentation_file = name |
| 89 | author = get_author_from_filename(name) |
| 90 | |
| 91 | all_presentation_files.append(name) |
| 92 | elif readme_md_regex.search(name): |
| 93 | readme_md_file = name |
| 94 | else: |
| 95 | all_other_files.append(name) |
| 96 | |
| 97 | if all_presentation_files: |
| 98 | presentation_path = join(path, presentation_file) |
| 99 | else: |
| 100 | presentation_path = path |
no test coverage detected