| 1 |
import os |
| 2 |
import shutil |
| 3 |
from collections import OrderedDict |
| 4 |
|
| •5 |
#from git import Repo |
| 6 |
|
| 7 |
|
| 8 |
def get_raw_data(): |
| •9 |
return # Disable git clone for Debian package |
| 10 |
cldr_version = "31.0.1" |
| 11 |
raw_data_directory = "../raw_data" |
| 12 |
|
| 13 |
cldr_data = { |
| 14 |
"dates_full": { |
| 15 |
"url": "https://github.com/unicode-cldr/cldr-dates-full.git", |
| 16 |
"dir": "{}/cldr_dates_full/".format(raw_data_directory), |
| 17 |
}, |
| 18 |
"core": { |
| 19 |
"url": "https://github.com/unicode-cldr/cldr-core.git", |
| 20 |
"dir": "{}/cldr_core/".format(raw_data_directory), |
| 21 |
}, |
| 22 |
"rbnf": { |
| 23 |
"url": "https://github.com/unicode-cldr/cldr-rbnf.git", |
| 24 |
"dir": "{}/cldr_rbnf/".format(raw_data_directory), |
| 25 |
}, |
| 26 |
} |
| 27 |
|
| 28 |
if os.path.isdir(raw_data_directory): |
| 29 |
# remove current raw data |
| 30 |
shutil.rmtree(raw_data_directory) |
| 31 |
os.mkdir(raw_data_directory) |
| 32 |
|
| 33 |
for name, data in cldr_data.items(): |
| 34 |
print('Clonning "{}" from: {}'.format(name, data["url"])) |
| 35 |
repo = Repo.clone_from(data["url"], data["dir"], branch="master") |
| 36 |
repo.git.co(cldr_version) |
| 37 |
|
| 38 |
|
| 39 |
def get_dict_difference(parent_dict, child_dict): |
| 40 |
difference_dict = OrderedDict() |
| 41 |
for key, child_value in child_dict.items(): |
| 42 |
parent_value = parent_dict.get(key) |
| 43 |
child_specific_value = None |
| 44 |
if not parent_value: |
| 45 |
child_specific_value = child_value |
| 46 |
elif isinstance(child_value, list): |
| 47 |
child_specific_value = sorted(set(child_value) - set(parent_value)) |
| 48 |
elif isinstance(child_value, dict): |
| 49 |
child_specific_value = get_dict_difference(parent_value, child_value) |
| 50 |
elif child_value != parent_value: |
| 51 |
child_specific_value = child_value |
| 52 |
if child_specific_value: |
| 53 |
difference_dict[key] = child_specific_value |
| 54 |
return difference_dict |
| 55 |
|
| 56 |
|
| 57 |
def combine_dicts(primary_dict, supplementary_dict): |
| 58 |
combined_dict = OrderedDict() |
| 59 |
for key, value in primary_dict.items(): |
| 60 |
if key in supplementary_dict: |
| 61 |
if isinstance(value, list): |
| 62 |
combined_dict[key] = value + supplementary_dict[key] |
| 63 |
elif isinstance(value, dict): |
| 64 |
combined_dict[key] = combine_dicts(value, supplementary_dict[key]) |
| 65 |
else: |
| 66 |
combined_dict[key] = supplementary_dict[key] |
| 67 |
else: |
| 68 |
combined_dict[key] = primary_dict[key] |
| 69 |
remaining_keys = [ |
| 70 |
key for key in supplementary_dict.keys() if key not in primary_dict.keys() |
| 71 |
] |
| 72 |
for key in remaining_keys: |
| 73 |
combined_dict[key] = supplementary_dict[key] |
| 74 |
return combined_dict |