33"""Download latest LanguageTool distribution."""
44
55import glob
6+ import logging
67import os
78import re
89import requests
1718from urllib .parse import urljoin
1819from .utils import get_download_directory
1920
21+ # Create logger for this file.
22+ logging .basicConfig (format = '%(message)s' )
23+ logger = logging .getLogger (__name__ )
24+ logger .setLevel (logging .INFO )
25+
26+
2027# Get download host from environment or default.
2128BASE_URL = os .environ .get ('LTP_DOWNLOAD_HOST' , 'https://www.languagetool.org/download/' )
2229FILENAME = 'LanguageTool-{version}.zip'
@@ -95,7 +102,7 @@ def http_get(url, out_file, proxies=None):
95102 total = int (content_length ) if content_length is not None else None
96103 if req .status_code == 403 : # Not found on AWS
97104 raise Exception ('Could not find at URL {}.' .format (url ))
98- progress = tqdm .tqdm (unit = "B" , unit_scale = True , total = total )
105+ progress = tqdm .tqdm (unit = "B" , unit_scale = True , total = total , desc = 'Downloading LanguageTool' )
99106 for chunk in req .iter_content (chunk_size = 1024 ):
100107 if chunk : # filter out keep-alive new chunks
101108 progress .update (len (chunk ))
@@ -104,7 +111,7 @@ def http_get(url, out_file, proxies=None):
104111
105112def unzip_file (temp_file , directory_to_extract_to ):
106113 """ Unzips a .zip file to folder path. """
107- print ('Unzipping {} to {}.' .format (temp_file .name , directory_to_extract_to ))
114+ logger . info ('Unzipping {} to {}.' .format (temp_file .name , directory_to_extract_to ))
108115 with zipfile .ZipFile (temp_file .name , 'r' ) as zip_ref :
109116 zip_ref .extractall (directory_to_extract_to )
110117
@@ -121,7 +128,7 @@ def download_zip(url, directory):
121128 # Remove the temporary file.
122129 os .remove (downloaded_file .name )
123130 # Tell the user the download path.
124- print ('Downloaded {} to {}.' .format (url , directory ))
131+ logger . info ('Downloaded {} to {}.' .format (url , directory ))
125132
126133def download_lt (update = False ):
127134 download_folder = get_download_directory ()
@@ -143,7 +150,7 @@ def download_lt(update=False):
143150 extract_path = os .path .join (download_folder , dirname )
144151
145152 if extract_path in old_path_list :
146- print ('No update needed: {!r}' .format (dirname ))
153+ logger . warn ('No update needed: {!r}' .format (dirname ))
147154 return
148155
149156 download_zip (language_tool_download_url , download_folder )
0 commit comments