commit 74d18c008d46aab62ba80831c4df1e56a7171024 Author: vaydheesh Date: Thu Jul 18 00:21:02 2019 +0530 added: os based installation support for ubuntu & windows diff --git a/.travis.yml b/.travis.yml index 230c37c..a682c0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,9 +14,7 @@ install: - pip install pipenv - pipenv install --dev --system before_script: - - wget http://apertium.projectjj.com/apt/install-nightly.sh -O - | sudo bash - - sudo apt-get -f --allow-unauthenticated install apertium-all-dev - - sudo apt-get -f --allow-unauthenticated install apertium-nno-nob apertium-es-en apertium-eng + - python3 setup.py install - python3 setup.py test - ./build-swig-wrapper.sh script: diff --git a/Pipfile b/Pipfile index ef46445..cc52dee 100644 --- a/Pipfile +++ b/Pipfile @@ -20,3 +20,4 @@ sphinx = "*" [packages] apertium-streamparser = "*" +distro = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 1655fee..7c85120 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "f3c0d4b2a7f1f81a6b8c819e094e4bbb2df663ee1d66437003e788f9930af28d" + "sha256": "c66a1d9a8db13b9264dc5c28e2031c35c240f4d6a2d8f4424d7e0abc8b61a53a" }, "pipfile-spec": 6, "requires": {}, @@ -21,6 +21,14 @@ ], "index": "pypi", "version": "==5.0.2" + }, + "distro": { + "hashes": [ + "sha256:362dde65d846d23baee4b5c058c8586f219b5a54be1cf5fc6ff55c4578392f57", + "sha256:eedf82a470ebe7d010f1872c17237c79ab04097948800029994fa458e52fb4b4" + ], + "index": "pypi", + "version": "==1.4.0" } }, "develop": { @@ -133,11 +141,11 @@ }, "flake8": { "hashes": [ - "sha256:859996073f341f2670741b51ec1e67a01da142831aa1fdc6242dbf88dffbe661", - "sha256:a796a115208f5c03b18f332f7c11729812c8c3ded6c46319c59b53efd3819da8" + "sha256:19241c1cbc971b9962473e4438a2ca19749a7dd002dd1a946eaba171b4114548", + "sha256:8e9dfa3cecb2400b3738a42c54c3043e821682b9c840b0448c0503f781130696" ], "index": "pypi", - "version": "==3.7.7" + "version": "==3.7.8" }, "flake8-bugbear": { "hashes": [ @@ -265,20 +273,20 @@ }, "mypy": { "hashes": [ - "sha256:12d18bd7fc642c5d54b1bb62dde813a7e2ab79b32ee11ff206ac387c68fc2ad4", - "sha256:23e24bc1683a36f39dee67d8ac74ea414654642eee26d420bada95b8ee8c9095", - "sha256:2b38e64c52a8968df4ebcae0ddba4a54eb94d184695dd4e54e14509a9389b78c", - "sha256:3d4f551466a76e278187ec3a5b26cfb50f72f6760b749aa00ac69a6f9c99898d", - "sha256:53d5dacb8d844e50be698830509aa592b093547e7ab90aee63eb23db61109007", - "sha256:56f981d246010ba21cac6b2455eaecfaf68fc8a5663d865b26c8e579c36f751d", - "sha256:8c57f6f59f1e8479d9fc6e1bf034353e54626ed64e32394c613afc493a441dc1", - "sha256:bbed4a593d87476b592d52867ef86da2155ccd0becf0c4c02e6567d842e43368", - "sha256:d6ff850e2ba18b2db7704897c8f2f1384478e3b75ad292ec06196bf7794f3a40", - "sha256:e13b1bb8785d7f785e0b88873f1c21cda58ceba9ce1153b58cbfa24b09a111d5", - "sha256:e2b9ee6f648ce72d6741925a47c88c2391168ef973b6f74f17969450c5b1ffdd" + "sha256:0107bff4f46a289f0e4081d59b77cef1c48ea43da5a0dbf0005d54748b26df2a", + "sha256:07957f5471b3bb768c61f08690c96d8a09be0912185a27a68700f3ede99184e4", + "sha256:10af62f87b6921eac50271e667cc234162a194e742d8e02fc4ddc121e129a5b0", + "sha256:11fd60d2f69f0cefbe53ce551acf5b1cec1a89e7ce2d47b4e95a84eefb2899ae", + "sha256:15e43d3b1546813669bd1a6ec7e6a11d2888db938e0607f7b5eef6b976671339", + "sha256:352c24ba054a89bb9a35dd064ee95ab9b12903b56c72a8d3863d882e2632dc76", + "sha256:437020a39417e85e22ea8edcb709612903a9924209e10b3ec6d8c9f05b79f498", + "sha256:49925f9da7cee47eebf3420d7c0e00ec662ec6abb2780eb0a16260a7ba25f9c4", + "sha256:6724fcd5777aa6cebfa7e644c526888c9d639bd22edd26b2a8038c674a7c34bd", + "sha256:7a17613f7ea374ab64f39f03257f22b5755335b73251d0d253687a69029701ba", + "sha256:cdc1151ced496ca1496272da7fc356580e95f2682be1d32377c22ddebdf73c91" ], "index": "pypi", - "version": "==0.711" + "version": "==0.720" }, "mypy-extensions": { "hashes": [ diff --git a/apertium/__init__.py b/apertium/__init__.py index c462f04..042e14b 100644 --- a/apertium/__init__.py +++ b/apertium/__init__.py @@ -5,6 +5,7 @@ from typing import Dict, Tuple from apertium.analysis import analyze, Analyzer # noqa: F401 from apertium.generation import generate, Generator # noqa: F401 +from apertium.installer import install_language_pack from apertium.mode_search import search_path from apertium.translation import translate, Translator # noqa: F401 diff --git a/installer.py b/apertium/installer.py similarity index 73% rename from installer.py rename to apertium/installer.py index e5cd962..42991c6 100644 --- a/installer.py +++ b/apertium/installer.py @@ -5,12 +5,14 @@ import logging import os import platform import shutil +import subprocess import tempfile from urllib.request import urlretrieve from zipfile import ZipFile class Windows: + """Download ApertiumWin64 and Move to %localappdata%""" base_link = 'http://apertium.projectjj.com/{}' def __init__(self, languages: list) -> None: @@ -25,7 +27,7 @@ class Windows: def _download_zips(self, download_files: dict, extract_path: Optional[str]) -> None: for zip_name, zip_link in download_files.items(): zip_download_path = os.path.join(self._download_path, zip_name) - urlretrieve(Installer.base_link.format(zip_link), filename=zip_download_path) + urlretrieve(Windows.base_link.format(zip_link), filename=zip_download_path) self._logger.info('%s download completed', zip_name) # Extract the zip @@ -96,15 +98,45 @@ class Windows: outfile.write(line) outfile.close() - def install_windows(self): + def install_apertium_base(self) -> None: self._download_apertium_windows() + + def install_apertium_language(self) -> None: self._download_package() self._edit_modes() -def install_apertium_windows(): - """Download ApertiumWin64 and Move to %localappdata%""" +class Ubuntu: + def __init__(self, languages: list) -> None: + self._languages = languages + init_script = 'wget http://apertium.projectjj.com/apt/install-nightly.sh -O - | sudo bash' + subprocess.run(init_script, shell=True, check=True) + self._languages = languages + + @staticmethod + def _download_package(packages: list) -> None: + command = 'sudo apt-get -f --allow-unauthenticated install {}' + for package in packages: + subprocess.run(command.format(package), shell=True, check=True) + + def install_apertium_language(self) -> None: + install_packages = self._languages + self._download_package(install_packages) + + def install_apertium_base(self) -> None: + self._download_package(['apertium-all-dev']) + +def install_language_pack(languages: list = None, install_base: bool = False) -> None: + if languages is None: + languages = ['apertium-eng', 'apertium-en-es'] + apertium_installer = None if platform.system() == 'Windows': - p = Installer(['apertium-eng', 'apertium-en-es']) - p.install_windows() + apertium_installer = Windows(languages) + elif distro.name() == 'Ubuntu': + apertium_installer = Ubuntu(languages) + else: + raise ValueError('Installation on {} not supported'.format(distro.name())) + if install_base: + apertium_installer.install_apertium_base() + apertium_installer.install_apertium_language() diff --git a/setup.py b/setup.py index 07ed5db..cb4d7eb 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,5 @@ from atexit import register from os import path - -import installer - from setuptools import find_packages, setup # noqa: I202 from setuptools.command.install import install @@ -14,7 +11,8 @@ class PostInstallCommand(install): @staticmethod def _post_install(): - installer.install_apertium_windows() + import apertium + apertium.installer.install_language_pack(['apertium-eng', 'apertium-en-es'], install_base=True) setup( @@ -27,6 +25,7 @@ setup( python_requires='>=3.4', install_requires=[ 'apertium-streamparser==5.0.2', + 'distro', ], test_suite='tests', packages=find_packages(exclude=['tests']),