fosslight-util 2.0.1__tar.gz → 2.1.0__tar.gz

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.
Files changed (38) hide show
  1. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/PKG-INFO +1 -1
  2. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/requirements.txt +3 -2
  3. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/setup.py +1 -1
  4. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/download.py +25 -24
  5. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/oss_item.py +17 -0
  6. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/write_spdx.py +34 -19
  7. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util.egg-info/PKG-INFO +1 -1
  8. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util.egg-info/requires.txt +4 -1
  9. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/LICENSE +0 -0
  10. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/MANIFEST.in +0 -0
  11. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/README.md +0 -0
  12. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/setup.cfg +0 -0
  13. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/__init__.py +0 -0
  14. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/_get_downloadable_url.py +0 -0
  15. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/compare_yaml.py +0 -0
  16. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/constant.py +0 -0
  17. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/convert_excel_to_yaml.py +0 -0
  18. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/correct.py +0 -0
  19. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/cover.py +0 -0
  20. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/help.py +0 -0
  21. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/output_format.py +0 -0
  22. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/parsing_yaml.py +0 -0
  23. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/read_excel.py +0 -0
  24. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
  25. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
  26. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/resources/licenses.json +0 -0
  27. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/set_log.py +0 -0
  28. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/spdx_licenses.py +0 -0
  29. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/timer_thread.py +0 -0
  30. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/write_excel.py +0 -0
  31. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/write_opossum.py +0 -0
  32. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/write_scancodejson.py +0 -0
  33. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/write_txt.py +0 -0
  34. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util/write_yaml.py +0 -0
  35. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util.egg-info/SOURCES.txt +0 -0
  36. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
  37. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util.egg-info/entry_points.txt +0 -0
  38. {fosslight_util-2.0.1 → fosslight_util-2.1.0}/src/fosslight_util.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight_util
3
- Version: 2.0.1
3
+ Version: 2.1.0
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Author: LG Electronics
@@ -8,9 +8,10 @@ coloredlogs
8
8
  python3-wget
9
9
  beautifulsoup4
10
10
  jsonmerge
11
- spdx-tools
11
+ spdx-tools>=0.8.2;sys_platform!="win32"
12
12
  setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
13
13
  numpy; python_version < '3.8'
14
14
  numpy>=1.22.2; python_version >= '3.8'
15
15
  npm
16
- requests
16
+ requests
17
+ GitPython
@@ -14,7 +14,7 @@ with open('requirements.txt', 'r', 'utf-8') as f:
14
14
  if __name__ == "__main__":
15
15
  setup(
16
16
  name='fosslight_util',
17
- version='2.0.1',
17
+ version='2.1.0',
18
18
  package_dir={"": "src"},
19
19
  packages=find_packages(where='src'),
20
20
  description='FOSSLight Util',
@@ -10,7 +10,7 @@ import zipfile
10
10
  import logging
11
11
  import argparse
12
12
  import shutil
13
- import pygit2 as git
13
+ from git import Repo, GitCommandError
14
14
  import bz2
15
15
  import contextlib
16
16
  from datetime import datetime
@@ -230,14 +230,10 @@ def get_github_token(git_url):
230
230
 
231
231
 
232
232
  def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""):
233
- ref_to_checkout = decide_checkout(checkout_to, tag, branch)
234
- msg = ""
235
233
  oss_name = get_github_ossname(git_url)
236
- oss_version = ""
237
- github_token = get_github_token(git_url)
238
- callbacks = None
239
- if github_token != "":
240
- callbacks = git.RemoteCallbacks(credentials=git.UserPass("foo", github_token)) # username is not used, so set to dummy
234
+ refs_to_checkout = decide_checkout(checkout_to, tag, branch)
235
+ clone_default_branch_flag = False
236
+ msg = ""
241
237
 
242
238
  try:
243
239
  if platform.system() != "Windows":
@@ -248,9 +244,26 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""):
248
244
  alarm.start()
249
245
 
250
246
  Path(target_dir).mkdir(parents=True, exist_ok=True)
251
- repo = git.clone_repository(git_url, target_dir,
252
- bare=False, repository=None,
253
- remote=None, callbacks=callbacks)
247
+ if refs_to_checkout != "":
248
+ try:
249
+ # gitPython uses the branch argument the same whether you check out to a branch or a tag.
250
+ repo = Repo.clone_from(git_url, target_dir, branch=refs_to_checkout)
251
+ except GitCommandError as error:
252
+ error_msg = error.args[2].decode("utf-8")
253
+ if "Remote branch " + refs_to_checkout + " not found in upstream origin" in error_msg:
254
+ # clone default branch, when non-existent branch or tag entered
255
+ repo = Repo.clone_from(git_url, target_dir)
256
+ clone_default_branch_flag = True
257
+ else:
258
+ repo = Repo.clone_from(git_url, target_dir)
259
+ clone_default_branch_flag = True
260
+
261
+ if refs_to_checkout != tag or clone_default_branch_flag:
262
+ oss_version = repo.active_branch.name
263
+ else:
264
+ oss_version = repo.git.describe('--tags')
265
+ logger.info(f"git checkout: {oss_version}")
266
+
254
267
  if platform.system() != "Windows":
255
268
  signal.alarm(0)
256
269
  else:
@@ -258,20 +271,8 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""):
258
271
  except Exception as error:
259
272
  logger.warning(f"git clone - failed: {error}")
260
273
  msg = str(error)
261
- return False, msg, oss_name, oss_version
262
- try:
263
- if ref_to_checkout != "":
264
- ref_list = [x for x in repo.references]
265
- ref_to_checkout = get_ref_to_checkout(ref_to_checkout, ref_list)
266
- logger.info(f"git checkout: {ref_to_checkout}")
267
- repo.checkout(ref_to_checkout)
274
+ return False, msg, oss_name, refs_to_checkout
268
275
 
269
- for prefix_ref in prefix_refs:
270
- if ref_to_checkout.startswith(prefix_ref):
271
- oss_version = ref_to_checkout[len(prefix_ref):]
272
-
273
- except Exception as error:
274
- logger.warning(f"git checkout to {ref_to_checkout} - failed: {error}")
275
276
  return True, msg, oss_name, oss_version
276
277
 
277
278
 
@@ -5,6 +5,7 @@
5
5
 
6
6
  import logging
7
7
  import os
8
+ import hashlib
8
9
  from fosslight_util.constant import LOGGER_NAME, FOSSLIGHT_SCANNER
9
10
  from fosslight_util.cover import CoverItem
10
11
  from typing import List, Dict
@@ -171,6 +172,22 @@ class FileItem:
171
172
  return items
172
173
 
173
174
 
175
+ def get_checksum_sha1(source_name_or_path) -> str:
176
+ checksum = CHECKSUM_NULL
177
+ try:
178
+ checksum = str(hashlib.sha1(source_name_or_path.encode()).hexdigest())
179
+ except Exception:
180
+ try:
181
+ f = open(source_name_or_path, "rb")
182
+ byte = f.read()
183
+ checksum = str(hashlib.sha1(byte).hexdigest())
184
+ f.close()
185
+ except Exception as ex:
186
+ _logger.info(f"(Error) Get_checksum: {ex}")
187
+
188
+ return checksum
189
+
190
+
174
191
  def invalid(cmd):
175
192
  _logger.info('[{}] is invalid'.format(cmd))
176
193
 
@@ -8,31 +8,36 @@ import uuid
8
8
  import logging
9
9
  import re
10
10
  from pathlib import Path
11
- from spdx_tools.common.spdx_licensing import spdx_licensing
12
- from spdx_tools.spdx.model import (
13
- Actor,
14
- ActorType,
15
- Checksum,
16
- ChecksumAlgorithm,
17
- CreationInfo,
18
- Document,
19
- File,
20
- Package,
21
- Relationship,
22
- RelationshipType,
23
- SpdxNoAssertion,
24
- SpdxNone
25
- )
26
- from spdx_tools.spdx.validation.document_validator import validate_full_spdx_document
27
- from spdx_tools.spdx.writer.write_anything import write_file
28
11
  from datetime import datetime
29
12
  from fosslight_util.spdx_licenses import get_spdx_licenses_json, get_license_from_nick
30
13
  from fosslight_util.constant import (LOGGER_NAME, FOSSLIGHT_DEPENDENCY, FOSSLIGHT_SCANNER,
31
14
  FOSSLIGHT_BINARY, FOSSLIGHT_SOURCE)
15
+ from fosslight_util.oss_item import CHECKSUM_NULL, get_checksum_sha1
32
16
  import traceback
33
17
 
34
18
  logger = logging.getLogger(LOGGER_NAME)
35
19
 
20
+ try:
21
+ from spdx_tools.common.spdx_licensing import spdx_licensing
22
+ from spdx_tools.spdx.model import (
23
+ Actor,
24
+ ActorType,
25
+ Checksum,
26
+ ChecksumAlgorithm,
27
+ CreationInfo,
28
+ Document,
29
+ File,
30
+ Package,
31
+ Relationship,
32
+ RelationshipType,
33
+ SpdxNoAssertion,
34
+ SpdxNone
35
+ )
36
+ from spdx_tools.spdx.validation.document_validator import validate_full_spdx_document
37
+ from spdx_tools.spdx.writer.write_anything import write_file
38
+ except Exception:
39
+ logger.info('No import spdx-tools')
40
+
36
41
 
37
42
  def get_license_list_version():
38
43
  version = 'N/A'
@@ -81,12 +86,21 @@ def write_spdx(output_file_without_ext, output_extension, scan_item, spdx_versio
81
86
  for file_item in file_items:
82
87
  file = '' # file의 license, copyright은 oss item에서 append
83
88
  if scanner_name in [FOSSLIGHT_BINARY, FOSSLIGHT_SOURCE]:
89
+ if file_item.exclude:
90
+ continue
91
+ if file_item.checksum == CHECKSUM_NULL:
92
+ if os.path.exists(file_item.source_name_or_path):
93
+ file_item.checksum = get_checksum_sha1(file_item.source_name_or_path)
94
+ if file_item.checksum == CHECKSUM_NULL:
95
+ logger.info(f'Failed to get checksum, Skip: {file_item.source_name_or_path}')
96
+ continue
84
97
  file_id += 1
85
98
  file = File(name=file_item.source_name_or_path,
86
99
  spdx_id=f'SPDXRef-File{file_id}',
87
100
  checksums=[Checksum(ChecksumAlgorithm.SHA1, file_item.checksum)])
88
101
  file_license = []
89
102
  file_copyright = []
103
+ file_comment = []
90
104
  for oss_item in file_item.oss_items:
91
105
  oss_licenses = []
92
106
  declared_oss_licenses = []
@@ -100,6 +114,7 @@ def write_spdx(output_file_without_ext, output_extension, scan_item, spdx_versio
100
114
  except Exception:
101
115
  logger.debug(f'No spdx license name: {oi}')
102
116
  lic_comment.append(oi)
117
+ file_comment.append(oi)
103
118
  if oss_licenses:
104
119
  file_license.extend(oss_licenses)
105
120
  if oss_item.copyright != '':
@@ -157,8 +172,8 @@ def write_spdx(output_file_without_ext, output_extension, scan_item, spdx_versio
157
172
  file.license_info_in_file = file_license
158
173
  if file_copyright:
159
174
  file.copyright_text = '\n'.join(file_copyright)
160
- if lic_comment:
161
- file.license_comment = ' '.join(lic_comment)
175
+ if file_comment:
176
+ file.license_comment = ' '.join(file_comment)
162
177
  doc.files.append(file)
163
178
 
164
179
  if len(doc.packages) > 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-util
3
- Version: 2.0.1
3
+ Version: 2.1.0
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Author: LG Electronics
@@ -8,10 +8,10 @@ coloredlogs
8
8
  python3-wget
9
9
  beautifulsoup4
10
10
  jsonmerge
11
- spdx-tools
12
11
  setuptools>=65.5.1
13
12
  npm
14
13
  requests
14
+ GitPython
15
15
 
16
16
  [:python_version < "3.8"]
17
17
  numpy
@@ -24,3 +24,6 @@ pygit2==1.6.1
24
24
 
25
25
  [:python_version>='3.7']
26
26
  pygit2>=1.10.1
27
+
28
+ [:sys_platform != "win32"]
29
+ spdx-tools>=0.8.2
File without changes
File without changes
File without changes