fosslight-util 2.0.1__py3-none-any.whl → 2.0.2__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.
@@ -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
 
@@ -8,23 +8,6 @@ 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,
@@ -33,6 +16,27 @@ import traceback
33
16
 
34
17
  logger = logging.getLogger(LOGGER_NAME)
35
18
 
19
+ try:
20
+ from spdx_tools.common.spdx_licensing import spdx_licensing
21
+ from spdx_tools.spdx.model import (
22
+ Actor,
23
+ ActorType,
24
+ Checksum,
25
+ ChecksumAlgorithm,
26
+ CreationInfo,
27
+ Document,
28
+ File,
29
+ Package,
30
+ Relationship,
31
+ RelationshipType,
32
+ SpdxNoAssertion,
33
+ SpdxNone
34
+ )
35
+ from spdx_tools.spdx.validation.document_validator import validate_full_spdx_document
36
+ from spdx_tools.spdx.writer.write_anything import write_file
37
+ except Exception:
38
+ logger.info('No import spdx-tools')
39
+
36
40
 
37
41
  def get_license_list_version():
38
42
  version = 'N/A'
@@ -87,6 +91,7 @@ def write_spdx(output_file_without_ext, output_extension, scan_item, spdx_versio
87
91
  checksums=[Checksum(ChecksumAlgorithm.SHA1, file_item.checksum)])
88
92
  file_license = []
89
93
  file_copyright = []
94
+ file_comment = []
90
95
  for oss_item in file_item.oss_items:
91
96
  oss_licenses = []
92
97
  declared_oss_licenses = []
@@ -100,6 +105,7 @@ def write_spdx(output_file_without_ext, output_extension, scan_item, spdx_versio
100
105
  except Exception:
101
106
  logger.debug(f'No spdx license name: {oi}')
102
107
  lic_comment.append(oi)
108
+ file_comment.append(oi)
103
109
  if oss_licenses:
104
110
  file_license.extend(oss_licenses)
105
111
  if oss_item.copyright != '':
@@ -157,8 +163,8 @@ def write_spdx(output_file_without_ext, output_extension, scan_item, spdx_versio
157
163
  file.license_info_in_file = file_license
158
164
  if file_copyright:
159
165
  file.copyright_text = '\n'.join(file_copyright)
160
- if lic_comment:
161
- file.license_comment = ' '.join(lic_comment)
166
+ if file_comment:
167
+ file.license_comment = ' '.join(file_comment)
162
168
  doc.files.append(file)
163
169
 
164
170
  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.0.2
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Author: LG Electronics
@@ -26,14 +26,15 @@ Requires-Dist: coloredlogs
26
26
  Requires-Dist: python3-wget
27
27
  Requires-Dist: beautifulsoup4
28
28
  Requires-Dist: jsonmerge
29
- Requires-Dist: spdx-tools
30
29
  Requires-Dist: setuptools>=65.5.1
31
30
  Requires-Dist: npm
32
31
  Requires-Dist: requests
32
+ Requires-Dist: GitPython
33
33
  Requires-Dist: numpy; python_version < "3.8"
34
34
  Requires-Dist: numpy>=1.22.2; python_version >= "3.8"
35
35
  Requires-Dist: pygit2==1.6.1; python_version < "3.7"
36
36
  Requires-Dist: pygit2>=1.10.1; python_version >= "3.7"
37
+ Requires-Dist: spdx-tools>=0.8.2; sys_platform != "win32"
37
38
 
38
39
  <!--
39
40
  Copyright (c) 2021 LG Electronics
@@ -5,7 +5,7 @@ fosslight_util/constant.py,sha256=Ig3ACm9_QirE4389Wt-IfxOqRkVOUjqGnX1B05z2Byo,21
5
5
  fosslight_util/convert_excel_to_yaml.py,sha256=OJ11av4bsoxnVS15aa2aX-X3zGYUZW6M3118TPtHHTc,2323
6
6
  fosslight_util/correct.py,sha256=3iUipan8ZX8sbyIIGAPtMkAGvZ4YucjeJwx1K1Bx_z4,3897
7
7
  fosslight_util/cover.py,sha256=qqqKzxqFwKimal764FaugRUBcHWdeKt8af6xeK0mH8E,2040
8
- fosslight_util/download.py,sha256=X-R2RTWwmhx_LSIBZhIxzPTJZ2GwasZnhIsZ5m3hUig,14997
8
+ fosslight_util/download.py,sha256=y2WYHUjAUH5kTTDtPrAop9sD1QDWTiGgFdUbNocIuH0,15070
9
9
  fosslight_util/help.py,sha256=M3_XahUkP794US9Q0NS6ujmGvrFFnKBHsTU95Fg1KpA,2181
10
10
  fosslight_util/oss_item.py,sha256=lDbBzKDG0diId39Rk-kqtwGtTLpdATDPtkP47FhlkMA,6382
11
11
  fosslight_util/output_format.py,sha256=je3oVrDDnA160jIkFGpCHlG9Fc4YDlkQGwor2LFSmb0,8173
@@ -17,15 +17,15 @@ fosslight_util/timer_thread.py,sha256=5VbZENQPD-N0NUmzEktqGr6Am-e7vxD79K05mmr29g
17
17
  fosslight_util/write_excel.py,sha256=G0fIslbWoOtWZCJxbBGLCpUKbhmwrrqhI5PHwRw8_44,9931
18
18
  fosslight_util/write_opossum.py,sha256=ltmo6SkugKWdAYupeCqwE4-3lua0GwLpix1XqFC-tT8,11678
19
19
  fosslight_util/write_scancodejson.py,sha256=81n7cWNYoyIKE_V4Kx5YtL2CgjMPIjoKdnSU3inkpJY,2163
20
- fosslight_util/write_spdx.py,sha256=azAaZmkIeFhx9YlV644B59K7SYkLMxQbtAr2mwixwBs,11265
20
+ fosslight_util/write_spdx.py,sha256=R0jUrwy9dk1aBNbxDnS0ZLpRa-Te6rgYPmtWNUyzI6U,11493
21
21
  fosslight_util/write_txt.py,sha256=BEFjYBppqk1CITx-fUN4vfvKv0XCs1GXWtc2Iu-etU4,629
22
22
  fosslight_util/write_yaml.py,sha256=QlEKoIPQsEaYERfbP53TeKgnllYzhLQWm5wYjnWtVjE,3238
23
23
  fosslight_util/resources/frequentLicenselist.json,sha256=GUhzK6tu7ok10fekOnmVmUgIGRC-acGABZKTNKfDyYA,4776157
24
24
  fosslight_util/resources/frequent_license_nick_list.json,sha256=ryU2C_6ZxHbz90_sUN9OvI9GXkCMLu7oGcmd9W79YYo,5005
25
25
  fosslight_util/resources/licenses.json,sha256=mK55z-bhY7Mjpj2KsO1crKGGL-X3F6MBFQJ0zLlx010,240843
26
- fosslight_util-2.0.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
27
- fosslight_util-2.0.1.dist-info/METADATA,sha256=ESvt6K7SJ-ft5Lgt-5eNBzNv9Ss8EeJ4c5aYGB8it6s,6374
28
- fosslight_util-2.0.1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
29
- fosslight_util-2.0.1.dist-info/entry_points.txt,sha256=bzXX5i7HZ13V8BLKvtu_9KO3ZjtRypH-XszOXT6I3bU,69
30
- fosslight_util-2.0.1.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
31
- fosslight_util-2.0.1.dist-info/RECORD,,
26
+ fosslight_util-2.0.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
27
+ fosslight_util-2.0.2.dist-info/METADATA,sha256=0eZmjckM4kcQnjV5a8e0UgIATAL2CHRvaNyZ86Et9zc,6431
28
+ fosslight_util-2.0.2.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
29
+ fosslight_util-2.0.2.dist-info/entry_points.txt,sha256=bzXX5i7HZ13V8BLKvtu_9KO3ZjtRypH-XszOXT6I3bU,69
30
+ fosslight_util-2.0.2.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
31
+ fosslight_util-2.0.2.dist-info/RECORD,,