Skip to content

Commit e070f97

Browse files
authored
Merge branch 'main' into pre-commit-ci-update-config
2 parents 763a277 + f22f37f commit e070f97

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

builder/pyinstaller_build_macos.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
# package
2222
sys.path.insert(0, str(Path(".").resolve()))
23+
from builder import tldextract_update
2324
from qgis_deployment_toolbelt import __about__ # noqa: E402
2425

2526
# #############################################################################
@@ -49,10 +50,14 @@
4950
mac_os_version, _, _ = platform.mac_ver()
5051
mac_os_version = "-".join(mac_os_version.split(".")[:2])
5152

53+
tldextract_update.run()
54+
5255
PyInstaller.__main__.run(
5356
[
5457
"--add-data=LICENSE:.",
5558
"--add-data=README.md:.",
59+
f"--add-data={Path(__file__).parent / 'build' / 'tldextract_cache'/ '.suffix_cache'}:tldextract/.suffix_cache",
60+
f"--add-data={Path(__file__).parent / 'build' / 'tldextract_cache'/'.tld_set_snapshot'}:tldextract/",
5661
f"--add-data={package_folder.joinpath('shortcuts/shortcut_freedesktop.template').resolve()}:profiles/",
5762
f"--log-level={getenv('PYINSTALLER_LOG_LEVEL', 'WARN')}",
5863
f"--name={output_filename}",

builder/pyinstaller_build_ubuntu.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
# package
2323
sys.path.insert(0, str(Path(".").resolve()))
24+
from builder import tldextract_update
2425
from qgis_deployment_toolbelt import __about__ # noqa: E402
2526

2627
# #############################################################################
@@ -48,10 +49,14 @@
4849
)
4950
package_folder = Path("qgis_deployment_toolbelt")
5051

52+
tldextract_update.run()
53+
5154
PyInstaller.__main__.run(
5255
[
5356
"--add-data=LICENSE:.",
5457
"--add-data=README.md:.",
58+
f"--add-data={Path(__file__).parent / 'build' / 'tldextract_cache'/ '.suffix_cache'}:tldextract/.suffix_cache",
59+
f"--add-data={Path(__file__).parent / 'build' / 'tldextract_cache'/'.tld_set_snapshot'}:tldextract/",
5560
f"--add-data={package_folder.joinpath('shortcuts/shortcut_freedesktop.template').resolve()}:shortcuts/",
5661
f"--log-level={getenv('PYINSTALLER_LOG_LEVEL', 'WARN')}",
5762
f"--name={output_filename}",

builder/pyinstaller_build_windows.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
# package
2222
sys.path.insert(0, str(Path(".").resolve()))
23+
from builder import tldextract_update
2324
from qgis_deployment_toolbelt import __about__ # noqa: E402
2425

2526
# #############################################################################
@@ -46,10 +47,14 @@
4647
)
4748
package_folder = Path("qgis_deployment_toolbelt")
4849

50+
tldextract_update.run()
51+
4952
PyInstaller.__main__.run(
5053
[
5154
"--add-data=LICENSE:.",
5255
"--add-data=README.md:.",
56+
f"--add-data={Path(__file__).parent / 'build' / 'tldextract_cache'/ '.suffix_cache'}:tldextract/.suffix_cache",
57+
f"--add-data={Path(__file__).parent / 'build' / 'tldextract_cache'/'.tld_set_snapshot'}:tldextract/",
5358
# "--clean",
5459
f"--icon={package_folder.parent.resolve()}/docs/static/logo_qdt.ico",
5560
f"--log-level={getenv('PYINSTALLER_LOG_LEVEL', 'WARN')}",

builder/tldextract_update.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#! python3 # noqa: E265
2+
3+
"""
4+
Create tldextract update cache folder
5+
6+
"""
7+
8+
# #############################################################################
9+
# ########## Libraries #############
10+
# ##################################
11+
12+
# Standard library
13+
import argparse
14+
import urllib.request
15+
from os import W_OK, access
16+
from pathlib import Path
17+
18+
# 3rd party
19+
from tldextract import TLDExtract
20+
21+
# #############################################################################
22+
# ########### MAIN #################
23+
# ##################################
24+
25+
26+
def run():
27+
"""Minimal CLI to generate a tldextract cache.
28+
29+
:raises PermissionError: if output directory already exists but it's not writable
30+
:raises SystemExit: in case of user abort
31+
32+
:example:
33+
34+
.. code-block:: bash
35+
36+
python tldextract_update.py
37+
"""
38+
# variables
39+
script_path = Path(__file__).parent
40+
41+
# cli parser arguments
42+
parser = argparse.ArgumentParser(
43+
epilog=("tdlextract cache are created in output folder")
44+
)
45+
parser.add_argument(
46+
"-o",
47+
"--output",
48+
default=script_path / "build" / "tldextract_cache",
49+
help="tld extract cache output folder",
50+
type=Path,
51+
)
52+
53+
args = parser.parse_args()
54+
55+
try:
56+
# check output directory
57+
output_dir = Path(args.output)
58+
if output_dir.exists() and not access(output_dir, W_OK):
59+
raise PermissionError(output_dir.resolve())
60+
61+
output_dir.mkdir(exist_ok=True, parents=True)
62+
63+
tld_extract = TLDExtract(str(output_dir / ".suffix_cache"))
64+
tld_extract.update(True)
65+
66+
urllib.request.urlretrieve(
67+
"https://publicsuffix.org/list/public_suffix_list.dat",
68+
output_dir / ".tld_set_snapshot",
69+
)
70+
71+
# log user
72+
print(f"tldextract cache written to: {output_dir.resolve()}")
73+
except KeyboardInterrupt:
74+
raise SystemExit("Aborted by user request.")
75+
76+
77+
# Stand alone execution
78+
if __name__ == "__main__":
79+
run()

0 commit comments

Comments
 (0)