|
4 | 4 | from __future__ import with_statement
|
5 | 5 | from __future__ import print_function
|
6 | 6 |
|
| 7 | +import os |
| 8 | +import sys |
| 9 | +import importlib.resources |
7 | 10 | import re
|
8 | 11 | import collections.abc
|
9 | 12 |
|
|
33 | 36 | "JSPlatform"]
|
34 | 37 |
|
35 | 38 |
|
| 39 | +# ICU |
| 40 | +ICU_DATA_FOLDERS_UNIX = ("/usr/share/stpyv8", os.path.expanduser("~/.local/share/stpyv8")) |
| 41 | +ICU_DATA_FOLDERS_OSX = ("/Library/Application Support/STPyV8", os.path.expanduser('~/Library/Application Support/STPyV8')) |
| 42 | +ICU_DATA_FOLDERS_WINDOWS = (os.path.join(os.environ["PROGRAMDATA"], "STPyV8") if "PROGRAMDATA" in os.environ else None, ) |
| 43 | + |
| 44 | +icu_data_folders = None |
| 45 | +if os.name in ("posix", ): |
| 46 | + icu_data_folders = ICU_DATA_FOLDERS_OSX if sys.platform in ("darwin", ) else ICU_DATA_FOLDERS_UNIX |
| 47 | +else: |
| 48 | + icu_data_folders = ICU_DATA_FOLDERS_WINDOWS |
| 49 | + |
| 50 | + |
36 | 51 | class JSAttribute:
|
37 | 52 | def __init__(self, name):
|
38 | 53 | self.name = name
|
@@ -326,6 +341,36 @@ def __exit__(self, exc_type, exc_value, traceback):
|
326 | 341 | del self
|
327 | 342 |
|
328 | 343 |
|
| 344 | + |
| 345 | +def icu_sync(): |
| 346 | + try: |
| 347 | + files = importlib.resources.files('stpyv8-icu') |
| 348 | + except ModuleNotFoundError: |
| 349 | + return |
| 350 | + |
| 351 | + for f in files.iterdir(): |
| 352 | + if f.name not in ('icudtl.dat', ): |
| 353 | + continue |
| 354 | + |
| 355 | + synced = False |
| 356 | + |
| 357 | + data = f.read_bytes() |
| 358 | + |
| 359 | + for folder in icu_data_folders: |
| 360 | + try: |
| 361 | + os.makedirs(folder, exist_ok = True) |
| 362 | + with open(os.path.join(folder, 'icudtl.dat'), mode = 'wb') as fd: |
| 363 | + fd.write(data) |
| 364 | + |
| 365 | + synced = True |
| 366 | + except PermissionError: |
| 367 | + pass |
| 368 | + |
| 369 | + if synced: |
| 370 | + f.unlink() |
| 371 | + |
| 372 | +icu_sync() |
| 373 | + |
329 | 374 | v8_default_platform = JSPlatform()
|
330 | 375 | v8_default_platform.init()
|
331 | 376 |
|
|
0 commit comments