Skip to content

Commit b9db294

Browse files
committed
log outputs to stderr, better download progress bar
1 parent e1460f6 commit b9db294

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎language_tool_python/download_lt.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Download latest LanguageTool distribution."""
44

55
import glob
6+
import logging
67
import os
78
import re
89
import requests
@@ -17,6 +18,12 @@
1718
from urllib.parse import urljoin
1819
from .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.
2128
BASE_URL = os.environ.get('LTP_DOWNLOAD_HOST', 'https://www.languagetool.org/download/')
2229
FILENAME = '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

105112
def 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

126133
def 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)

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='language_tool_python',
10-
version='2.2.2',
10+
version='2.2.3',
1111
description='Checks grammar using LanguageTool.',
1212
long_description_content_type='text/markdown',
1313
long_description=long_description,

0 commit comments

Comments
 (0)