|
1 | 1 | # Copyright (c) Microsoft Corporation.
|
2 | 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
3 | 3 |
|
| 4 | +from pathlib import PurePosixPath |
| 5 | +import sys |
4 | 6 | from urllib.request import urlretrieve
|
5 | 7 |
|
6 | 8 |
|
7 |
| -Unicode_data_files = { |
8 |
| - "DerivedCoreProperties.txt": "https://www.unicode.org/Public/UCD/latest/ucd/DerivedCoreProperties.txt", |
9 |
| - "DerivedGeneralCategory.txt": "https://www.unicode.org/Public/UCD/latest/ucd/extracted/DerivedGeneralCategory.txt", |
10 |
| - "EastAsianWidth.txt": "https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt", |
11 |
| - "GraphemeBreakProperty.txt": "https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakProperty.txt", |
12 |
| - "GraphemeBreakTest.txt": "https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakTest.txt", |
13 |
| - "emoji-data.txt": "https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt", |
14 |
| -} |
| 9 | +def get_base_url(): |
| 10 | + if len(sys.argv) != 2: |
| 11 | + sys.exit(f"Usage: python {sys.argv[0]} [latest|<VERSION LIKE 15.0.0>]") |
| 12 | + |
| 13 | + version = sys.argv[1] |
| 14 | + |
| 15 | + if version == "latest": |
| 16 | + return "https://unicode.org/Public/UCD/latest/" |
| 17 | + |
| 18 | + return f"https://unicode.org/Public/{version}/" |
| 19 | + |
| 20 | + |
| 21 | +Unicode_data_files = [ |
| 22 | + "ucd/DerivedCoreProperties.txt", |
| 23 | + "ucd/extracted/DerivedGeneralCategory.txt", |
| 24 | + "ucd/EastAsianWidth.txt", |
| 25 | + "ucd/auxiliary/GraphemeBreakProperty.txt", |
| 26 | + "ucd/auxiliary/GraphemeBreakTest.txt", |
| 27 | + "ucd/emoji/emoji-data.txt", |
| 28 | +] |
| 29 | + |
15 | 30 |
|
16 | 31 | def download_unicode_data_files():
|
17 |
| - for filename, url in Unicode_data_files.items(): |
18 |
| - print(f"downloading {filename} from {url}") |
| 32 | + base_url = get_base_url() |
| 33 | + print(f" Base URL: {base_url}") |
| 34 | + |
| 35 | + for data_file in Unicode_data_files: |
| 36 | + url = base_url + data_file |
| 37 | + filename = PurePosixPath(data_file).name |
| 38 | + print(f"Downloading: {url}") |
19 | 39 | urlretrieve(url, filename)
|
20 | 40 |
|
21 | 41 |
|
|
0 commit comments