Skip to content

Commit bac5bf7

Browse files
windows: wrapper installation
1 parent 8506f5e commit bac5bf7

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

apertium/installer.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import platform
55
import shutil
66
import subprocess
7+
import sysconfig
78
import tempfile
8-
from typing import Optional
99
from urllib.request import urlretrieve
1010
from zipfile import ZipFile
1111

@@ -22,7 +22,7 @@ def __init__(self) -> None:
2222
self._logger = logging.getLogger()
2323
self._logger.setLevel(logging.DEBUG)
2424

25-
def _download_zip(self, download_files: dict, extract_path: Optional[str]) -> None:
25+
def _download_zip(self, download_files: dict, extract_path: str) -> None:
2626
for zip_name, zip_link in download_files.items():
2727
zip_download_path = os.path.join(self._download_path, zip_name)
2828
urlretrieve(Windows.base_link.format(zip_link), filename=zip_download_path)
@@ -94,9 +94,25 @@ def install_apertium_module(self, language: str) -> None:
9494
self._download_package(language)
9595
self._edit_modes()
9696

97-
def install_wrapper(self, swig_wrapper: str) -> None:
98-
# TODO: create installer for wrappers on windows
99-
pass
97+
def install_wrapper(self, swig_wrapper: str = '') -> None:
98+
wrapper_link = 'https://codeload.github.com/Vaydheesh/wrappers/zip/windows'
99+
zip_name = 'windows.zip'
100+
zip_download_path = os.path.join(os.environ['temp'], zip_name)
101+
urlretrieve(wrapper_link, filename=zip_download_path)
102+
103+
extract_path = tempfile.mkdtemp()
104+
# Extract the zip
105+
with ZipFile(zip_download_path) as zip_file:
106+
zip_file.extractall(path=extract_path)
107+
self._logger.info('%s Extraction completed', zip_name)
108+
109+
self._logger.info('Copying wrapper to site-packages')
110+
site_packages = sysconfig.get_paths()['purelib']
111+
for directory in os.listdir(extract_path):
112+
source = os.path.join(extract_path, directory)
113+
destination = site_packages
114+
copy_tree(source, destination)
115+
self._logger.info('%s -> %s', source, destination)
100116

101117

102118
class Ubuntu:

0 commit comments

Comments
 (0)