Skip to content

Commit 1ab6c07

Browse files
added: installation of wrapper
1 parent 71d17e2 commit 1ab6c07

File tree

3 files changed

+50
-39
lines changed

3 files changed

+50
-39
lines changed

apertium/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import platform
4+
import sys
45
from typing import Dict, Tuple
56

67
from apertium.analysis import analyze, Analyzer # noqa: F401
@@ -62,7 +63,8 @@ def update_path_windows() -> None:
6263
update_path = '{}{}{}{}'.format(current, os.pathsep, apertium_path, os.pathsep)
6364
os.environ['path'] = update_path
6465

65-
66+
if platform.system() == 'Linux':
67+
sys.path.append('/usr/lib/python3/dist-packages')
6668
pair_paths = ['/usr/share/apertium', '/usr/local/share/apertium']
6769
analyzers = {} # type: Dict[str, Tuple[str, str]]
6870
generators = {} # type: Dict[str, Tuple[str, str]]

apertium/installer.py

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

@@ -14,11 +14,10 @@ class Windows:
1414
"""Download ApertiumWin64 and Move to %localappdata%"""
1515
base_link = 'http://apertium.projectjj.com/{}'
1616

17-
def __init__(self, languages: list) -> None:
17+
def __init__(self) -> None:
1818
self._install_path = os.getenv('LOCALAPPDATA')
1919
self._apertium_path = os.path.join(self._install_path, 'apertium-all-dev')
2020
self._download_path = tempfile.mkdtemp()
21-
self._languages = languages
2221
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)
2322
self._logger = logging.getLogger()
2423
self._logger.setLevel(logging.DEBUG)
@@ -45,18 +44,15 @@ def _download_apertium_windows(self) -> None:
4544

4645
self._download_zips(apertium_windows, self._install_path)
4746

48-
def _download_package(self) -> None:
47+
def _download_package(self, packages: List[str]) -> None:
4948
"""Installs Language Data to Apertium"""
5049

51-
if platform.system() == 'Windows':
52-
zip_path = 'win32/nightly/data.php?zip='
53-
else:
54-
raise ValueError('Installation for {} is not supported'.format(platform.system()))
55-
language_zip = {}
56-
for curr_lang in self._languages:
57-
language_zip[curr_lang] = zip_path + curr_lang
50+
zip_path = 'win32/nightly/data.php?zip='
51+
package_zip = {}
52+
for curr_package in packages:
53+
package_zip[curr_package] = zip_path + curr_package
5854

59-
self._download_zips(language_zip, self._download_path)
55+
self._download_zips(package_zip, self._download_path)
6056

6157
# move the extracted files to desired location
6258
lang_data_path = os.path.join(self._download_path, 'usr', 'share', 'apertium')
@@ -100,49 +96,61 @@ def _edit_modes(self) -> None:
10096
def install_apertium_base(self) -> None:
10197
self._download_apertium_windows()
10298

103-
def install_apertium_language(self) -> None:
104-
self._download_package()
99+
def install_apertium_language(self, language: List[str]) -> None:
100+
self._download_package(language)
105101
self._edit_modes()
106102

103+
def install_wrapper(self, swig_wrappers: List[str]) -> None:
104+
pass
105+
107106

108107
class Ubuntu:
109-
def __init__(self, languages: list) -> None:
110-
self._languages = languages
108+
def __init__(self) -> None:
111109
init_script = 'wget http://apertium.projectjj.com/apt/install-nightly.sh -O - | sudo bash'
112110
subprocess.run(init_script, shell=True, check=True)
113-
self._languages = languages
114111

115112
@staticmethod
116-
def _download_package(packages: list) -> None:
113+
def _download_package(packages: List[str]) -> None:
117114
command = 'sudo apt-get -f --allow-unauthenticated install {}'
118115
for package in packages:
119116
subprocess.run(command.format(package), shell=True, check=True)
120117

121-
def install_apertium_language(self) -> None:
122-
install_packages = self._languages
123-
self._download_package(install_packages)
118+
def install_apertium_language(self, languages: List[str]) -> None:
119+
self._download_package(languages)
124120

125121
def install_apertium_base(self) -> None:
126122
self._download_package(['apertium-all-dev'])
127123

124+
def install_wrapper(self, swig_wrappers: List[str]) -> None:
125+
self._download_package(swig_wrappers)
128126

129-
def install_language_pack(languages: list = None, install_base: bool = False) -> None:
130-
if languages is None:
131-
languages = ['apertium-eng', 'apertium-en-es']
127+
128+
def get_installer_object():
132129
apertium_installer = None
133-
user_platform = platform.system()
134-
if apertium_installer == 'Windows':
135-
apertium_installer = Windows(languages)
136-
elif apertium_installer == 'Linux':
137-
distro_name = ''
130+
if platform.system() == 'Windows':
131+
apertium_installer = Windows()
132+
elif platform.system() == 'Linux':
138133
with open('/etc/os-release') as os_release:
139-
distro_name = os_release.readline().split('"')[-1]
134+
distro_name = os_release.readline().split('=')[-1].strip().replace('"', '')
140135
if distro_name == 'Ubuntu':
141-
apertium_installer = Ubuntu(languages)
136+
apertium_installer = Ubuntu()
142137
else:
143138
raise ValueError('Installation on {} not supported'.format(distro_name))
144-
else:
145-
raise ValueError('{} is not supported'.format(apertium_installer))
146-
if install_base:
147-
apertium_installer.install_apertium_base()
148-
apertium_installer.install_apertium_language()
139+
return apertium_installer
140+
141+
142+
def install_apertium() -> None:
143+
apertium_installer = get_installer_object()
144+
apertium_installer.install_apertium_base()
145+
146+
147+
def install_language_pack(languages: List[str] = None) -> None:
148+
if languages is None:
149+
languages = ['apertium-eng', 'apertium-en-es']
150+
apertium_installer = get_installer_object()
151+
apertium_installer.install_apertium_language(languages)
152+
153+
154+
def install_wrapper(swig_wrappers: List[str]) -> None:
155+
apertium_installer = get_installer_object()
156+
apertium_installer.install_wrapper(swig_wrappers)

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ def __init__(self, *args, **kwargs):
1212
@staticmethod
1313
def _post_install():
1414
import apertium
15-
apertium.installer.install_language_pack(['apertium-eng', 'apertium-en-es'], install_base=True)
16-
15+
apertium.installer.install_apertium()
16+
apertium.installer.install_language_pack(['apertium-eng', 'apertium-en-es'])
17+
apertium.installer.install_wrapper(['python3-lttoolbox'])
1718

1819
setup(
1920
name='apertium-python',

0 commit comments

Comments
 (0)