Skip to content

Commit 4a02d21

Browse files
author
spirit
committed
Backed out changeset: df47e182521c
1 parent b285a37 commit 4a02d21

2 files changed

Lines changed: 30 additions & 35 deletions

File tree

‎download_lt.py‎

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
from distutils.version import LooseVersion
3030
NormalizedVersion = None
3131

32-
import language_tool
33-
3432

3533
BASE_URL = "http://www.languagetool.org/download/"
3634
PACKAGE_PATH = "language_tool"
@@ -55,15 +53,14 @@ class Version(LooseVersion):
5553

5654

5755
def download_lt(update=False):
58-
"""Download and extract LanguageTool distribution into package directory.
59-
"""
6056
assert os.path.isdir(PACKAGE_PATH)
61-
try:
62-
lt_dir = language_tool.get_language_tool_dir()
63-
except language_tool.Error:
64-
lt_dir = None
57+
old_path_list = [
58+
path for path in
59+
glob.glob(os.path.join(PACKAGE_PATH, "LanguageTool*"))
60+
if os.path.isdir(path)
61+
]
6562

66-
if lt_dir and not update:
63+
if old_path_list and not update:
6764
return
6865

6966
contents = ""
@@ -89,24 +86,29 @@ def download_lt(update=False):
8986
]
9087

9188
filename, version = matches[-1]
92-
93-
if lt_dir:
94-
try:
95-
installed_version = Version(language_tool.get_version())
96-
update_needed = installed_version < version
97-
except TypeError:
98-
update_needed = True
99-
else:
100-
update_needed = True
101-
102-
if not update_needed:
103-
print("No update needed: {!s}".format(installed_version))
104-
return
105-
10689
url = urljoin(BASE_URL, filename)
10790
dirname = os.path.splitext(filename)[0]
10891
extract_path = os.path.join(PACKAGE_PATH, dirname)
10992

93+
if extract_path in old_path_list:
94+
print("No update needed: {!r}".format(dirname))
95+
return
96+
97+
for old_path in old_path_list:
98+
match = re.search("LanguageTool-(\d+.*?)$", old_path)
99+
if match:
100+
current_version = Version(match.group(1))
101+
try:
102+
version_test = current_version > version
103+
except TypeError:
104+
continue
105+
if version_test:
106+
print(
107+
"Local version: {!r}, Remote version: {!r}"
108+
.format(str(current_version), str(version))
109+
)
110+
return
111+
110112
with closing(TemporaryFile()) as t:
111113
with closing(urlopen(url)) as u:
112114
content_len = int(u.headers["Content-Length"])
@@ -128,13 +130,12 @@ def download_lt(update=False):
128130
sys.stdout.flush()
129131
sys.stdout.write("\n")
130132
t.seek(0)
131-
132-
if lt_dir and os.path.isdir(lt_dir):
133-
shutil.rmtree(lt_dir)
134-
133+
for old_path in old_path_list:
134+
if os.path.isdir(old_path):
135+
shutil.rmtree(old_path)
135136
with closing(ZipFile(t)) as z:
136137
z.extractall(extract_path)
137138

138139

139140
if __name__ == "__main__":
140-
sys.exit(download_lt(update="--no-update" not in sys.argv))
141+
sys.exit(download_lt(update=True))

‎setup_language_tool.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import sys
22

3-
if sys.version_info[0] < 3:
4-
import subprocess
5-
6-
def download_lt(update=False):
7-
return subprocess.call(["download_lt.py", "--no-update"])
8-
else:
9-
from download_lt import download_lt
3+
from download_lt import download_lt
104

115

126
def hook(config):

0 commit comments

Comments
 (0)