fosslight-util 2.1.21__py3-none-any.whl → 2.1.23__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fosslight_util/_get_downloadable_url.py +89 -25
- fosslight_util/download.py +6 -3
- fosslight_util/help.py +6 -1
- {fosslight_util-2.1.21.dist-info → fosslight_util-2.1.23.dist-info}/METADATA +1 -1
- {fosslight_util-2.1.21.dist-info → fosslight_util-2.1.23.dist-info}/RECORD +9 -9
- {fosslight_util-2.1.21.dist-info → fosslight_util-2.1.23.dist-info}/LICENSE +0 -0
- {fosslight_util-2.1.21.dist-info → fosslight_util-2.1.23.dist-info}/WHEEL +0 -0
- {fosslight_util-2.1.21.dist-info → fosslight_util-2.1.23.dist-info}/entry_points.txt +0 -0
- {fosslight_util-2.1.21.dist-info → fosslight_util-2.1.23.dist-info}/top_level.txt +0 -0
|
@@ -13,7 +13,7 @@ import fosslight_util.constant as constant
|
|
|
13
13
|
logger = logging.getLogger(constant.LOGGER_NAME)
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
def extract_name_version_from_link(link):
|
|
16
|
+
def extract_name_version_from_link(link, checkout_version):
|
|
17
17
|
oss_name = ""
|
|
18
18
|
oss_version = ""
|
|
19
19
|
matched = False
|
|
@@ -53,8 +53,12 @@ def extract_name_version_from_link(link):
|
|
|
53
53
|
except Exception as ex:
|
|
54
54
|
logger.info(f"extract_name_version_from_link {key}:{ex}")
|
|
55
55
|
if oss_name and (not oss_version):
|
|
56
|
-
if
|
|
57
|
-
oss_version
|
|
56
|
+
if checkout_version:
|
|
57
|
+
oss_version = checkout_version
|
|
58
|
+
elif key in ["pypi", "maven", "npm", "npm2", "pub", "go"]:
|
|
59
|
+
oss_version = get_latest_package_version(link, key, origin_name)
|
|
60
|
+
if oss_version:
|
|
61
|
+
link = get_new_link_with_version(link, key, origin_name, oss_version)
|
|
58
62
|
logger.info(f'Try to download with the latest version:{link}')
|
|
59
63
|
matched = True
|
|
60
64
|
break
|
|
@@ -63,50 +67,56 @@ def extract_name_version_from_link(link):
|
|
|
63
67
|
return oss_name, oss_version, link, key
|
|
64
68
|
|
|
65
69
|
|
|
70
|
+
def get_new_link_with_version(link, pkg_type, oss_name, oss_version):
|
|
71
|
+
if pkg_type == "pypi":
|
|
72
|
+
link = f'https://pypi.org/project/{oss_name}/{oss_version}'
|
|
73
|
+
elif pkg_type == "maven":
|
|
74
|
+
oss_name = oss_name.replace(':', '/')
|
|
75
|
+
link = f'https://mvnrepository.com/artifact/{oss_name}/{oss_version}'
|
|
76
|
+
elif pkg_type == "npm" or pkg_type == "npm2":
|
|
77
|
+
link = f'https://www.npmjs.com/package/{oss_name}/v/{oss_version}'
|
|
78
|
+
elif pkg_type == "pub":
|
|
79
|
+
link = f'https://pub.dev/packages/{oss_name}/versions/{oss_version}'
|
|
80
|
+
elif pkg_type == "go":
|
|
81
|
+
link = f'https://pkg.go.dev/{oss_name}@{oss_version}'
|
|
82
|
+
elif pkg_type == "cargo":
|
|
83
|
+
link = f'https://crates.io/crates/{oss_name}/{oss_version}'
|
|
84
|
+
return link
|
|
85
|
+
|
|
86
|
+
|
|
66
87
|
def get_latest_package_version(link, pkg_type, oss_name):
|
|
67
88
|
find_version = ''
|
|
68
|
-
link_with_version = link
|
|
69
89
|
|
|
70
90
|
try:
|
|
71
91
|
if pkg_type in ['npm', 'npm2']:
|
|
72
92
|
npm_response = requests.get(f"https://registry.npmjs.org/{oss_name}")
|
|
73
93
|
if npm_response.status_code == 200:
|
|
74
94
|
find_version = npm_response.json().get("dist-tags", {}).get("latest")
|
|
75
|
-
if find_version:
|
|
76
|
-
link_with_version = f'https://www.npmjs.com/package/{oss_name}/v/{find_version}'
|
|
77
95
|
elif pkg_type == 'pypi':
|
|
78
96
|
find_version = str(latest(oss_name, at='pip', output_format='version', pre_ok=True))
|
|
79
|
-
link_with_version = f'https://pypi.org/project/{oss_name}/{find_version}'
|
|
80
97
|
elif pkg_type == 'maven':
|
|
81
98
|
maven_response = requests.get(f'https://api.deps.dev/v3alpha/systems/maven/packages/{oss_name}')
|
|
82
99
|
if maven_response.status_code == 200:
|
|
83
100
|
find_version = maven_response.json().get('versions')[-1].get('versionKey').get('version')
|
|
84
|
-
oss_name = oss_name.replace(':', '/')
|
|
85
|
-
if find_version:
|
|
86
|
-
link_with_version = f'https://mvnrepository.com/artifact/{oss_name}/{find_version}'
|
|
87
101
|
elif pkg_type == 'pub':
|
|
88
102
|
pub_response = requests.get(f'https://pub.dev/api/packages/{oss_name}')
|
|
89
103
|
if pub_response.status_code == 200:
|
|
90
104
|
find_version = pub_response.json().get('latest').get('version')
|
|
91
|
-
if find_version:
|
|
92
|
-
link_with_version = f'https://pub.dev/packages/{oss_name}/versions/{find_version}'
|
|
93
105
|
elif pkg_type == 'go':
|
|
94
106
|
go_response = requests.get(f'https://proxy.golang.org/{oss_name}/@latest')
|
|
95
107
|
if go_response.status_code == 200:
|
|
96
108
|
find_version = go_response.json().get('Version')
|
|
97
|
-
if find_version:
|
|
98
|
-
link_with_version = f'https://pkg.go.dev/{oss_name}@{find_version}'
|
|
99
109
|
except Exception as e:
|
|
100
110
|
logger.info(f'Fail to get latest package version({link}:{e})')
|
|
101
|
-
return find_version
|
|
111
|
+
return find_version
|
|
102
112
|
|
|
103
113
|
|
|
104
|
-
def get_downloadable_url(link):
|
|
114
|
+
def get_downloadable_url(link, checkout_version):
|
|
105
115
|
|
|
106
116
|
ret = False
|
|
107
117
|
result_link = link
|
|
108
118
|
|
|
109
|
-
oss_name, oss_version, new_link, pkg_type = extract_name_version_from_link(link)
|
|
119
|
+
oss_name, oss_version, new_link, pkg_type = extract_name_version_from_link(link, checkout_version)
|
|
110
120
|
new_link = new_link.replace('http://', '')
|
|
111
121
|
new_link = new_link.replace('https://', '')
|
|
112
122
|
|
|
@@ -180,6 +190,28 @@ def get_download_location_for_go(link):
|
|
|
180
190
|
return ret, new_link
|
|
181
191
|
|
|
182
192
|
|
|
193
|
+
def get_available_wheel_urls(name, version):
|
|
194
|
+
try:
|
|
195
|
+
api_url = f'https://pypi.org/pypi/{name}/{version}/json'
|
|
196
|
+
response = requests.get(api_url)
|
|
197
|
+
if response.status_code == 200:
|
|
198
|
+
data = response.json()
|
|
199
|
+
wheel_urls = []
|
|
200
|
+
|
|
201
|
+
for file_info in data.get('urls', []):
|
|
202
|
+
if file_info.get('packagetype') == 'bdist_wheel':
|
|
203
|
+
wheel_urls.append(file_info.get('url'))
|
|
204
|
+
|
|
205
|
+
return wheel_urls
|
|
206
|
+
else:
|
|
207
|
+
logger.warning(f'Cannot get PyPI API data for {name}({version})')
|
|
208
|
+
return []
|
|
209
|
+
|
|
210
|
+
except Exception as error:
|
|
211
|
+
logger.warning(f'Failed to get wheel URLs from PyPI API: {error}')
|
|
212
|
+
return []
|
|
213
|
+
|
|
214
|
+
|
|
183
215
|
def get_download_location_for_pypi(link):
|
|
184
216
|
# get the url for downloading source file: https://docs.pypi.org/api/ Predictable URLs
|
|
185
217
|
ret = False
|
|
@@ -192,24 +224,56 @@ def get_download_location_for_pypi(link):
|
|
|
192
224
|
oss_name = re.sub(r"[-_.]+", "-", oss_name)
|
|
193
225
|
oss_version = dn_loc_re[0][1]
|
|
194
226
|
|
|
227
|
+
# 1. Source distribution 시도
|
|
195
228
|
new_link = f'{host}/packages/source/{oss_name[0]}/{oss_name}/{oss_name}-{oss_version}.tar.gz'
|
|
196
229
|
try:
|
|
197
230
|
res = urlopen(new_link)
|
|
198
231
|
if res.getcode() == 200:
|
|
199
232
|
ret = True
|
|
200
|
-
|
|
201
|
-
logger.warning(f'Cannot find the valid link for pypi (url:{new_link}')
|
|
233
|
+
return ret, new_link
|
|
202
234
|
except Exception:
|
|
203
235
|
oss_name = re.sub(r"[-]+", "_", oss_name)
|
|
204
236
|
new_link = f'{host}/packages/source/{oss_name[0]}/{oss_name}/{oss_name}-{oss_version}.tar.gz'
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
237
|
+
try:
|
|
238
|
+
res = urlopen(new_link)
|
|
239
|
+
if res.getcode() == 200:
|
|
240
|
+
ret = True
|
|
241
|
+
return ret, new_link
|
|
242
|
+
except Exception:
|
|
243
|
+
pass
|
|
244
|
+
|
|
245
|
+
# 2. Source distribution이 없으면 wheel 파일들을 시도
|
|
246
|
+
wheel_urls = get_available_wheel_urls(oss_name, oss_version)
|
|
247
|
+
|
|
248
|
+
if wheel_urls:
|
|
249
|
+
# Pure Python wheel을 우선적으로 찾기
|
|
250
|
+
for wheel_url in wheel_urls:
|
|
251
|
+
if 'py3-none-any' in wheel_url or 'py2.py3-none-any' in wheel_url:
|
|
252
|
+
try:
|
|
253
|
+
res = urlopen(wheel_url)
|
|
254
|
+
if res.getcode() == 200:
|
|
255
|
+
ret = True
|
|
256
|
+
new_link = wheel_url
|
|
257
|
+
logger.info(f'Using wheel file : {wheel_url}')
|
|
258
|
+
return ret, new_link
|
|
259
|
+
except Exception:
|
|
260
|
+
continue
|
|
261
|
+
|
|
262
|
+
# Pure Python wheel이 없으면 첫 번째 wheel 시도
|
|
263
|
+
if wheel_urls:
|
|
264
|
+
try:
|
|
265
|
+
res = urlopen(wheel_urls[0])
|
|
266
|
+
if res.getcode() == 200:
|
|
267
|
+
ret = True
|
|
268
|
+
new_link = wheel_urls[0]
|
|
269
|
+
logger.info(f'Using wheel file : {wheel_urls[0]}')
|
|
270
|
+
return ret, new_link
|
|
271
|
+
except Exception:
|
|
272
|
+
pass
|
|
273
|
+
|
|
210
274
|
except Exception as error:
|
|
211
275
|
ret = False
|
|
212
|
-
logger.warning(f'Cannot find the link for pypi (url:{link}({
|
|
276
|
+
logger.warning(f'Cannot find the link for pypi (url:{link}({new_link})) e:{str(error)}')
|
|
213
277
|
|
|
214
278
|
return ret, new_link
|
|
215
279
|
|
fosslight_util/download.py
CHANGED
|
@@ -137,7 +137,8 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
|
|
|
137
137
|
if os.path.isfile(target_dir):
|
|
138
138
|
shutil.rmtree(target_dir)
|
|
139
139
|
|
|
140
|
-
success, downloaded_file, msg_wget, oss_name, oss_version = download_wget(link, target_dir,
|
|
140
|
+
success, downloaded_file, msg_wget, oss_name, oss_version = download_wget(link, target_dir,
|
|
141
|
+
compressed_only, checkout_to)
|
|
141
142
|
if success:
|
|
142
143
|
success = extract_compressed_file(downloaded_file, target_dir, True, compressed_only)
|
|
143
144
|
# Download from rubygems.org
|
|
@@ -310,7 +311,7 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="",
|
|
|
310
311
|
return success, msg, oss_name, refs_to_checkout
|
|
311
312
|
|
|
312
313
|
|
|
313
|
-
def download_wget(link, target_dir, compressed_only):
|
|
314
|
+
def download_wget(link, target_dir, compressed_only, checkout_to):
|
|
314
315
|
success = False
|
|
315
316
|
msg = ""
|
|
316
317
|
oss_name = ""
|
|
@@ -327,7 +328,7 @@ def download_wget(link, target_dir, compressed_only):
|
|
|
327
328
|
|
|
328
329
|
Path(target_dir).mkdir(parents=True, exist_ok=True)
|
|
329
330
|
|
|
330
|
-
ret, new_link, oss_name, oss_version, pkg_type = get_downloadable_url(link)
|
|
331
|
+
ret, new_link, oss_name, oss_version, pkg_type = get_downloadable_url(link, checkout_to)
|
|
331
332
|
if ret and new_link:
|
|
332
333
|
link = new_link
|
|
333
334
|
|
|
@@ -399,6 +400,8 @@ def extract_compressed_file(fname, extract_path, remove_after_extract=True, comp
|
|
|
399
400
|
unzip(fname, extract_path)
|
|
400
401
|
elif fname.endswith(".bz2"):
|
|
401
402
|
decompress_bz2(fname, extract_path)
|
|
403
|
+
elif fname.endswith(".whl"):
|
|
404
|
+
unzip(fname, extract_path)
|
|
402
405
|
else:
|
|
403
406
|
is_compressed_file = False
|
|
404
407
|
if compressed_only:
|
fosslight_util/help.py
CHANGED
|
@@ -34,7 +34,12 @@ _HELP_MESSAGE_DOWNLOAD = """
|
|
|
34
34
|
Optional:
|
|
35
35
|
-h\t\t Print help message
|
|
36
36
|
-t\t\t Output path name
|
|
37
|
-
-d\t\t Directory name to save the log file
|
|
37
|
+
-d\t\t Directory name to save the log file
|
|
38
|
+
-s\t\t Source link to download
|
|
39
|
+
-t\t\t Directory to download source code
|
|
40
|
+
-c\t\t Checkout to branch or tag/ or version
|
|
41
|
+
-z\t\t Unzip only compressed file
|
|
42
|
+
-o\t\t Generate summary output file with this option"""
|
|
38
43
|
|
|
39
44
|
|
|
40
45
|
class PrintHelpMsg():
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
fosslight_util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
fosslight_util/_get_downloadable_url.py,sha256=
|
|
2
|
+
fosslight_util/_get_downloadable_url.py,sha256=zCBSVNTEumVxeLyaW5l4HKYKt73NLbC2y7gZoAhuWYA,14618
|
|
3
3
|
fosslight_util/compare_yaml.py,sha256=eLqqCLgERxRHN5vsnpQVMXIEU862Lx66mD_y4uMgQE4,2916
|
|
4
4
|
fosslight_util/constant.py,sha256=zElnWOzXt020sYiFTiRQn8ZjZyZpL3aPmfAqfQLcxJk,2278
|
|
5
5
|
fosslight_util/correct.py,sha256=1WEAL-9_KhjFPLucPhv0PNN3K7avm0z8mU6sTuSyeHM,3864
|
|
6
6
|
fosslight_util/cover.py,sha256=qqqKzxqFwKimal764FaugRUBcHWdeKt8af6xeK0mH8E,2040
|
|
7
|
-
fosslight_util/download.py,sha256=
|
|
7
|
+
fosslight_util/download.py,sha256=F_cbweXKkr4pSRWRbvsuwK_pMjorneJBkPbTy2bEdJc,19069
|
|
8
8
|
fosslight_util/exclude.py,sha256=fDmBsZJ_F7O9Oh2T-07R03XNbElo1tFaf_z01KfSAqU,2399
|
|
9
|
-
fosslight_util/help.py,sha256=
|
|
9
|
+
fosslight_util/help.py,sha256=iyWmAaUQSHJtWv5mjFv0f3YoDVlDgEqdsDDEyImEUNc,2646
|
|
10
10
|
fosslight_util/oss_item.py,sha256=8W2HlwqGH3l1iPPdvycrRYKsBSBpqAkqYyYtBVPgMtY,6868
|
|
11
11
|
fosslight_util/output_format.py,sha256=BP23LspxawDZ_a99oWLVKWUQ-G7P5uoUpjEXhkRFKwc,8801
|
|
12
12
|
fosslight_util/parsing_yaml.py,sha256=2zx_N5lMkXT1dRmfJMpzlrru-y_2F_CkVbGlba6vQpU,5380
|
|
@@ -24,9 +24,9 @@ fosslight_util/write_yaml.py,sha256=QlEKoIPQsEaYERfbP53TeKgnllYzhLQWm5wYjnWtVjE,
|
|
|
24
24
|
fosslight_util/resources/frequentLicenselist.json,sha256=GUhzK6tu7ok10fekOnmVmUgIGRC-acGABZKTNKfDyYA,4776157
|
|
25
25
|
fosslight_util/resources/frequent_license_nick_list.json,sha256=ryU2C_6ZxHbz90_sUN9OvI9GXkCMLu7oGcmd9W79YYo,5005
|
|
26
26
|
fosslight_util/resources/licenses.json,sha256=mK55z-bhY7Mjpj2KsO1crKGGL-X3F6MBFQJ0zLlx010,240843
|
|
27
|
-
fosslight_util-2.1.
|
|
28
|
-
fosslight_util-2.1.
|
|
29
|
-
fosslight_util-2.1.
|
|
30
|
-
fosslight_util-2.1.
|
|
31
|
-
fosslight_util-2.1.
|
|
32
|
-
fosslight_util-2.1.
|
|
27
|
+
fosslight_util-2.1.23.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
28
|
+
fosslight_util-2.1.23.dist-info/METADATA,sha256=qcT5R4XpXKm7Zeclyj_1TosxMzzE2H0-FvNvOIGkV_Q,6156
|
|
29
|
+
fosslight_util-2.1.23.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
30
|
+
fosslight_util-2.1.23.dist-info/entry_points.txt,sha256=0yZggRWNwDaClDG8UmUA10UFG8cVX3Jiy5gG9nW7hJs,68
|
|
31
|
+
fosslight_util-2.1.23.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
|
|
32
|
+
fosslight_util-2.1.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|