Skip to content

Commit

Permalink
Added: Logging Module
Browse files Browse the repository at this point in the history
  • Loading branch information
singh-lokendra committed Apr 6, 2019
1 parent ed63123 commit 2c1858f
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions installer.py
Expand Up @@ -5,6 +5,7 @@
import platform
from distutils.dir_util import copy_tree
from shutil import rmtree
import logging


class Installer:
Expand All @@ -19,24 +20,27 @@ def __init__(self, languages: tuple):
# Remove abandoned files from previous incomplete install
if path.isdir(self._download_path):
rmtree(self._download_path)

os.mkdir(self._download_path)

self._languages = languages
logging.basicConfig(filename='installer.log',format='%(asctime)s %(message)s',
filemode='w', level=logging.DEBUG)
self._logger=logging.getLogger()
self._logger.setLevel(logging.DEBUG)

@staticmethod
def _download_zip(download_files: dict, download_dir, extract_path):
def _download_zip(self, download_files: dict, download_dir, extract_path):
for zip_name, zip_link in download_files.items():
zip_download_path = path.join(download_dir, zip_name)
urlretrieve(zip_link, filename=zip_download_path)
print("{} download completed".format(zip_name))
self._logger.info('%s download completed', zip_name)

# Extact the zip
zip_obj = ZipFile(zip_download_path, 'r')
zip_obj.extractall(path=extract_path)
zip_obj.close()
print("Extraction completed")
self._logger.info("%s Extraction completed", zip_name)
os.remove(zip_download_path)
print("zip removed")
self._logger.info("%s removed", zip_name)

def download_apertium_windows(self):
"""Installs Apertium-all-dev to %localappdata%"""
Expand Down Expand Up @@ -66,12 +70,12 @@ def download_language_data(self):
# move the extracted files to desired location
lang_data_path = path.join(self._download_path, 'usr', 'share', 'apertium')

print("Copying Language Data to Apertium")
self._logger.info("Copying Language Data to Apertium")
for directory in os.listdir(lang_data_path):
source = path.join(lang_data_path, directory)
destination = path.join(self._apertium_path, 'share', 'apertium', directory)
copy_tree(source, destination)
print(source, '->', destination)
self._logger.info('%s -> %s', source, destination)

rmtree(path.join(extract_path, 'usr'))

Expand All @@ -90,7 +94,7 @@ def mode_editor(self):
'mode' in file]

for file in only_files:
print(f"Opening {file} for editing")
self._logger.info("Opening %s for editing", file)
infile = open(path.join(mode_path, file), 'r')
line = infile.read()
infile.close()
Expand All @@ -109,7 +113,7 @@ def mode_editor(self):
outfile = open(path.join(mode_path, file), 'w')
outfile.write(line)
outfile.close()
print(f"Closing {file}")
self._logger.info("Closing %s", file)


def install_apertium_windows():
Expand Down

0 comments on commit 2c1858f

Please sign in to comment.