fosslight-util 1.4.35__py3-none-any.whl → 1.4.36__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 +103 -23
- fosslight_util/download.py +34 -8
- {fosslight_util-1.4.35.dist-info → fosslight_util-1.4.36.dist-info}/METADATA +3 -2
- {fosslight_util-1.4.35.dist-info → fosslight_util-1.4.36.dist-info}/RECORD +8 -8
- {fosslight_util-1.4.35.dist-info → fosslight_util-1.4.36.dist-info}/LICENSE +0 -0
- {fosslight_util-1.4.35.dist-info → fosslight_util-1.4.36.dist-info}/WHEEL +0 -0
- {fosslight_util-1.4.35.dist-info → fosslight_util-1.4.36.dist-info}/entry_points.txt +0 -0
- {fosslight_util-1.4.35.dist-info → fosslight_util-1.4.36.dist-info}/top_level.txt +0 -0
|
@@ -4,32 +4,119 @@
|
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
import logging
|
|
6
6
|
import re
|
|
7
|
+
import requests
|
|
8
|
+
from npm.bindings import npm_run
|
|
9
|
+
from lastversion import latest
|
|
7
10
|
from bs4 import BeautifulSoup
|
|
8
11
|
from urllib.request import urlopen
|
|
9
12
|
import fosslight_util.constant as constant
|
|
10
|
-
from npm.bindings import npm_run
|
|
11
13
|
|
|
12
14
|
logger = logging.getLogger(constant.LOGGER_NAME)
|
|
13
15
|
|
|
14
16
|
|
|
17
|
+
def extract_name_version_from_link(link):
|
|
18
|
+
# Github : https://github.com/(owner)/(repo)
|
|
19
|
+
# npm : https://www.npmjs.com/package/(package)/v/(version)
|
|
20
|
+
# npm2 : https://www.npmjs.com/package/@(group)/(package)/v/(version)
|
|
21
|
+
# pypi : https://pypi.org/project/(oss_name)/(version)
|
|
22
|
+
# pypi2 : https://files.pythonhosted.org/packages/source/(alphabet)/(oss_name)/(oss_name)-(version).tar.gz
|
|
23
|
+
# Maven: https://mvnrepository.com/artifact/(group)/(artifact)/(version)
|
|
24
|
+
# pub: https://pub.dev/packages/(package)/versions/(version)
|
|
25
|
+
# Cocoapods: https://cocoapods.org/(package)
|
|
26
|
+
pkg_pattern = {
|
|
27
|
+
"pypi": r'https?:\/\/pypi\.org\/project\/([^\/]+)[\/]?([^\/]*)',
|
|
28
|
+
"pypi2": r'https?:\/\/files\.pythonhosted\.org\/packages\/source\/[\w]\/([^\/]+)\/[\S]+-([^\-]+)\.tar\.gz',
|
|
29
|
+
"maven": r'https?:\/\/mvnrepository\.com\/artifact\/([^\/]+)\/([^\/]+)\/?([^\/]*)',
|
|
30
|
+
"npm": r'https?:\/\/www\.npmjs\.com\/package\/([^\/\@]+)(?:\/v\/)?([^\/]*)',
|
|
31
|
+
"npm2": r'https?:\/\/www\.npmjs\.com\/package\/(\@[^\/]+\/[^\/]+)(?:\/v\/)?([^\/]*)',
|
|
32
|
+
"pub": r'https?:\/\/pub\.dev\/packages\/([^\/]+)(?:\/versions\/)?([^\/]*)',
|
|
33
|
+
"pods": r'https?:\/\/cocoapods\.org\/pods\/([^\/]+)'
|
|
34
|
+
}
|
|
35
|
+
oss_name = ""
|
|
36
|
+
oss_version = ""
|
|
37
|
+
if link.startswith("www."):
|
|
38
|
+
link = link.replace("www.", "https://www.", 1)
|
|
39
|
+
for key, value in pkg_pattern.items():
|
|
40
|
+
p = re.compile(value)
|
|
41
|
+
match = p.match(link)
|
|
42
|
+
if match:
|
|
43
|
+
try:
|
|
44
|
+
origin_name = match.group(1)
|
|
45
|
+
if (key == "pypi") or (key == "pypi2"):
|
|
46
|
+
oss_name = f"pypi:{origin_name}"
|
|
47
|
+
oss_name = re.sub(r"[-_.]+", "-", oss_name).lower()
|
|
48
|
+
oss_version = match.group(2)
|
|
49
|
+
elif key == "maven":
|
|
50
|
+
artifact = match.group(2)
|
|
51
|
+
oss_name = f"{origin_name}:{artifact}"
|
|
52
|
+
origin_name = oss_name
|
|
53
|
+
oss_version = match.group(3)
|
|
54
|
+
elif key == "npm" or key == "npm2":
|
|
55
|
+
oss_name = f"npm:{origin_name}"
|
|
56
|
+
oss_version = match.group(2)
|
|
57
|
+
elif key == "pub":
|
|
58
|
+
oss_name = f"pub:{origin_name}"
|
|
59
|
+
oss_version = match.group(2)
|
|
60
|
+
elif key == "pods":
|
|
61
|
+
oss_name = f"cocoapods:{origin_name}"
|
|
62
|
+
except Exception as ex:
|
|
63
|
+
logger.info(f"extract_name_version_from_link {key}:{ex}")
|
|
64
|
+
if oss_name and (not oss_version):
|
|
65
|
+
if key in ["pypi", "maven", "npm", "npm2", "pub"]:
|
|
66
|
+
oss_version, link = get_latest_package_version(link, key, origin_name)
|
|
67
|
+
logger.debug(f'Try to download with the latest version:{link}')
|
|
68
|
+
break
|
|
69
|
+
return oss_name, oss_version, link, key
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def get_latest_package_version(link, pkg_type, oss_name):
|
|
73
|
+
find_version = ''
|
|
74
|
+
link_with_version = link
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
if pkg_type in ['npm', 'npm2']:
|
|
78
|
+
stderr, stdout = npm_run('view', oss_name, 'version')
|
|
79
|
+
if stdout:
|
|
80
|
+
find_version = stdout.strip()
|
|
81
|
+
link_with_version = f'https://www.npmjs.com/package/{oss_name}/v/{find_version}'
|
|
82
|
+
elif pkg_type == 'pypi':
|
|
83
|
+
find_version = str(latest(oss_name, at='pip', output_format='version', pre_ok=True))
|
|
84
|
+
link_with_version = f'https://pypi.org/project/{oss_name}/{find_version}'
|
|
85
|
+
elif pkg_type == 'maven':
|
|
86
|
+
maven_response = requests.get(f'https://api.deps.dev/v3alpha/systems/maven/packages/{oss_name}')
|
|
87
|
+
if maven_response.status_code == 200:
|
|
88
|
+
find_version = maven_response.json().get('versions')[-1].get('versionKey').get('version')
|
|
89
|
+
oss_name = oss_name.replace(':', '/')
|
|
90
|
+
link_with_version = f'https://mvnrepository.com/artifact/{oss_name}/{find_version}'
|
|
91
|
+
elif pkg_type == 'pub':
|
|
92
|
+
pub_response = requests.get(f'https://pub.dev/api/packages/{oss_name}')
|
|
93
|
+
if pub_response.status_code == 200:
|
|
94
|
+
find_version = pub_response.json().get('latest').get('version')
|
|
95
|
+
link_with_version = f'https://pub.dev/packages/{oss_name}/versions/{find_version}'
|
|
96
|
+
except Exception as e:
|
|
97
|
+
logger.debug(f'Fail to get latest package version({link}:{e})')
|
|
98
|
+
return find_version, link_with_version
|
|
99
|
+
|
|
100
|
+
|
|
15
101
|
def get_downloadable_url(link):
|
|
16
102
|
|
|
17
103
|
ret = False
|
|
18
|
-
|
|
104
|
+
result_link = link
|
|
19
105
|
|
|
20
|
-
|
|
21
|
-
|
|
106
|
+
oss_name, oss_version, new_link, pkg_type = extract_name_version_from_link(link)
|
|
107
|
+
new_link = new_link.replace('http://', '')
|
|
108
|
+
new_link = new_link.replace('https://', '')
|
|
22
109
|
|
|
23
|
-
if
|
|
24
|
-
ret,
|
|
25
|
-
elif
|
|
26
|
-
ret,
|
|
27
|
-
elif
|
|
28
|
-
ret,
|
|
29
|
-
elif
|
|
30
|
-
ret,
|
|
110
|
+
if pkg_type == "pypi":
|
|
111
|
+
ret, result_link = get_download_location_for_pypi(new_link)
|
|
112
|
+
elif pkg_type == "maven" or new_link.startswith('repo1.maven.org/'):
|
|
113
|
+
ret, result_link = get_download_location_for_maven(new_link)
|
|
114
|
+
elif (pkg_type in ["npm", "npm2"]) or new_link.startswith('registry.npmjs.org/'):
|
|
115
|
+
ret, result_link = get_download_location_for_npm(new_link)
|
|
116
|
+
elif pkg_type == "pub":
|
|
117
|
+
ret, result_link = get_download_location_for_pub(new_link)
|
|
31
118
|
|
|
32
|
-
return ret,
|
|
119
|
+
return ret, result_link, oss_name, oss_version
|
|
33
120
|
|
|
34
121
|
|
|
35
122
|
def get_download_location_for_pypi(link):
|
|
@@ -134,16 +221,9 @@ def get_download_location_for_npm(link):
|
|
|
134
221
|
oss_name_npm = dn_loc_split[idx]
|
|
135
222
|
tar_name = oss_name_npm
|
|
136
223
|
oss_version = dn_loc_split[idx+2]
|
|
137
|
-
except Exception:
|
|
138
|
-
pass
|
|
139
224
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
stderr, stdout = npm_run('view', oss_name_npm, 'version')
|
|
143
|
-
if stdout:
|
|
144
|
-
oss_version = stdout.strip()
|
|
145
|
-
tar_name = f"{tar_name}-{oss_version}"
|
|
146
|
-
new_link = 'https://registry.npmjs.org/' + oss_name_npm + '/-/' + tar_name + '.tgz'
|
|
225
|
+
tar_name = f'{tar_name}-{oss_version}'
|
|
226
|
+
new_link = f'https://registry.npmjs.org/{oss_name_npm}/-/{tar_name}.tgz'
|
|
147
227
|
ret = True
|
|
148
228
|
except Exception as error:
|
|
149
229
|
ret = False
|
|
@@ -159,7 +239,7 @@ def get_download_location_for_pub(link):
|
|
|
159
239
|
# download url format : https://pub.dev/packages/(oss_name)/versions/(oss_version).tar.gz
|
|
160
240
|
try:
|
|
161
241
|
if link.startswith('pub.dev/packages'):
|
|
162
|
-
new_link = 'https://{link}.tar.gz'
|
|
242
|
+
new_link = f'https://{link}.tar.gz'
|
|
163
243
|
ret = True
|
|
164
244
|
|
|
165
245
|
except Exception as error:
|
fosslight_util/download.py
CHANGED
|
@@ -24,6 +24,7 @@ import time
|
|
|
24
24
|
import threading
|
|
25
25
|
import platform
|
|
26
26
|
import subprocess
|
|
27
|
+
import re
|
|
27
28
|
|
|
28
29
|
logger = logging.getLogger(constant.LOGGER_NAME)
|
|
29
30
|
compression_extension = {".tar.bz2", ".tar.gz", ".tar.xz", ".tgz", ".tar", ".zip", ".jar", ".bz2"}
|
|
@@ -115,6 +116,8 @@ def cli_download_and_extract(link, target_dir, log_dir, checkout_to="", compress
|
|
|
115
116
|
|
|
116
117
|
success = True
|
|
117
118
|
msg = ""
|
|
119
|
+
oss_name = ""
|
|
120
|
+
oss_version = ""
|
|
118
121
|
log_file_name = "fosslight_download_" + \
|
|
119
122
|
datetime.now().strftime('%Y%m%d_%H-%M-%S')+".txt"
|
|
120
123
|
logger, log_item = init_log(os.path.join(log_dir, log_file_name))
|
|
@@ -135,22 +138,29 @@ def cli_download_and_extract(link, target_dir, log_dir, checkout_to="", compress
|
|
|
135
138
|
is_rubygems = src_info.get("rubygems", False)
|
|
136
139
|
|
|
137
140
|
# General download (git clone, wget)
|
|
138
|
-
|
|
141
|
+
success_git, msg, oss_name = download_git_clone(link, target_dir, checkout_to, tag, branch)
|
|
142
|
+
if (not is_rubygems) and (not success_git):
|
|
139
143
|
if os.path.isfile(target_dir):
|
|
140
144
|
shutil.rmtree(target_dir)
|
|
141
145
|
|
|
142
|
-
success, downloaded_file = download_wget(link, target_dir, compressed_only)
|
|
146
|
+
success, downloaded_file, msg_wget, oss_name, oss_version = download_wget(link, target_dir, compressed_only)
|
|
143
147
|
if success:
|
|
144
148
|
success = extract_compressed_file(downloaded_file, target_dir, True)
|
|
145
149
|
# Download from rubygems.org
|
|
146
150
|
elif is_rubygems and shutil.which("gem"):
|
|
147
151
|
success = gem_download(link, target_dir, checkout_to)
|
|
152
|
+
if msg:
|
|
153
|
+
msg = f'git fail: {msg}'
|
|
154
|
+
if msg_wget:
|
|
155
|
+
msg = f'{msg}, wget fail: {msg_wget}'
|
|
156
|
+
else:
|
|
157
|
+
msg = f'{msg}, wget success'
|
|
148
158
|
except Exception as error:
|
|
149
159
|
success = False
|
|
150
160
|
msg = str(error)
|
|
151
161
|
|
|
152
|
-
logger.info(f"\n* FOSSLight Downloader - Result: {success}
|
|
153
|
-
return success, msg
|
|
162
|
+
logger.info(f"\n* FOSSLight Downloader - Result: {success} ({msg})")
|
|
163
|
+
return success, msg, oss_name, oss_version
|
|
154
164
|
|
|
155
165
|
|
|
156
166
|
def get_ref_to_checkout(checkout_to, ref_list):
|
|
@@ -184,8 +194,19 @@ def decide_checkout(checkout_to="", tag="", branch=""):
|
|
|
184
194
|
return ref_to_checkout
|
|
185
195
|
|
|
186
196
|
|
|
197
|
+
def get_github_ossname(link):
|
|
198
|
+
oss_name = ""
|
|
199
|
+
p = re.compile(r'https?:\/\/github.com\/([^\/]+)\/([^\/\.]+)(\.git)?')
|
|
200
|
+
match = p.match(link)
|
|
201
|
+
if match:
|
|
202
|
+
oss_name = f"{match.group(1)}-{match.group(2)}"
|
|
203
|
+
return oss_name
|
|
204
|
+
|
|
205
|
+
|
|
187
206
|
def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""):
|
|
188
207
|
ref_to_checkout = decide_checkout(checkout_to, tag, branch)
|
|
208
|
+
msg = ""
|
|
209
|
+
oss_name = get_github_ossname(git_url)
|
|
189
210
|
|
|
190
211
|
if platform.system() != "Windows":
|
|
191
212
|
signal.signal(signal.SIGALRM, alarm_handler)
|
|
@@ -204,7 +225,8 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""):
|
|
|
204
225
|
del alarm
|
|
205
226
|
except Exception as error:
|
|
206
227
|
logger.warning(f"git clone - failed: {error}")
|
|
207
|
-
|
|
228
|
+
msg = str(error)
|
|
229
|
+
return False, msg, oss_name
|
|
208
230
|
try:
|
|
209
231
|
if ref_to_checkout != "":
|
|
210
232
|
ref_list = [x for x in repo.references]
|
|
@@ -213,11 +235,14 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""):
|
|
|
213
235
|
repo.checkout(ref_to_checkout)
|
|
214
236
|
except Exception as error:
|
|
215
237
|
logger.warning(f"git checkout to {ref_to_checkout} - failed: {error}")
|
|
216
|
-
return True
|
|
238
|
+
return True, msg, oss_name
|
|
217
239
|
|
|
218
240
|
|
|
219
241
|
def download_wget(link, target_dir, compressed_only):
|
|
220
242
|
success = False
|
|
243
|
+
msg = ""
|
|
244
|
+
oss_name = ""
|
|
245
|
+
oss_version = ""
|
|
221
246
|
downloaded_file = ""
|
|
222
247
|
if platform.system() != "Windows":
|
|
223
248
|
signal.signal(signal.SIGALRM, alarm_handler)
|
|
@@ -228,7 +253,7 @@ def download_wget(link, target_dir, compressed_only):
|
|
|
228
253
|
try:
|
|
229
254
|
Path(target_dir).mkdir(parents=True, exist_ok=True)
|
|
230
255
|
|
|
231
|
-
ret, new_link = get_downloadable_url(link)
|
|
256
|
+
ret, new_link, oss_name, oss_version = get_downloadable_url(link)
|
|
232
257
|
if ret and new_link:
|
|
233
258
|
link = new_link
|
|
234
259
|
|
|
@@ -255,9 +280,10 @@ def download_wget(link, target_dir, compressed_only):
|
|
|
255
280
|
logger.debug(f"wget - downloaded: {downloaded_file}")
|
|
256
281
|
except Exception as error:
|
|
257
282
|
success = False
|
|
283
|
+
msg = str(error)
|
|
258
284
|
logger.warning(f"wget - failed: {error}")
|
|
259
285
|
|
|
260
|
-
return success, downloaded_file
|
|
286
|
+
return success, downloaded_file, msg, oss_name, oss_version
|
|
261
287
|
|
|
262
288
|
|
|
263
289
|
def extract_compressed_dir(src_dir, target_dir, remove_after_extract=True):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fosslight-util
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.36
|
|
4
4
|
Summary: FOSSLight Util
|
|
5
5
|
Home-page: https://github.com/fosslight/fosslight_util
|
|
6
6
|
Author: LG Electronics
|
|
@@ -28,8 +28,9 @@ Requires-Dist: python3-wget
|
|
|
28
28
|
Requires-Dist: beautifulsoup4
|
|
29
29
|
Requires-Dist: jsonmerge
|
|
30
30
|
Requires-Dist: spdx-tools ==0.7.0rc0
|
|
31
|
-
Requires-Dist: npm
|
|
32
31
|
Requires-Dist: setuptools >=65.5.1
|
|
32
|
+
Requires-Dist: npm
|
|
33
|
+
Requires-Dist: requests
|
|
33
34
|
Requires-Dist: numpy ; python_version < "3.8"
|
|
34
35
|
Requires-Dist: numpy >=1.22.2 ; python_version >= "3.8"
|
|
35
36
|
Requires-Dist: pygit2 ==1.6.1 ; python_version<'3.7'
|
|
@@ -1,10 +1,10 @@
|
|
|
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=Fb_-7S7vTg4HIsdQ_W77WbO1IYTFqGaf0lRRSunbWFI,10167
|
|
3
3
|
fosslight_util/compare_yaml.py,sha256=0bapoyS0yrzkiK70K57E8-3wZ_D6mZAJ-24Eq9TYBlk,2632
|
|
4
4
|
fosslight_util/constant.py,sha256=mDrH3Ahldhs9xT63iC8BmeRLHjN6fewI1H-pxnGvcD8,595
|
|
5
5
|
fosslight_util/convert_excel_to_yaml.py,sha256=7ZsAMMQJIEXrmcl_28nSHvFpGMi1ZiRZYpEfI5O8vP8,2298
|
|
6
6
|
fosslight_util/correct.py,sha256=RQ70zaQ_xuo9Mo0zIcb6pRQwt96bsimQJWkYldE2vbg,5224
|
|
7
|
-
fosslight_util/download.py,sha256=
|
|
7
|
+
fosslight_util/download.py,sha256=UVBQ5dtu9BCulUG20A0FBy98AlTmrjRau1Qmb4Ayd5U,13394
|
|
8
8
|
fosslight_util/help.py,sha256=3ej8HhpszfFLRxR99Ob55MwHypjIHce1-YSp5_ENq-A,2113
|
|
9
9
|
fosslight_util/oss_item.py,sha256=Gjw-aI4gZGYrCbAkCL35lXlgA2w2F2plgOUmenQ1Cig,5238
|
|
10
10
|
fosslight_util/output_format.py,sha256=kmlruqjTjrkENsg0sF4B-wAfEUlld_Uc--cGGm5NPs0,3214
|
|
@@ -22,9 +22,9 @@ fosslight_util/write_yaml.py,sha256=ppBBErAXbXw8jtJ9j7BDeQHHzDlsTRt62XR0GgTcr70,
|
|
|
22
22
|
fosslight_util/resources/frequentLicenselist.json,sha256=GUhzK6tu7ok10fekOnmVmUgIGRC-acGABZKTNKfDyYA,4776157
|
|
23
23
|
fosslight_util/resources/frequent_license_nick_list.json,sha256=ryU2C_6ZxHbz90_sUN9OvI9GXkCMLu7oGcmd9W79YYo,5005
|
|
24
24
|
fosslight_util/resources/licenses.json,sha256=mK55z-bhY7Mjpj2KsO1crKGGL-X3F6MBFQJ0zLlx010,240843
|
|
25
|
-
fosslight_util-1.4.
|
|
26
|
-
fosslight_util-1.4.
|
|
27
|
-
fosslight_util-1.4.
|
|
28
|
-
fosslight_util-1.4.
|
|
29
|
-
fosslight_util-1.4.
|
|
30
|
-
fosslight_util-1.4.
|
|
25
|
+
fosslight_util-1.4.36.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
26
|
+
fosslight_util-1.4.36.dist-info/METADATA,sha256=POQH9BPStS1HuuZUnuj3AND4EitzjRIgGtJj7ONP7ls,6189
|
|
27
|
+
fosslight_util-1.4.36.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
28
|
+
fosslight_util-1.4.36.dist-info/entry_points.txt,sha256=bzXX5i7HZ13V8BLKvtu_9KO3ZjtRypH-XszOXT6I3bU,69
|
|
29
|
+
fosslight_util-1.4.36.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
|
|
30
|
+
fosslight_util-1.4.36.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|