|
1 | | -import csv |
2 | 1 | import datetime |
3 | 2 | import shutil |
4 | 3 | import os |
| 4 | +from utils import parse_package_info |
5 | 5 |
|
6 | 6 | def main(csv_file_path, html_file_path, functions_file_path): |
7 | 7 | print(f"Current working directory: {os.getcwd()}") |
@@ -32,109 +32,115 @@ def main(csv_file_path, html_file_path, functions_file_path): |
32 | 32 |
|
33 | 33 | top_content = '<div class="top-content">' |
34 | 34 | top_content += '<h1>DataSHIELD packages</h1>' |
35 | | - top_content += '<p>This page lists all the packages that have been developed in the DataSHIELD ecosystem. It includes packages that are in production, in development, retired, and unknown status.</p>' |
| 35 | + top_content += '<p>This page lists all the packages that have been developed in the <a href="https://www.datashield.org">DataSHIELD</a> ecosystem. It includes packages that are in production, in development, retired, and unknown status.</p>' |
36 | 36 |
|
37 | 37 | html_file.write(top_content) |
38 | 38 |
|
39 | | - with open(csv_file_path, 'r', encoding='utf-8') as csv_file: |
40 | | - package_list = csv.reader(csv_file) |
41 | | - |
42 | | - # Count the number of lines in the CSV file then go back to the beginning |
43 | | - row_count = sum(1 for row in package_list) # fileObject is your csv.reader |
44 | | - csv_file.seek(0) |
45 | | - |
46 | | - stats = f'<p>There are {row_count - 1} packages and {number_of_functions} functions listed on these pages.</p>' |
47 | | - html_file.write(stats) |
48 | | - |
49 | | - # Skip header |
50 | | - next(package_list) |
51 | | - |
52 | | - html_file.write('<table border="1">\n') |
53 | | - |
54 | | - html_file.write('<tr><td></td>') |
55 | | - html_file.write('<th>Name</th>') |
56 | | - html_file.write('<th>Description</th>') |
57 | | - html_file.write('<th>CRAN version</th>') |
58 | | - html_file.write('<th>CRAN license</th>') |
59 | | - html_file.write('<th>GitHub last update</th>') |
60 | | - html_file.write('<th>GitHub version</th>') |
61 | | - html_file.write('<th>GitHub license</th>') |
62 | | - html_file.write('<th>GitHub owner</th>') |
63 | | - html_file.write('</tr>') |
64 | | - |
65 | | - production_rows = "" |
66 | | - development_rows = "" |
67 | | - retired_rows = "" |
68 | | - unknown_rows = "" |
69 | | - |
70 | | - # Counts for each rows |
71 | | - production_rows_count = 1 |
72 | | - development_rows_count = 1 |
73 | | - retired_rows_count = 1 |
74 | | - unknown_rows_count = 1 |
75 | | - |
76 | | - for row in package_list: |
77 | | - print(row) |
78 | | - this_row = "" |
79 | | - |
80 | | - # Add GitHub link if available, otherwise just the name |
81 | | - this_row += '<td class="left"><a href="packages.html#' + row[0] + '">' + row[0] + '</a></td>' |
82 | | - |
83 | | - # Description |
84 | | - if len(row[1]) > 0: |
85 | | - this_row += '<td class="left">' + row[1] + '</td>' |
86 | | - else: |
87 | | - this_row += '<td></td>' |
88 | | - |
89 | | - # CRAN version with link |
90 | | - if len(row[2]) > 0: |
91 | | - this_row += '<td><a href="' + row[2] + '" target="blank">' + row[3] + '</a></td>' |
92 | | - else: |
93 | | - this_row += '<td></td>' |
94 | | - |
95 | | - this_row += '<td>' + row[4] + '</td>' # CRAN license |
96 | | - this_row += '<td>' + row[6] + '</td>' # GH last update |
97 | | - this_row += '<td>' + row[7] + '</td>' # GH version |
98 | | - this_row += '<td>' + row[9] + '</td>' # GH license |
99 | | - this_row += '<td class="left">' + row[10] + '</td>' # GH owner |
100 | | - |
101 | | - # Group rows by status and add put a row number in |
102 | | - if row[11].strip() == 'production': |
103 | | - production_rows += '<tr>' |
104 | | - production_rows += '<td>' + str(production_rows_count) + '</td>' # Row number |
105 | | - production_rows += this_row |
106 | | - production_rows += '</tr>' |
107 | | - production_rows_count += 1 |
108 | | - elif row[11].strip() == 'development': |
109 | | - development_rows += '<tr>' |
110 | | - development_rows += '<td>' + str(development_rows_count) + '</td>' |
111 | | - development_rows += this_row |
112 | | - development_rows += '</tr>' |
113 | | - development_rows_count += 1 |
114 | | - elif row[11].strip() == 'retired': |
115 | | - retired_rows += '<tr>' |
116 | | - retired_rows += '<td>' + str(retired_rows_count) + '</td>' |
117 | | - retired_rows += this_row |
118 | | - retired_rows += '</tr>' |
119 | | - retired_rows_count += 1 |
120 | | - else: |
121 | | - unknown_rows += '<tr>' |
122 | | - unknown_rows += '<td>' + str(unknown_rows_count) + '</td>' |
123 | | - unknown_rows += this_row |
124 | | - unknown_rows += '</tr>' |
125 | | - unknown_rows_count += 1 |
126 | | - |
127 | | - # Build the table with the rows grouped by status |
128 | | - html_file.write('<tr><td colspan="9">Production</td></tr>') |
129 | | - html_file.write(production_rows) |
130 | | - html_file.write('<tr><td colspan="9">Development</td></tr>') |
131 | | - html_file.write(development_rows) |
132 | | - html_file.write('<tr><td colspan="9">Retired</td></tr>') |
133 | | - html_file.write(retired_rows) |
134 | | - html_file.write('<tr><td colspan="9">Unknown</td></tr>') |
135 | | - html_file.write(unknown_rows) |
136 | | - html_file.write('</table>') |
137 | | - |
| 39 | + package_info = parse_package_info(csv_file_path) |
| 40 | + |
| 41 | + stats = f'<p>There are {len(package_info)} packages and {number_of_functions} functions listed on these pages.</p>' |
| 42 | + html_file.write(stats) |
| 43 | + |
| 44 | + html_file.write('<table border="1">\n') |
| 45 | + |
| 46 | + html_file.write('<tr><td></td>') |
| 47 | + html_file.write('<th>Name</th>') |
| 48 | + html_file.write('<th>Description</th>') |
| 49 | + html_file.write('<th>CRAN version</th>') |
| 50 | + html_file.write('<th>CRAN license</th>') |
| 51 | + html_file.write('<th>GitHub last update</th>') |
| 52 | + html_file.write('<th>GitHub version</th>') |
| 53 | + html_file.write('<th>GitHub license</th>') |
| 54 | + html_file.write('<th>GitHub owner</th>') |
| 55 | + html_file.write('</tr>') |
| 56 | + |
| 57 | + production_rows = "" |
| 58 | + development_rows = "" |
| 59 | + retired_rows = "" |
| 60 | + unknown_rows = "" |
| 61 | + |
| 62 | + # Counts for each rows |
| 63 | + production_rows_count = 1 |
| 64 | + development_rows_count = 1 |
| 65 | + retired_rows_count = 1 |
| 66 | + unknown_rows_count = 1 |
| 67 | + |
| 68 | + #for row in package_list: |
| 69 | + for this_package_name, this_package_info in package_info.items(): |
| 70 | + print(this_package_name) |
| 71 | + print(this_package_info) |
| 72 | + this_row = "" |
| 73 | + |
| 74 | + # Add GitHub link if available, otherwise just the name |
| 75 | + this_row += '<td class="left"><a href="packages.html#' + this_package_name + '">' + this_package_name + '</a></td>' |
| 76 | + |
| 77 | + # Description |
| 78 | + if len(this_package_info['short_description']) > 0: |
| 79 | + this_row += '<td class="left">' + this_package_info['short_description'] + '</td>' |
| 80 | + else: |
| 81 | + this_row += '<td></td>' |
| 82 | + |
| 83 | + # CRAN version with link |
| 84 | + if len(this_package_info.get('cran_link')) > 0: |
| 85 | + this_row += '<td><a href="' + this_package_info['cran_link'] + '" target="blank">' + this_package_info['cran_version'] + '</a></td>' |
| 86 | + else: |
| 87 | + this_row += '<td></td>' |
| 88 | + |
| 89 | + this_row += '<td>' + this_package_info.get('cran_license', "") + '</td>' # CRAN license |
| 90 | + this_row += '<td>' + this_package_info.get('github_last_update', "") + '</td>' # GH last update |
| 91 | + |
| 92 | + # GH version with link |
| 93 | + if this_package_info.get('github_version_url') == "null": |
| 94 | + this_row += '<td></td>' |
| 95 | + else: |
| 96 | + this_row += '<td><a href="' + this_package_info['github_version_url'] + '" target="_blank">' + this_package_info['github_version'] + '</a></td>' |
| 97 | + |
| 98 | + # GH license |
| 99 | + if this_package_info.get('github_license') == "null": |
| 100 | + this_row += '<td></td>' |
| 101 | + else: |
| 102 | + this_row += '<td>' + this_package_info.get('github_license', "") + '</td>' |
| 103 | + |
| 104 | + this_row += '<td class="left"><a href="https://github.com/' + this_package_info['github_owner'] + '" target="_blank">' + this_package_info['github_owner'] + '</a></td>' # GH owner |
| 105 | + |
| 106 | + # Group rows by status and add put a row number in |
| 107 | + if this_package_info['status'].strip() == 'production': |
| 108 | + production_rows += '<tr>' |
| 109 | + production_rows += '<td>' + str(production_rows_count) + '</td>' # Row number |
| 110 | + production_rows += this_row |
| 111 | + production_rows += '</tr>' |
| 112 | + production_rows_count += 1 |
| 113 | + elif this_package_info['status'].strip() == 'development': |
| 114 | + development_rows += '<tr>' |
| 115 | + development_rows += '<td>' + str(development_rows_count) + '</td>' |
| 116 | + development_rows += this_row |
| 117 | + development_rows += '</tr>' |
| 118 | + development_rows_count += 1 |
| 119 | + elif this_package_info['status'].strip() == 'retired': |
| 120 | + retired_rows += '<tr>' |
| 121 | + retired_rows += '<td>' + str(retired_rows_count) + '</td>' |
| 122 | + retired_rows += this_row |
| 123 | + retired_rows += '</tr>' |
| 124 | + retired_rows_count += 1 |
| 125 | + else: |
| 126 | + unknown_rows += '<tr>' |
| 127 | + unknown_rows += '<td>' + str(unknown_rows_count) + '</td>' |
| 128 | + unknown_rows += this_row |
| 129 | + unknown_rows += '</tr>' |
| 130 | + unknown_rows_count += 1 |
| 131 | + |
| 132 | + # Build the table with the rows grouped by status |
| 133 | + html_file.write('<tr><td colspan="9">Production</td></tr>') |
| 134 | + html_file.write(production_rows) |
| 135 | + html_file.write('<tr><td colspan="9">Development</td></tr>') |
| 136 | + html_file.write(development_rows) |
| 137 | + html_file.write('<tr><td colspan="9">Retired</td></tr>') |
| 138 | + html_file.write(retired_rows) |
| 139 | + html_file.write('<tr><td colspan="9">Unknown</td></tr>') |
| 140 | + html_file.write(unknown_rows) |
| 141 | + html_file.write('</table>') |
| 142 | + |
| 143 | + html_file.write('<hr/>') |
138 | 144 | html_file.write('Generated on ' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) |
139 | 145 | html_file.write(' Made by the <a href="https://github.com/FederatedMethods">Federated Methods team</a>') |
140 | 146 |
|
|
0 commit comments