fosslight-util 2.1.29__tar.gz → 2.1.31__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 (48) hide show
  1. {fosslight_util-2.1.29/src/fosslight_util.egg-info → fosslight_util-2.1.31}/PKG-INFO +2 -1
  2. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/requirements.txt +1 -0
  3. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/setup.py +1 -1
  4. fosslight_util-2.1.31/src/fosslight_util/get_pom_license.py +120 -0
  5. fosslight_util-2.1.31/src/fosslight_util/help.py +108 -0
  6. {fosslight_util-2.1.29 → fosslight_util-2.1.31/src/fosslight_util.egg-info}/PKG-INFO +2 -1
  7. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util.egg-info/SOURCES.txt +1 -0
  8. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util.egg-info/requires.txt +1 -0
  9. fosslight_util-2.1.29/src/fosslight_util/help.py +0 -75
  10. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/LICENSE +0 -0
  11. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/MANIFEST.in +0 -0
  12. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/README.md +0 -0
  13. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/setup.cfg +0 -0
  14. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/__init__.py +0 -0
  15. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/_get_downloadable_url.py +0 -0
  16. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/compare_yaml.py +0 -0
  17. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/constant.py +0 -0
  18. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/correct.py +0 -0
  19. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/cover.py +0 -0
  20. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/download.py +0 -0
  21. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/exclude.py +0 -0
  22. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/oss_item.py +0 -0
  23. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/output_format.py +0 -0
  24. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/parsing_yaml.py +0 -0
  25. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/read_excel.py +0 -0
  26. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
  27. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
  28. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/resources/licenses.json +0 -0
  29. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/set_log.py +0 -0
  30. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/spdx_licenses.py +0 -0
  31. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/timer_thread.py +0 -0
  32. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/write_cyclonedx.py +0 -0
  33. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/write_excel.py +0 -0
  34. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/write_opossum.py +0 -0
  35. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/write_scancodejson.py +0 -0
  36. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/write_spdx.py +0 -0
  37. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/write_txt.py +0 -0
  38. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util/write_yaml.py +0 -0
  39. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
  40. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util.egg-info/entry_points.txt +0 -0
  41. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/src/fosslight_util.egg-info/top_level.txt +0 -0
  42. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/tests/test_cyclonedx.py +0 -0
  43. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/tests/test_download.py +0 -0
  44. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/tests/test_opossum.py +0 -0
  45. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/tests/test_spdx_licenses.py +0 -0
  46. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/tests/test_text.py +0 -0
  47. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/tests/test_write_output.py +0 -0
  48. {fosslight_util-2.1.29 → fosslight_util-2.1.31}/tests/test_write_yaml.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.1.29
3
+ Version: 2.1.31
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Download-URL: https://github.com/fosslight/fosslight_util
@@ -28,6 +28,7 @@ Requires-Dist: numpy
28
28
  Requires-Dist: requests
29
29
  Requires-Dist: GitPython
30
30
  Requires-Dist: cyclonedx-python-lib==8.5.*; sys_platform == "linux"
31
+ Requires-Dist: defusedxml
31
32
  Dynamic: author
32
33
  Dynamic: classifier
33
34
  Dynamic: description
@@ -14,3 +14,4 @@ numpy
14
14
  requests
15
15
  GitPython
16
16
  cyclonedx-python-lib==8.5.*;sys_platform=="linux"
17
+ defusedxml
@@ -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.1.29',
17
+ version='2.1.31',
18
18
  package_dir={"": "src"},
19
19
  packages=find_packages(where='src'),
20
20
  description='FOSSLight Util',
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (c) 2025 LG Electronics Inc.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ import os
7
+ import logging
8
+ import urllib.request
9
+ from urllib.error import URLError, HTTPError
10
+ from defusedxml.ElementTree import fromstring as xml_fromstring
11
+ import fosslight_util.constant as constant
12
+
13
+ logger = logging.getLogger(constant.LOGGER_NAME)
14
+
15
+
16
+ def get_license_from_pom(group_id: str = None,
17
+ artifact_id: str = None,
18
+ version: str = None,
19
+ pom_path: str = None,
20
+ check_parent: bool = True) -> str:
21
+
22
+ def build_urls(g, a, v):
23
+ group_path = g.replace('.', '/')
24
+ name = f"{a}-{v}.pom"
25
+ repo1 = f"https://repo1.maven.org/maven2/{group_path}/{a}/{v}/{name}"
26
+ google = f"https://dl.google.com/android/maven2/{group_path}/{a}/{v}/{name}"
27
+ return [repo1, google]
28
+
29
+ def fetch_pom(g, a, v):
30
+ for url in build_urls(g, a, v):
31
+ try:
32
+ with urllib.request.urlopen(url) as resp:
33
+ return resp.read().decode('utf-8')
34
+ except (HTTPError, URLError):
35
+ continue
36
+ return None
37
+
38
+ def extract_licenses(root):
39
+ licenses_elem = root.find('{*}licenses')
40
+ if licenses_elem is not None:
41
+ names = []
42
+ for lic in licenses_elem.findall('{*}license'):
43
+ name = lic.findtext('{*}name')
44
+ if name:
45
+ names.append(name.replace(',', ''))
46
+ if names:
47
+ return ', '.join(names)
48
+ return None
49
+
50
+ def extract_parent_info(root):
51
+ parent = root.find('{*}parent')
52
+ if parent is not None:
53
+ g = parent.findtext('{*}groupId') or parent.findtext('groupId')
54
+ a = parent.findtext('{*}artifactId') or parent.findtext('artifactId')
55
+ v = parent.findtext('{*}version') or parent.findtext('version')
56
+ if g and a and v:
57
+ return g, a, v
58
+ return None, None, None
59
+
60
+ visited = set()
61
+
62
+ def find_license_in_pom_recursive(g, a, v, check_parent_flag):
63
+ key = (g, a, v)
64
+ if key in visited:
65
+ return ''
66
+ visited.add(key)
67
+ content = fetch_pom(g, a, v)
68
+ if not content:
69
+ return ''
70
+ try:
71
+ root = xml_fromstring(content)
72
+ except Exception:
73
+ return ''
74
+ licenses = extract_licenses(root)
75
+ if licenses:
76
+ return licenses
77
+ if not check_parent_flag:
78
+ return ''
79
+ pg, pa, pv = extract_parent_info(root)
80
+ if pg and pa and pv:
81
+ return find_license_in_pom_recursive(pg, pa, pv, check_parent_flag)
82
+ return ''
83
+
84
+ try:
85
+ if pom_path:
86
+ if not os.path.exists(pom_path):
87
+ logger.warning(f"POM file not found: {pom_path}")
88
+ return ''
89
+ try:
90
+ with open(pom_path, 'r', encoding='utf-8') as f:
91
+ content = f.read()
92
+ xml_start = content.find('<?xml')
93
+ if xml_start > 0:
94
+ content = content[xml_start:]
95
+ elif xml_start == -1:
96
+ root_start = content.find('<project')
97
+ if root_start > 0:
98
+ content = content[root_start:]
99
+ root = xml_fromstring(content)
100
+ except Exception as e:
101
+ logger.warning(f"Failed to parse POM file {pom_path}: {e}")
102
+ return ''
103
+
104
+ licenses = extract_licenses(root)
105
+ if licenses:
106
+ return licenses
107
+ if not check_parent:
108
+ return ''
109
+ pg, pa, pv = extract_parent_info(root)
110
+ if pg and pa and pv:
111
+ return find_license_in_pom_recursive(pg, pa, pv, check_parent)
112
+
113
+ logger.debug(f"No license info found in local POM: {pom_path}, Retry with remote fetch.")
114
+
115
+ if not (group_id and artifact_id and version):
116
+ return ''
117
+ return find_license_in_pom_recursive(group_id, artifact_id, version, check_parent)
118
+ except Exception as e:
119
+ logger.warning(f"Error getting license from POM: {e}")
120
+ return ''
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (c) 2021 LG Electronics Inc.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+ import sys
6
+ import os
7
+ try:
8
+ from importlib.metadata import version, PackageNotFoundError
9
+ except ImportError:
10
+ from importlib_metadata import version, PackageNotFoundError # Python <3.8
11
+
12
+
13
+ def _supports_color():
14
+ """Check if the terminal supports color."""
15
+ # Check if output is redirected or if NO_COLOR environment variable is set
16
+ if not hasattr(sys.stdout, 'isatty') or not sys.stdout.isatty():
17
+ return False
18
+ if os.environ.get('NO_COLOR'):
19
+ return False
20
+ # Windows cmd.exe support (Windows 10+)
21
+ if sys.platform == 'win32':
22
+ return True
23
+ # Unix-like systems
24
+ return True
25
+
26
+
27
+ if _supports_color():
28
+ _RESET = "\033[0m"
29
+ _BOLD = "\033[1m"
30
+ _C1 = "\033[1;38;2;230;140;165m" # Toned Down Light Pink
31
+ _C2 = "\033[1;38;2;217;115;153m" # Toned Down Pink
32
+ _C3 = "\033[1;38;2;242;115;166m" # Medium Light Pink
33
+ _C4 = "\033[1;38;2;230;77;140m" # Pink
34
+ _C5 = "\033[1;38;2;217;38;115m" # Pink-Red
35
+ _C6 = "\033[1;38;2;191;19;89m" # Medium Red
36
+ _C7 = "\033[1;38;2;165;0;52m" # Burgundy (#A50034) - Middle
37
+ _C8 = "\033[1;38;2;140;0;44m" # Dark Burgundy
38
+ _C9 = "\033[1;38;2;115;0;36m" # Darker Burgundy
39
+ _C10 = "\033[1;38;2;89;0;28m" # Very Dark Burgundy
40
+ _STAR = "\033[1;38;5;226m" # Bright Yellow for stars
41
+ else:
42
+ # No color support
43
+ _RESET = _BOLD = _C1 = _C2 = _C3 = _C4 = _C5 = _C6 = _C7 = _C8 = _C9 = _C10 = _STAR = ""
44
+
45
+ _HELP_MESSAGE_COMMON = f"""
46
+ {_STAR} ═════════════════════════════════════════════════════════════════════{_RESET}
47
+ {_C1} ███████╗ {_C1}██████╗ {_C2}███████╗ {_C2}███████╗{_C3}██╗ {_C3}██╗ {_C4}██████╗ {_C5}██╗ {_C5}██╗{_C6}████████╗{_RESET}
48
+ {_C1} ██╔════╝{_C2}██╔═══██╗{_C2}██╔════╝ {_C3}██╔════╝{_C3}██║ {_C4}██║{_C4}██╔════╝ {_C5}██║ {_C6}██║{_C6}╚══██╔══╝{_RESET}
49
+ {_C2} █████╗ {_C2}██║ ██║{_C3}███████╗ {_C3}███████╗{_C4}██║ {_C5}██║{_C5}██║ ███╗{_C6}███████║{_C7} {_C7}██║ {_RESET}
50
+ {_C3} ██╔══╝ {_C3}██║ ██║{_C4}╚════██║ {_C4}╚════██║{_C5}██║ {_C6}██║{_C6}██║ ██║{_C7}██╔══██║{_C8} {_C8}██║ {_RESET}
51
+ {_C3} ██║ {_C4}╚██████╔╝{_C5}███████║ {_C5}███████║{_C6}███████╗{_C7}██║{_C7}╚██████╔╝{_C8}██║ {_C9}██║ {_C9}██║ {_RESET}
52
+ {_C4} ╚═╝ {_C5}╚═════╝ {_C5}╚══════╝ {_C6}╚══════╝{_C7}╚══════╝{_C8}╚═╝ {_C8}╚═════╝ {_C9}╚═╝ {_C10}╚═╝ {_C10}╚═╝ {_RESET}
53
+ {_STAR} ═════════════════════════════════════════════════════════════════════{_RESET}
54
+ {_STAR} ✨ Open Source Analysis Tool ✨{_RESET}
55
+ """
56
+
57
+
58
+ _HELP_MESSAGE_DOWNLOAD = """
59
+ FOSSLight Downloader is a tool to download the package via input URL
60
+
61
+ Usage: fosslight_download [option1] <arg1> [options2] <arg2>
62
+ ex) fosslight_download -s http://github.com/fosslight/fosslight -t output_dir -d log_dir
63
+
64
+ Required:
65
+ -s\t\t URL of the package to be downloaded
66
+
67
+ Optional:
68
+ -h\t\t Print help message
69
+ -t\t\t Output path name
70
+ -d\t\t Directory name to save the log file
71
+ -s\t\t Source link to download
72
+ -t\t\t Directory to download source code
73
+ -c\t\t Checkout to branch or tag/ or version
74
+ -z\t\t Unzip only compressed file
75
+ -o\t\t Generate summary output file with this option"""
76
+
77
+
78
+ class PrintHelpMsg():
79
+
80
+ def __init__(self, value: str = ""):
81
+ self.message_suffix = value
82
+
83
+ def print_help_msg(self, exitopt: bool) -> None:
84
+ print(_HELP_MESSAGE_COMMON)
85
+ print(self.message_suffix)
86
+
87
+ if exitopt:
88
+ sys.exit()
89
+
90
+
91
+ def print_package_version(pkg_name: str, msg: str = "", exitopt: bool = True) -> str:
92
+ if msg == "":
93
+ msg = f"{pkg_name} Version:"
94
+ try:
95
+ cur_version = version(pkg_name)
96
+ except PackageNotFoundError:
97
+ cur_version = "unknown"
98
+
99
+ if exitopt:
100
+ print(f'{msg} {cur_version}')
101
+ sys.exit(0)
102
+ else:
103
+ return cur_version
104
+
105
+
106
+ def print_help_msg_download(exitOpt=True):
107
+ helpMsg = PrintHelpMsg(_HELP_MESSAGE_DOWNLOAD)
108
+ helpMsg.print_help_msg(exitOpt)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.1.29
3
+ Version: 2.1.31
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Download-URL: https://github.com/fosslight/fosslight_util
@@ -28,6 +28,7 @@ Requires-Dist: numpy
28
28
  Requires-Dist: requests
29
29
  Requires-Dist: GitPython
30
30
  Requires-Dist: cyclonedx-python-lib==8.5.*; sys_platform == "linux"
31
+ Requires-Dist: defusedxml
31
32
  Dynamic: author
32
33
  Dynamic: classifier
33
34
  Dynamic: description
@@ -11,6 +11,7 @@ src/fosslight_util/correct.py
11
11
  src/fosslight_util/cover.py
12
12
  src/fosslight_util/download.py
13
13
  src/fosslight_util/exclude.py
14
+ src/fosslight_util/get_pom_license.py
14
15
  src/fosslight_util/help.py
15
16
  src/fosslight_util/oss_item.py
16
17
  src/fosslight_util/output_format.py
@@ -11,6 +11,7 @@ setuptools>=65.5.1
11
11
  numpy
12
12
  requests
13
13
  GitPython
14
+ defusedxml
14
15
 
15
16
  [:sys_platform == "linux"]
16
17
  spdx-tools==0.8.*
@@ -1,75 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- # Copyright (c) 2021 LG Electronics Inc.
4
- # SPDX-License-Identifier: Apache-2.0
5
- import sys
6
- try:
7
- from importlib.metadata import version, PackageNotFoundError
8
- except ImportError:
9
- from importlib_metadata import version, PackageNotFoundError # Python <3.8
10
-
11
- _HELP_MESSAGE_COMMON = """
12
- _______ _______ _______ _______ ___ ___ __
13
- | || || || || | |___| | | _
14
- | ___|| _ || _____|| _____|| | ___ | |____ __| |__
15
- | |___ | | | || |_____ | |_____ | | | | _______ | _ ||__ __|
16
- | ___|| |_| ||_____ ||_____ || |___ | || _ || | | | | |
17
- | | | | _____| | _____| || || || |_| || | | | | |__
18
- |___| |_______||_______||_______||_______||___||____ ||__| |__| |____|
19
- | |
20
- ____| |
21
- |_______|
22
- """
23
-
24
-
25
- _HELP_MESSAGE_DOWNLOAD = """
26
- FOSSLight Downloader is a tool to download the package via input URL
27
-
28
- Usage: fosslight_download [option1] <arg1> [options2] <arg2>
29
- ex) fosslight_download -s http://github.com/fosslight/fosslight -t output_dir -d log_dir
30
-
31
- Required:
32
- -s\t\t URL of the package to be downloaded
33
-
34
- Optional:
35
- -h\t\t Print help message
36
- -t\t\t Output path name
37
- -d\t\t Directory name to save the log file
38
- -s\t\t Source link to download
39
- -t\t\t Directory to download source code
40
- -c\t\t Checkout to branch or tag/ or version
41
- -z\t\t Unzip only compressed file
42
- -o\t\t Generate summary output file with this option"""
43
-
44
-
45
- class PrintHelpMsg():
46
-
47
- def __init__(self, value: str = ""):
48
- self.message_suffix = value
49
-
50
- def print_help_msg(self, exitopt: bool) -> None:
51
- print(_HELP_MESSAGE_COMMON)
52
- print(self.message_suffix)
53
-
54
- if exitopt:
55
- sys.exit()
56
-
57
-
58
- def print_package_version(pkg_name: str, msg: str = "", exitopt: bool = True) -> str:
59
- if msg == "":
60
- msg = f"{pkg_name} Version:"
61
- try:
62
- cur_version = version(pkg_name)
63
- except PackageNotFoundError:
64
- cur_version = "unknown"
65
-
66
- if exitopt:
67
- print(f'{msg} {cur_version}')
68
- sys.exit(0)
69
- else:
70
- return cur_version
71
-
72
-
73
- def print_help_msg_download(exitOpt=True):
74
- helpMsg = PrintHelpMsg(_HELP_MESSAGE_DOWNLOAD)
75
- helpMsg.print_help_msg(exitOpt)
File without changes