|
30 | 30 | NormalizedVersion = None |
31 | 31 |
|
32 | 32 |
|
33 | | -BASE_URLS = ['http://www.languagetool.org/download/'] |
| 33 | +BASE_URL = 'http://www.languagetool.org/download/' |
| 34 | +FILENAME = 'LanguageTool-2.3.zip' |
34 | 35 | PACKAGE_PATH = 'language_tool' |
35 | 36 |
|
36 | 37 |
|
@@ -72,64 +73,20 @@ def download_lt(update=False): |
72 | 73 | if old_path_list and not update: |
73 | 74 | return |
74 | 75 |
|
75 | | - contents = '' |
76 | | - |
77 | | - for n, base_url in enumerate(BASE_URLS): |
78 | | - try: |
79 | | - with closing(urlopen(base_url)) as u: |
80 | | - while True: |
81 | | - data = u.read() |
82 | | - if not data: |
83 | | - break |
84 | | - contents += data.decode() |
85 | | - break |
86 | | - except IOError: |
87 | | - if n == len(BASE_URLS) - 1: |
88 | | - raise |
89 | | - |
90 | | - href_format = r'<a href="(LanguageTool-(\d+.*?)\.{})">' |
91 | | - |
92 | | - matches = [ |
93 | | - (m.group(1), Version(m.group(2))) for m in |
94 | | - re.finditer(href_format.format('zip'), contents, re.I) |
95 | | - ] |
96 | | - |
97 | | - if not matches: |
98 | | - matches = [ |
99 | | - (m.group(1), Version(m.group(2))) for m in |
100 | | - re.finditer(href_format.format('oxt'), contents, re.I) |
101 | | - ] |
102 | | - |
103 | | - filename, version = matches[-1] |
104 | | - url = urljoin(base_url, filename) |
105 | | - dirname = os.path.splitext(filename)[0] |
| 76 | + url = urljoin(BASE_URL, FILENAME) |
| 77 | + dirname = os.path.splitext(FILENAME)[0] |
106 | 78 | extract_path = os.path.join(PACKAGE_PATH, dirname) |
107 | 79 |
|
108 | 80 | if extract_path in old_path_list: |
109 | 81 | print('No update needed: {!r}'.format(dirname)) |
110 | 82 | return |
111 | 83 |
|
112 | | - for old_path in old_path_list: |
113 | | - match = re.search('LanguageTool-(\d+.*?)$', old_path) |
114 | | - if match: |
115 | | - current_version = Version(match.group(1)) |
116 | | - try: |
117 | | - version_test = current_version > version |
118 | | - except TypeError: |
119 | | - continue |
120 | | - if version_test: |
121 | | - print( |
122 | | - 'Local version: {!r}, Remote version: {!r}' |
123 | | - .format(str(current_version), str(version)) |
124 | | - ) |
125 | | - return |
126 | | - |
127 | 84 | with closing(TemporaryFile()) as t: |
128 | 85 | with closing(urlopen(url)) as u: |
129 | 86 | content_len = int(u.headers['Content-Length']) |
130 | 87 | sys.stdout.write( |
131 | 88 | 'Downloading {!r} ({:.1f} MiB)...\n' |
132 | | - .format(filename, content_len / 1048576.) |
| 89 | + .format(FILENAME, content_len / 1048576.) |
133 | 90 | ) |
134 | 91 | sys.stdout.flush() |
135 | 92 | chunk_len = content_len // 100 |
|
0 commit comments