77import subprocess
88import tempfile
99import tqdm
10+ import json
1011from typing import IO , Dict , Optional , Tuple
1112import zipfile
1213from datetime import datetime
3435
3536LTP_DOWNLOAD_VERSION = 'latest'
3637LT_SNAPSHOT_CURRENT_VERSION = '6.7-SNAPSHOT'
38+ SNAPSHOT_MAP_FILE = "snapshots.json"
3739
3840JAVA_VERSION_REGEX = re .compile (
3941 r'^(?:java|openjdk) version "(?P<major1>\d+)(|\.(?P<major2>\d+)\.[^"]+)"' ,
@@ -155,18 +157,18 @@ def http_get(url: str, out_file: IO[bytes], proxies: Optional[Dict[str, str]] =
155157 progress .close ()
156158
157159
158- def unzip_file (temp_file : str , directory_to_extract_to : str ) -> None :
160+ def unzip_file (temp_file_name : str , directory_to_extract_to : str ) -> None :
159161 """
160162 Unzips a zip file to a specified directory.
161163
162- :param temp_file : A temporary file object representing the zip file to be extracted.
163- :type temp_file : str
164+ :param temp_file_name : A temporary file object representing the zip file to be extracted.
165+ :type temp_file_name : str
164166 :param directory_to_extract_to: The directory where the contents of the zip file will be extracted.
165167 :type directory_to_extract_to: str
166168 """
167169
168- logger .info (f'Unzipping { temp_file . name } to { directory_to_extract_to } .' )
169- with zipfile .ZipFile (temp_file . name , 'r' ) as zip_ref :
170+ logger .info (f'Unzipping { temp_file_name } to { directory_to_extract_to } .' )
171+ with zipfile .ZipFile (temp_file_name , 'r' ) as zip_ref :
170172 zip_ref .extractall (directory_to_extract_to )
171173
172174
@@ -185,7 +187,7 @@ def download_zip(url: str, directory: str) -> None:
185187 # Close the file so we can extract it.
186188 downloaded_file .close ()
187189 # Extract zip file to path.
188- unzip_file (downloaded_file , directory )
190+ unzip_file (downloaded_file . name , directory )
189191 # Remove the temporary file.
190192 os .remove (downloaded_file .name )
191193 # Tell the user the download path.
@@ -226,14 +228,12 @@ def download_lt(language_tool_version: Optional[str] = LTP_DOWNLOAD_VERSION) ->
226228 if re .match (r'^\d+\.\d+$' , version ):
227229 filename = FILENAME_RELEASE .format (version = version )
228230 language_tool_download_url = urljoin (BASE_URL_RELEASE , filename )
229- else :
231+ dirname , _ = os .path .splitext (filename )
232+ extract_path = os .path .join (download_folder , dirname )
233+ if extract_path in old_path_list :
234+ return
235+ elif version == 'latest' :
230236 filename = FILENAME_SNAPSHOT .format (version = version )
231- language_tool_download_url = urljoin (BASE_URL_SNAPSHOT , filename )
232- dirname , _ = os .path .splitext (filename )
233- if version == "latest" :
234237 dirname = f"LanguageTool-{ LT_SNAPSHOT_CURRENT_VERSION } "
235- extract_path = os .path .join (download_folder , dirname )
236238
237- if extract_path in old_path_list :
238- return
239239 download_zip (language_tool_download_url , download_folder )
0 commit comments