Skip to content

Commit

Permalink
Removed redundant code and renamed class method
Browse files Browse the repository at this point in the history
- Removed: Redundant removal of single quotes from .mode files
- Renamed: Installer methods to suggest internal usage
  • Loading branch information
singh-lokendra committed Apr 11, 2019
1 parent 08d5344 commit f0476a4
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions installer.py
Expand Up @@ -35,7 +35,7 @@ def _download_zip(self, download_files, extract_path): # type: (Installer, dict
os.remove(zip_download_path)
self._logger.info("%s removed", zip_name)

def download_apertium_windows(self): # type: (Installer) -> None
def _download_apertium_windows(self): # type: (Installer) -> None
"""Installs Apertium-all-dev to %localappdata%"""

apertium_windows = {
Expand All @@ -45,7 +45,7 @@ def download_apertium_windows(self): # type: (Installer) -> None

self._download_zip(apertium_windows, self._install_path)

def download_package(self): # type: (Installer) -> None
def _download_package(self): # type: (Installer) -> None
"""Installs Language Data to Apertium"""

zip_path = ""
Expand All @@ -70,12 +70,11 @@ def download_package(self): # type: (Installer) -> None

shutil.rmtree(os.path.join(self._download_path, "usr"))

def edit_modes(self): # type: (Installer) -> None
def _edit_modes(self): # type: (Installer) -> None
"""The mode files need to be modified before being used on Windows System
1. Replace /usr/share with %localappdata%\apertium-all-dev\share
2. Replace "/" with "\" to make path compatible with Windows System
3. Remove single quotes as it causes FileNotFound Error
"""

# List of Mode Files
Expand All @@ -92,20 +91,16 @@ def edit_modes(self): # type: (Installer) -> None
if len(t) > 2 and t[0] == "'" and t[1] == "/":
t = t.replace("/", "\\")
t = t.replace(r"\usr", self._apertium_path)
# Instead of calling eng.autogen.bin, cmd calls "eng.autogen.bin"
# Raising Error: "File can't be opened error"
# Hence removing quotes from file
t = t.replace("'", "")
contents[i] = t
line = " ".join(contents)
with open(os.path.join(mode_path, f), "w") as outfile:
outfile.write(line)
outfile.close()

def install_windows(self):
self.download_apertium_windows()
self.download_package()
self.edit_modes()
self._download_apertium_windows()
self._download_package()
self._edit_modes()

def install_apertium_windows():
"""Download ApertiumWin64 and Move to %localappdata%"""
Expand Down

0 comments on commit f0476a4

Please sign in to comment.