| Total Complexity | 7 |
| Total Lines | 107 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | Download the icons. |
||
| 3 | """ |
||
| 4 | |||
| 5 | import pathlib |
||
| 6 | import shutil |
||
| 7 | import sys |
||
| 8 | import urllib.error |
||
| 9 | import urllib.request |
||
| 10 | |||
| 11 | |||
| 12 | def get_icons() -> None: |
||
| 13 | """ |
||
| 14 | Download the icons. |
||
| 15 | """ |
||
| 16 | get_fontawesome() |
||
| 17 | |||
| 18 | |||
| 19 | def get_fontawesome() -> None: |
||
| 20 | """ |
||
| 21 | Get the fontawesome icons. |
||
| 22 | """ |
||
| 23 | folder = get_folder("fontawesome") |
||
| 24 | download( |
||
| 25 | "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/6.6.0/" |
||
| 26 | "css/fontawesome.css", |
||
| 27 | folder, |
||
| 28 | "fontawesome.css", |
||
| 29 | ) |
||
| 30 | download( |
||
| 31 | "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/6.6.0/" |
||
| 32 | "css/brands.css", |
||
| 33 | folder, |
||
| 34 | "brands.css", |
||
| 35 | ) |
||
| 36 | download( |
||
| 37 | "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/6.6.0/" |
||
| 38 | "webfonts/fa-brands-400.ttf", |
||
| 39 | folder, |
||
| 40 | "fa-brands-400.ttf", |
||
| 41 | ) |
||
| 42 | download( |
||
| 43 | "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/6.6.0/" |
||
| 44 | "webfonts/fa-regular-400.ttf", |
||
| 45 | folder, |
||
| 46 | "fa-regular-400.ttf", |
||
| 47 | ) |
||
| 48 | download( |
||
| 49 | "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/6.6.0/" |
||
| 50 | "webfonts/fa-solid-900.ttf", |
||
| 51 | folder, |
||
| 52 | "fa-solid-900.ttf", |
||
| 53 | ) |
||
| 54 | |||
| 55 | |||
| 56 | def download(url: str, folder: pathlib.Path, filename: str) -> None: |
||
| 57 | """ |
||
| 58 | Download an url to a folder/filename. |
||
| 59 | |||
| 60 | Arguments |
||
| 61 | --------- |
||
| 62 | url |
||
| 63 | An url |
||
| 64 | folder |
||
| 65 | A folder |
||
| 66 | filename |
||
| 67 | A filename |
||
| 68 | """ |
||
| 69 | print(f"Download '{url}' to {folder}/{filename}") # noqa: T201 |
||
| 70 | try: |
||
| 71 | with ( |
||
| 72 | urllib.request.urlopen(url) as response, # noqa: S310 |
||
| 73 | pathlib.Path(folder, filename).open("wb") as out_file, |
||
| 74 | ): |
||
| 75 | shutil.copyfileobj(response, out_file) |
||
| 76 | except urllib.error.HTTPError as exception: |
||
| 77 | sys.stderr.write(str(exception)) |
||
| 78 | |||
| 79 | |||
| 80 | def get_folder(collection: str) -> pathlib.Path: |
||
| 81 | """ |
||
| 82 | Get a folder. |
||
| 83 | |||
| 84 | Arguments |
||
| 85 | --------- |
||
| 86 | collection |
||
| 87 | The collection name |
||
| 88 | |||
| 89 | Returns |
||
| 90 | ------- |
||
| 91 | pathlib.Path |
||
| 92 | The folder |
||
| 93 | """ |
||
| 94 | folder = pathlib.Path( |
||
| 95 | "share", |
||
| 96 | "pandoc_latex_tip", |
||
| 97 | collection, |
||
| 98 | ) |
||
| 99 | |||
| 100 | if not folder.exists(): |
||
| 101 | folder.mkdir(parents=True) |
||
| 102 | |||
| 103 | return folder |
||
| 104 | |||
| 105 | |||
| 106 | if __name__ == "__main__": |
||
| 107 | get_icons() |
||
| 108 |