fosslight-util 2.1.14__py3-none-any.whl → 2.1.18__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.
@@ -42,12 +42,20 @@ def extract_name_version_from_link(link):
42
42
  oss_version = match.group(2)
43
43
  elif key == "cocoapods":
44
44
  oss_name = f"cocoapods:{origin_name}"
45
+ elif key == "go":
46
+ if origin_name.endswith('/'):
47
+ origin_name = origin_name[:-1]
48
+ oss_name = f"go:{origin_name}"
49
+ oss_version = match.group(2)
50
+ elif key == "cargo":
51
+ oss_name = f"cargo:{origin_name}"
52
+ oss_version = match.group(2)
45
53
  except Exception as ex:
46
54
  logger.info(f"extract_name_version_from_link {key}:{ex}")
47
55
  if oss_name and (not oss_version):
48
- if key in ["pypi", "maven", "npm", "npm2", "pub"]:
56
+ if key in ["pypi", "maven", "npm", "npm2", "pub", "go"]:
49
57
  oss_version, link = get_latest_package_version(link, key, origin_name)
50
- logger.debug(f'Try to download with the latest version:{link}')
58
+ logger.info(f'Try to download with the latest version:{link}')
51
59
  break
52
60
  return oss_name, oss_version, link, key
53
61
 
@@ -76,8 +84,13 @@ def get_latest_package_version(link, pkg_type, oss_name):
76
84
  if pub_response.status_code == 200:
77
85
  find_version = pub_response.json().get('latest').get('version')
78
86
  link_with_version = f'https://pub.dev/packages/{oss_name}/versions/{find_version}'
87
+ elif pkg_type == 'go':
88
+ go_response = requests.get(f'https://proxy.golang.org/{oss_name}/@latest')
89
+ if go_response.status_code == 200:
90
+ find_version = go_response.json().get('Version')
91
+ link_with_version = f'https://pkg.go.dev/{oss_name}@{find_version}'
79
92
  except Exception as e:
80
- logger.debug(f'Fail to get latest package version({link}:{e})')
93
+ logger.info(f'Fail to get latest package version({link}:{e})')
81
94
  return find_version, link_with_version
82
95
 
83
96
 
@@ -98,8 +111,66 @@ def get_downloadable_url(link):
98
111
  ret, result_link = get_download_location_for_npm(new_link)
99
112
  elif pkg_type == "pub":
100
113
  ret, result_link = get_download_location_for_pub(new_link)
114
+ elif pkg_type == "go":
115
+ ret, result_link = get_download_location_for_go(new_link)
116
+ elif pkg_type == "cargo":
117
+ ret, result_link = get_download_location_for_cargo(new_link)
118
+ return ret, result_link, oss_name, oss_version, pkg_type
119
+
120
+
121
+ def get_download_location_for_cargo(link):
122
+ # get the url for downloading source file: https://crates.io/api/v1/crates/<name>/<version>/download
123
+ ret = False
124
+ new_link = ''
125
+ host = 'https://crates.io/api/v1/crates'
126
+
127
+ try:
128
+ dn_loc_re = re.findall(r'crates.io\/crates\/([^\/]+)\/?([^\/]*)', link)
129
+ if dn_loc_re:
130
+ oss_name = dn_loc_re[0][0]
131
+ oss_version = dn_loc_re[0][1]
101
132
 
102
- return ret, result_link, oss_name, oss_version
133
+ new_link = f'{host}/{oss_name}/{oss_version}/download'
134
+ res = urlopen(new_link)
135
+ if res.getcode() == 200:
136
+ ret = True
137
+ else:
138
+ logger.warning(f'Cannot find the valid link for cargo (url:{new_link}')
139
+ except Exception as error:
140
+ ret = False
141
+ logger.warning(f'Cannot find the link for cargo (url:{link}({(new_link)})): {error}')
142
+
143
+ return ret, new_link
144
+
145
+
146
+ def get_download_location_for_go(link):
147
+ # get the url for downloading source file: https://proxy.golang.org/<module>/@v/VERSION.zip
148
+ ret = False
149
+ new_link = ''
150
+ host = 'https://proxy.golang.org'
151
+
152
+ try:
153
+ dn_loc_re = re.findall(r'pkg.go.dev\/([^\@]+)\@?([^\/]*)', link)
154
+ if dn_loc_re:
155
+ oss_name = dn_loc_re[0][0]
156
+ if oss_name.endswith('/'):
157
+ oss_name = oss_name[:-1]
158
+ oss_version = dn_loc_re[0][1]
159
+
160
+ new_link = f'{host}/{oss_name}/@v/{oss_version}.zip'
161
+ try:
162
+ res = urlopen(new_link)
163
+ if res.getcode() == 200:
164
+ ret = True
165
+ else:
166
+ logger.warning(f'Cannot find the valid link for go (url:{new_link}')
167
+ except Exception as e:
168
+ logger.warning(f'Fail to find the valid link for go (url:{new_link}: {e}')
169
+ except Exception as error:
170
+ ret = False
171
+ logger.warning(f'Cannot find the link for go (url:{link}({(new_link)})): {error}')
172
+
173
+ return ret, new_link
103
174
 
104
175
 
105
176
  def get_download_location_for_pypi(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
  }
@@ -26,6 +26,7 @@ import platform
26
26
  import subprocess
27
27
  import re
28
28
  from typing import Tuple
29
+ import urllib.parse
29
30
 
30
31
  logger = logging.getLogger(constant.LOGGER_NAME)
31
32
  compression_extension = {".tar.bz2", ".tar.gz", ".tar.xz", ".tgz", ".tar", ".zip", ".jar", ".bz2"}
@@ -94,7 +95,8 @@ def parse_src_link(src_link):
94
95
 
95
96
  def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_to: str = "",
96
97
  compressed_only: bool = False, ssh_key: str = "",
97
- id: str = "", git_token: str = "") -> Tuple[bool, str, str, str]:
98
+ id: str = "", git_token: str = "",
99
+ called_cli: bool = True) -> Tuple[bool, str, str, str]:
98
100
  global logger
99
101
 
100
102
  success = True
@@ -126,7 +128,8 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
126
128
  success_git, msg, oss_name, oss_version = download_git_clone(link, target_dir,
127
129
  checkout_to,
128
130
  tag, branch,
129
- ssh_key, id, git_token)
131
+ ssh_key, id, git_token,
132
+ called_cli)
130
133
  link = change_ssh_link_to_https(link)
131
134
  if (not is_rubygems) and (not success_git):
132
135
  if os.path.isfile(target_dir):
@@ -204,28 +207,44 @@ def get_github_token(git_url):
204
207
  return github_token
205
208
 
206
209
 
207
- def download_git_repository(refs_to_checkout, git_url, target_dir, tag):
210
+ def download_git_repository(refs_to_checkout, git_url, target_dir, tag, called_cli=True):
208
211
  success = False
209
212
  oss_version = ""
210
213
 
211
214
  logger.info(f"Download git url :{git_url}")
215
+ env = os.environ.copy()
216
+ if not called_cli:
217
+ env["GIT_TERMINAL_PROMPT"] = "0"
212
218
  if refs_to_checkout:
213
219
  try:
214
220
  # gitPython uses the branch argument the same whether you check out to a branch or a tag.
215
- Repo.clone_from(git_url, target_dir, branch=refs_to_checkout)
216
- success = True
217
- oss_version = refs_to_checkout
221
+ Repo.clone_from(git_url, target_dir, branch=refs_to_checkout, env=env)
222
+ if any(Path(target_dir).iterdir()):
223
+ success = True
224
+ oss_version = refs_to_checkout
225
+ logger.info(f"Files found in {target_dir} after clone.")
226
+ else:
227
+ logger.info(f"No files found in {target_dir} after clone.")
228
+ success = False
218
229
  except GitCommandError as error:
219
- logger.debug(f"Git checkout error:{error}")
230
+ logger.info(f"Git checkout error:{error}")
231
+ success = False
232
+ except Exception as e:
233
+ logger.info(f"Repo.clone_from error:{e}")
220
234
  success = False
221
235
 
222
236
  if not success:
223
- Repo.clone_from(git_url, target_dir)
224
- success = True
237
+ Repo.clone_from(git_url, target_dir, env=env)
238
+ if any(Path(target_dir).iterdir()):
239
+ success = True
240
+ else:
241
+ logger.info(f"No files found in {target_dir} after clone.")
242
+ success = False
225
243
  return success, oss_version
226
244
 
227
245
 
228
- def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="", ssh_key="", id="", git_token=""):
246
+ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="",
247
+ ssh_key="", id="", git_token="", called_cli=True):
229
248
  oss_name = get_github_ossname(git_url)
230
249
  refs_to_checkout = decide_checkout(checkout_to, tag, branch)
231
250
  msg = ""
@@ -249,17 +268,19 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="", s
249
268
  logger.info(f"Download git with ssh_key:{git_url}")
250
269
  git_ssh_cmd = f'ssh -i {ssh_key}'
251
270
  with Git().custom_environment(GIT_SSH_COMMAND=git_ssh_cmd):
252
- success, oss_version = download_git_repository(refs_to_checkout, git_url, target_dir, tag)
271
+ success, oss_version = download_git_repository(refs_to_checkout, git_url, target_dir, tag, called_cli)
253
272
  else:
254
273
  if id and git_token:
255
274
  try:
256
275
  m = re.match(r"^(ht|f)tp(s?)\:\/\/", git_url)
257
276
  protocol = m.group()
258
277
  if protocol:
259
- git_url = git_url.replace(protocol, f"{protocol}{id}:{git_token}@")
278
+ encoded_git_token = urllib.parse.quote(git_token, safe='')
279
+ encoded_id = urllib.parse.quote(id, safe='')
280
+ git_url = git_url.replace(protocol, f"{protocol}{encoded_id}:{encoded_git_token}@")
260
281
  except Exception as error:
261
282
  logger.info(f"Failed to insert id, token to git url:{error}")
262
- success, oss_version = download_git_repository(refs_to_checkout, git_url, target_dir, tag)
283
+ success, oss_version = download_git_repository(refs_to_checkout, git_url, target_dir, tag, called_cli)
263
284
 
264
285
  logger.info(f"git checkout: {oss_version}")
265
286
  refs_to_checkout = oss_version
@@ -293,7 +314,7 @@ def download_wget(link, target_dir, compressed_only):
293
314
 
294
315
  Path(target_dir).mkdir(parents=True, exist_ok=True)
295
316
 
296
- 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)
297
318
  if ret and new_link:
298
319
  link = new_link
299
320
 
@@ -302,6 +323,9 @@ def download_wget(link, target_dir, compressed_only):
302
323
  if link.endswith(ext):
303
324
  success = True
304
325
  break
326
+ if not success:
327
+ if pkg_type == 'cargo':
328
+ success = True
305
329
  else:
306
330
  success = True
307
331
 
@@ -309,7 +333,11 @@ def download_wget(link, target_dir, compressed_only):
309
333
  raise Exception('Not supported compression type (link:{0})'.format(link))
310
334
 
311
335
  logger.info(f"wget: {link}")
312
- 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)
313
341
  if platform.system() != "Windows":
314
342
  signal.alarm(0)
315
343
  else:
fosslight_util/help.py CHANGED
@@ -3,7 +3,10 @@
3
3
  # Copyright (c) 2021 LG Electronics Inc.
4
4
  # SPDX-License-Identifier: Apache-2.0
5
5
  import sys
6
- import pkg_resources
6
+ try:
7
+ from importlib.metadata import version, PackageNotFoundError
8
+ except ImportError:
9
+ from importlib_metadata import version, PackageNotFoundError # Python <3.8
7
10
 
8
11
  _HELP_MESSAGE_COMMON = """
9
12
  _______ _______ _______ _______ ___ ___ __
@@ -50,7 +53,10 @@ class PrintHelpMsg():
50
53
  def print_package_version(pkg_name: str, msg: str = "", exitopt: bool = True) -> str:
51
54
  if msg == "":
52
55
  msg = f"{pkg_name} Version:"
53
- cur_version = pkg_resources.get_distribution(pkg_name).version
56
+ try:
57
+ cur_version = version(pkg_name)
58
+ except PackageNotFoundError:
59
+ cur_version = "unknown"
54
60
 
55
61
  if exitopt:
56
62
  print(f'{msg} {cur_version}')
fosslight_util/set_log.py CHANGED
@@ -6,7 +6,6 @@
6
6
  import logging
7
7
  import os
8
8
  from pathlib import Path
9
- import pkg_resources
10
9
  import sys
11
10
  import platform
12
11
  from . import constant as constant
@@ -15,6 +14,11 @@ import coloredlogs
15
14
  from typing import Tuple
16
15
  from logging import Logger
17
16
 
17
+ try:
18
+ from importlib.metadata import version, PackageNotFoundError
19
+ except ImportError:
20
+ from importlib_metadata import version, PackageNotFoundError # Python <3.8
21
+
18
22
 
19
23
  def init_check_latest_version(pkg_version="", main_package_name=""):
20
24
 
@@ -92,9 +96,11 @@ def init_log(log_file: str, create_file: bool = True, stream_log_level: int = lo
92
96
  if main_package_name != "":
93
97
  pkg_info = main_package_name
94
98
  try:
95
- pkg_version = pkg_resources.get_distribution(main_package_name).version
99
+ pkg_version = version(main_package_name)
96
100
  init_check_latest_version(pkg_version, main_package_name)
97
101
  pkg_info = main_package_name + " v" + pkg_version
102
+ except PackageNotFoundError:
103
+ logger.debug('Cannot check the version: Package not found')
98
104
  except Exception as error:
99
105
  logger.debug('Cannot check the version:' + str(error))
100
106
  _result_log["Tool Info"] = pkg_info
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-util
3
- Version: 2.1.14
3
+ Version: 2.1.18
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Author: LG Electronics
@@ -1,17 +1,17 @@
1
1
  fosslight_util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- fosslight_util/_get_downloadable_url.py,sha256=cn5ahD04YzetTx8PAXnqRMF_i8iA4dKUPZ7Fi9QXm3I,9286
2
+ fosslight_util/_get_downloadable_url.py,sha256=SqXCESg1GVXhCpObZoceXdFJVecDrDp-7qW88w0QsCY,12091
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=5nLe0oE1pUHEawM4kLlryusPBlk6ptEvy4HtqwFmCMs,16292
7
+ fosslight_util/download.py,sha256=V3EBgXt-xHarJZFrskXHaX4Ij81ZPjj6hzvtmpKu7xE,17642
8
8
  fosslight_util/exclude.py,sha256=fDmBsZJ_F7O9Oh2T-07R03XNbElo1tFaf_z01KfSAqU,2399
9
- fosslight_util/help.py,sha256=M3_XahUkP794US9Q0NS6ujmGvrFFnKBHsTU95Fg1KpA,2181
9
+ fosslight_util/help.py,sha256=Bmyz-eFP0X0qUfgFPrWiuyUPE0TLQfWjgfHTzJBIInc,2377
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
13
13
  fosslight_util/read_excel.py,sha256=-QvrdxaNqYOpIm1H7ZqIEh5NLvFPymZo6BAOZcQmQug,5263
14
- fosslight_util/set_log.py,sha256=Xpa94AiOyGEK8ucaYkvkAllvlen1Pq_d6UG6kPYBYBc,3780
14
+ fosslight_util/set_log.py,sha256=AbcLFLvY9GSOYSN0a110wO5gNcyc8KKnNjl7GxHEW9A,4008
15
15
  fosslight_util/spdx_licenses.py,sha256=GvMNe_D4v2meapTVwPu2BJXInnTo3_gIzg669eJhUu0,3691
16
16
  fosslight_util/timer_thread.py,sha256=5VbZENQPD-N0NUmzEktqGr6Am-e7vxD79K05mmr29g0,433
17
17
  fosslight_util/write_cyclonedx.py,sha256=hq817j-0OM89B8jtZKgHgvVa0YEaYHlz_8R5vNpe21I,9662
@@ -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.14.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
28
- fosslight_util-2.1.14.dist-info/METADATA,sha256=tf14st0xgl7NnQjGzMwFiASC0CC1gHAXSBsnSIWCWI0,6500
29
- fosslight_util-2.1.14.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
30
- fosslight_util-2.1.14.dist-info/entry_points.txt,sha256=bzXX5i7HZ13V8BLKvtu_9KO3ZjtRypH-XszOXT6I3bU,69
31
- fosslight_util-2.1.14.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
32
- fosslight_util-2.1.14.dist-info/RECORD,,
27
+ fosslight_util-2.1.18.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
28
+ fosslight_util-2.1.18.dist-info/METADATA,sha256=eiYd-q6MOwvzp-SPII-NU2MPNQs6rdm9PgPZEWdweFY,6500
29
+ fosslight_util-2.1.18.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
30
+ fosslight_util-2.1.18.dist-info/entry_points.txt,sha256=bzXX5i7HZ13V8BLKvtu_9KO3ZjtRypH-XszOXT6I3bU,69
31
+ fosslight_util-2.1.18.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
32
+ fosslight_util-2.1.18.dist-info/RECORD,,