From 295a2afc72a02b7d8c4205fd3a26005d5bf7e168 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:51:53 +0600 Subject: [PATCH 1/4] add --- resvg_py/__init__.py | 10 ++++++++++ resvg_py/downloader.py | 20 ++++++++++++++++++++ src/__init__.py | 0 test.py | 3 +++ 4 files changed, 33 insertions(+) create mode 100644 resvg_py/__init__.py create mode 100644 resvg_py/downloader.py delete mode 100644 src/__init__.py create mode 100644 test.py diff --git a/resvg_py/__init__.py b/resvg_py/__init__.py new file mode 100644 index 0000000..8e423bc --- /dev/null +++ b/resvg_py/__init__.py @@ -0,0 +1,10 @@ +import platform + +plt = platform.system().lower() + +if plt == "windows": + print("Your system is Windows") +elif plt == "linux": + print("Your system is Linux") +else: + print("Unidentified system") diff --git a/resvg_py/downloader.py b/resvg_py/downloader.py new file mode 100644 index 0000000..c49324c --- /dev/null +++ b/resvg_py/downloader.py @@ -0,0 +1,20 @@ +import urllib.request +import zipfile + +from pathlib import Path + +BASE_DIR = Path(__file__).resolve().parent + +version = "0.40.0" + + +def download_windows(): + location = Path(BASE_DIR, "win.zip") + + urllib.request.urlretrieve( + f"https://github.com/RazrFalcon/resvg/releases/download/v{version}/resvg-win64.zip", + location, + ) + + with zipfile.ZipFile(location, "r") as zip_ref: + zip_ref.extractall() diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test.py b/test.py new file mode 100644 index 0000000..861e14f --- /dev/null +++ b/test.py @@ -0,0 +1,3 @@ +from resvg_py.downloader import download_windows + +download_windows() From 4f3389e1339ef316bb6172db674c0a4f92ef7319 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:55:32 +0600 Subject: [PATCH 2/4] add --- resvg_py/downloader.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/resvg_py/downloader.py b/resvg_py/downloader.py index c49324c..b867706 100644 --- a/resvg_py/downloader.py +++ b/resvg_py/downloader.py @@ -1,6 +1,6 @@ import urllib.request import zipfile - +import os from pathlib import Path BASE_DIR = Path(__file__).resolve().parent @@ -17,4 +17,7 @@ def download_windows(): ) with zipfile.ZipFile(location, "r") as zip_ref: - zip_ref.extractall() + zip_ref.extractall(path=BASE_DIR) + for file in BASE_DIR.glob("*exe"): + if "resvg.exe" in file.name: + os.remove(location) From aa822f19493323436e7f981e26b4fc3516828c54 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sat, 24 Feb 2024 12:21:18 +0600 Subject: [PATCH 3/4] add --- .gitignore | 2 ++ resvg_py/downloader.py | 21 ++++++++++++--------- resvg_py/main.py | 26 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 resvg_py/main.py diff --git a/.gitignore b/.gitignore index d9005f2..b91c29c 100644 --- a/.gitignore +++ b/.gitignore @@ -150,3 +150,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +*exe \ No newline at end of file diff --git a/resvg_py/downloader.py b/resvg_py/downloader.py index b867706..a0d1790 100644 --- a/resvg_py/downloader.py +++ b/resvg_py/downloader.py @@ -1,7 +1,7 @@ import urllib.request import zipfile -import os from pathlib import Path +import tempfile BASE_DIR = Path(__file__).resolve().parent @@ -9,15 +9,18 @@ def download_windows(): - location = Path(BASE_DIR, "win.zip") + for file in BASE_DIR.glob("*.exe"): + if "resvg.exe" in file.name: + return - urllib.request.urlretrieve( + f = urllib.request.urlopen( f"https://github.com/RazrFalcon/resvg/releases/download/v{version}/resvg-win64.zip", - location, ) - with zipfile.ZipFile(location, "r") as zip_ref: - zip_ref.extractall(path=BASE_DIR) - for file in BASE_DIR.glob("*exe"): - if "resvg.exe" in file.name: - os.remove(location) + with tempfile.NamedTemporaryFile() as fp: + fp.write(f.read()) + + with zipfile.ZipFile(fp, "r") as zip_ref: + zip_ref.extractall(path=BASE_DIR) + + fp.close() diff --git a/resvg_py/main.py b/resvg_py/main.py new file mode 100644 index 0000000..523c80b --- /dev/null +++ b/resvg_py/main.py @@ -0,0 +1,26 @@ +import subprocess +from .downloader import download_windows +import platform + +from pathlib import Path + +BASE_DIR = Path(__file__).resolve().parent + +plt = platform.system().lower() + +if plt == "windows": + download_windows() + binary = Path(BASE_DIR, "resvg.exe") +elif plt == "linux": + print("Your system is Linux") +else: + print("Unidentified system") + + +def main_function(input: str, output: str): + subprocess.Popen( + f"{binary} {input} {output}", + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + bufsize=2**12, + ) From fde6e8543557161139c497b36049079ab246c67e Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sat, 24 Feb 2024 12:43:13 +0600 Subject: [PATCH 4/4] add --- .gitignore | 3 ++- resvg_py/__init__.py | 10 ---------- resvg_py/downloader.py | 27 ++++++++++++++++++++++++--- resvg_py/main.py | 5 +++-- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index b91c29c..a915c8a 100644 --- a/.gitignore +++ b/.gitignore @@ -151,4 +151,5 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -*exe \ No newline at end of file +resvg +resvg.exe \ No newline at end of file diff --git a/resvg_py/__init__.py b/resvg_py/__init__.py index 8e423bc..e69de29 100644 --- a/resvg_py/__init__.py +++ b/resvg_py/__init__.py @@ -1,10 +0,0 @@ -import platform - -plt = platform.system().lower() - -if plt == "windows": - print("Your system is Windows") -elif plt == "linux": - print("Your system is Linux") -else: - print("Unidentified system") diff --git a/resvg_py/downloader.py b/resvg_py/downloader.py index a0d1790..cb28929 100644 --- a/resvg_py/downloader.py +++ b/resvg_py/downloader.py @@ -2,17 +2,22 @@ import zipfile from pathlib import Path import tempfile +import tarfile BASE_DIR = Path(__file__).resolve().parent version = "0.40.0" -def download_windows(): - for file in BASE_DIR.glob("*.exe"): - if "resvg.exe" in file.name: +def _skip_if_file_exists(): + for file in BASE_DIR.glob("*"): + if "resvg" in file.name: return + +def download_windows(): + _skip_if_file_exists() + f = urllib.request.urlopen( f"https://github.com/RazrFalcon/resvg/releases/download/v{version}/resvg-win64.zip", ) @@ -24,3 +29,19 @@ def download_windows(): zip_ref.extractall(path=BASE_DIR) fp.close() + + +def download_linux(): + _skip_if_file_exists() + + f = urllib.request.urlopen( + f"https://github.com/RazrFalcon/resvg/releases/download/v{version}/resvg-linux-x86_64.tar.gz", + ) + + with tempfile.NamedTemporaryFile( + "wb", suffix=".tar.gz", delete_on_close=False + ) as fp: + fp.write(f.read()) + + with tarfile.open(fp.name, "r:gz") as tar: + tar.extractall(path=BASE_DIR) diff --git a/resvg_py/main.py b/resvg_py/main.py index 523c80b..3207f18 100644 --- a/resvg_py/main.py +++ b/resvg_py/main.py @@ -1,5 +1,5 @@ import subprocess -from .downloader import download_windows +from .downloader import download_windows, download_linux import platform from pathlib import Path @@ -12,7 +12,8 @@ download_windows() binary = Path(BASE_DIR, "resvg.exe") elif plt == "linux": - print("Your system is Linux") + download_linux() + binary = Path(BASE_DIR, "resvg") else: print("Unidentified system")