fosslight-util 2.1.17__py3-none-any.whl → 2.1.19__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.
@@ -5,7 +5,6 @@
5
5
  import logging
6
6
  import re
7
7
  import requests
8
- from npm.bindings import npm_run
9
8
  from lastversion import latest
10
9
  from bs4 import BeautifulSoup
11
10
  from urllib.request import urlopen
@@ -47,6 +46,9 @@ def extract_name_version_from_link(link):
47
46
  origin_name = origin_name[:-1]
48
47
  oss_name = f"go:{origin_name}"
49
48
  oss_version = match.group(2)
49
+ elif key == "cargo":
50
+ oss_name = f"cargo:{origin_name}"
51
+ oss_version = match.group(2)
50
52
  except Exception as ex:
51
53
  logger.info(f"extract_name_version_from_link {key}:{ex}")
52
54
  if oss_name and (not oss_version):
@@ -63,10 +65,11 @@ def get_latest_package_version(link, pkg_type, oss_name):
63
65
 
64
66
  try:
65
67
  if pkg_type in ['npm', 'npm2']:
66
- stderr, stdout = npm_run('view', oss_name, 'version')
67
- if stdout:
68
- find_version = stdout.strip()
69
- link_with_version = f'https://www.npmjs.com/package/{oss_name}/v/{find_version}'
68
+ npm_response = requests.get(f"https://registry.npmjs.org/{oss_name}")
69
+ if npm_response.status_code == 200:
70
+ find_version = npm_response.json().get("dist-tags", {}).get("latest")
71
+ if find_version:
72
+ link_with_version = f'https://www.npmjs.com/package/{oss_name}/v/{find_version}'
70
73
  elif pkg_type == 'pypi':
71
74
  find_version = str(latest(oss_name, at='pip', output_format='version', pre_ok=True))
72
75
  link_with_version = f'https://pypi.org/project/{oss_name}/{find_version}'
@@ -75,17 +78,20 @@ def get_latest_package_version(link, pkg_type, oss_name):
75
78
  if maven_response.status_code == 200:
76
79
  find_version = maven_response.json().get('versions')[-1].get('versionKey').get('version')
77
80
  oss_name = oss_name.replace(':', '/')
78
- link_with_version = f'https://mvnrepository.com/artifact/{oss_name}/{find_version}'
81
+ if find_version:
82
+ link_with_version = f'https://mvnrepository.com/artifact/{oss_name}/{find_version}'
79
83
  elif pkg_type == 'pub':
80
84
  pub_response = requests.get(f'https://pub.dev/api/packages/{oss_name}')
81
85
  if pub_response.status_code == 200:
82
86
  find_version = pub_response.json().get('latest').get('version')
83
- link_with_version = f'https://pub.dev/packages/{oss_name}/versions/{find_version}'
87
+ if find_version:
88
+ link_with_version = f'https://pub.dev/packages/{oss_name}/versions/{find_version}'
84
89
  elif pkg_type == 'go':
85
90
  go_response = requests.get(f'https://proxy.golang.org/{oss_name}/@latest')
86
91
  if go_response.status_code == 200:
87
92
  find_version = go_response.json().get('Version')
88
- link_with_version = f'https://pkg.go.dev/{oss_name}@{find_version}'
93
+ if find_version:
94
+ link_with_version = f'https://pkg.go.dev/{oss_name}@{find_version}'
89
95
  except Exception as e:
90
96
  logger.info(f'Fail to get latest package version({link}:{e})')
91
97
  return find_version, link_with_version
@@ -110,8 +116,34 @@ def get_downloadable_url(link):
110
116
  ret, result_link = get_download_location_for_pub(new_link)
111
117
  elif pkg_type == "go":
112
118
  ret, result_link = get_download_location_for_go(new_link)
119
+ elif pkg_type == "cargo":
120
+ ret, result_link = get_download_location_for_cargo(new_link)
121
+ return ret, result_link, oss_name, oss_version, pkg_type
122
+
123
+
124
+ def get_download_location_for_cargo(link):
125
+ # get the url for downloading source file: https://crates.io/api/v1/crates/<name>/<version>/download
126
+ ret = False
127
+ new_link = ''
128
+ host = 'https://crates.io/api/v1/crates'
129
+
130
+ try:
131
+ dn_loc_re = re.findall(r'crates.io\/crates\/([^\/]+)\/?([^\/]*)', link)
132
+ if dn_loc_re:
133
+ oss_name = dn_loc_re[0][0]
134
+ oss_version = dn_loc_re[0][1]
113
135
 
114
- return ret, result_link, oss_name, oss_version
136
+ new_link = f'{host}/{oss_name}/{oss_version}/download'
137
+ res = urlopen(new_link)
138
+ if res.getcode() == 200:
139
+ ret = True
140
+ else:
141
+ logger.warning(f'Cannot find the valid link for cargo (url:{new_link}')
142
+ except Exception as error:
143
+ ret = False
144
+ logger.warning(f'Cannot find the link for cargo (url:{link}({(new_link)})): {error}')
145
+
146
+ return ret, new_link
115
147
 
116
148
 
117
149
  def get_download_location_for_go(link):
@@ -35,6 +35,7 @@ SHEET_NAME_FOR_SCANNER = {
35
35
  # pub: https://pub.dev/packages/(package)/versions/(version)
36
36
  # Cocoapods : https://cocoapods.org/(package)
37
37
  # go : https://pkg.go.dev/(package_name_with_slash)@(version)
38
+ # cargo : https://crates.io/crates/(crate_name)/(version)
38
39
  PKG_PATTERN = {
39
40
  "pypi": r'https?:\/\/pypi\.org\/project\/([^\/]+)[\/]?([^\/]*)',
40
41
  "pypi2": r'https?:\/\/files\.pythonhosted\.org\/packages\/source\/[\w]\/([^\/]+)\/[\S]+-([^\-]+)\.tar\.gz',
@@ -43,5 +44,6 @@ PKG_PATTERN = {
43
44
  "npm2": r'https?:\/\/www\.npmjs\.com\/package\/(\@[^\/]+\/[^\/]+)(?:\/v\/)?([^\/]*)',
44
45
  "pub": r'https?:\/\/pub\.dev\/packages\/([^\/]+)(?:\/versions\/)?([^\/]*)',
45
46
  "cocoapods": r'https?:\/\/cocoapods\.org\/pods\/([^\/]+)',
46
- "go": r'https?:\/\/pkg.go.dev\/([^\@]+)\@?v?([^\/]*)'
47
+ "go": r'https?:\/\/pkg.go.dev\/([^\@]+)\@?v?([^\/]*)',
48
+ "cargo": r'https?:\/\/crates\.io\/crates\/([^\/]+)\/?([^\/]*)',
47
49
  }
@@ -314,7 +314,7 @@ def download_wget(link, target_dir, compressed_only):
314
314
 
315
315
  Path(target_dir).mkdir(parents=True, exist_ok=True)
316
316
 
317
- ret, new_link, oss_name, oss_version = get_downloadable_url(link)
317
+ ret, new_link, oss_name, oss_version, pkg_type = get_downloadable_url(link)
318
318
  if ret and new_link:
319
319
  link = new_link
320
320
 
@@ -323,6 +323,9 @@ def download_wget(link, target_dir, compressed_only):
323
323
  if link.endswith(ext):
324
324
  success = True
325
325
  break
326
+ if not success:
327
+ if pkg_type == 'cargo':
328
+ success = True
326
329
  else:
327
330
  success = True
328
331
 
@@ -330,7 +333,11 @@ def download_wget(link, target_dir, compressed_only):
330
333
  raise Exception('Not supported compression type (link:{0})'.format(link))
331
334
 
332
335
  logger.info(f"wget: {link}")
333
- downloaded_file = wget.download(link, target_dir)
336
+ if pkg_type == 'cargo':
337
+ outfile = os.path.join(target_dir, f'{oss_name}.tar.gz')
338
+ downloaded_file = wget.download(link, out=outfile)
339
+ else:
340
+ downloaded_file = wget.download(link, target_dir)
334
341
  if platform.system() != "Windows":
335
342
  signal.alarm(0)
336
343
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-util
3
- Version: 2.1.17
3
+ Version: 2.1.19
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Author: LG Electronics
@@ -27,7 +27,6 @@ Requires-Dist: python3-wget
27
27
  Requires-Dist: beautifulsoup4
28
28
  Requires-Dist: jsonmerge
29
29
  Requires-Dist: setuptools>=65.5.1
30
- Requires-Dist: npm
31
30
  Requires-Dist: requests
32
31
  Requires-Dist: GitPython
33
32
  Requires-Dist: numpy; python_version < "3.8"
@@ -1,10 +1,10 @@
1
1
  fosslight_util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- fosslight_util/_get_downloadable_url.py,sha256=5QBEM1Ac_T3vhBUPJYSMkaGrI1A_f3VWDptxfVwMiy8,10976
2
+ fosslight_util/_get_downloadable_url.py,sha256=TbzzW-MJky-A610mgw5bpf6xmELyQAwXo9jfubi05d8,12271
3
3
  fosslight_util/compare_yaml.py,sha256=eLqqCLgERxRHN5vsnpQVMXIEU862Lx66mD_y4uMgQE4,2916
4
- fosslight_util/constant.py,sha256=Ig3ACm9_QirE4389Wt-IfxOqRkVOUjqGnX1B05z2Byo,2151
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=b55ZDso1nnAwIQwMyAYyxnJcvTYQx8eGVcIg9D1CpCc,17347
7
+ fosslight_util/download.py,sha256=V3EBgXt-xHarJZFrskXHaX4Ij81ZPjj6hzvtmpKu7xE,17642
8
8
  fosslight_util/exclude.py,sha256=fDmBsZJ_F7O9Oh2T-07R03XNbElo1tFaf_z01KfSAqU,2399
9
9
  fosslight_util/help.py,sha256=Bmyz-eFP0X0qUfgFPrWiuyUPE0TLQfWjgfHTzJBIInc,2377
10
10
  fosslight_util/oss_item.py,sha256=8W2HlwqGH3l1iPPdvycrRYKsBSBpqAkqYyYtBVPgMtY,6868
@@ -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.17.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
28
- fosslight_util-2.1.17.dist-info/METADATA,sha256=dG34Ulv95GV7bhARLITbYUWmEe52VqazekVCRfQ0vqs,6500
29
- fosslight_util-2.1.17.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
30
- fosslight_util-2.1.17.dist-info/entry_points.txt,sha256=bzXX5i7HZ13V8BLKvtu_9KO3ZjtRypH-XszOXT6I3bU,69
31
- fosslight_util-2.1.17.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
32
- fosslight_util-2.1.17.dist-info/RECORD,,
27
+ fosslight_util-2.1.19.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
28
+ fosslight_util-2.1.19.dist-info/METADATA,sha256=rqYqFM4FZEKmhmATRltYAJreokGayqWFTX2tENCgje4,6481
29
+ fosslight_util-2.1.19.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
30
+ fosslight_util-2.1.19.dist-info/entry_points.txt,sha256=bzXX5i7HZ13V8BLKvtu_9KO3ZjtRypH-XszOXT6I3bU,69
31
+ fosslight_util-2.1.19.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
32
+ fosslight_util-2.1.19.dist-info/RECORD,,