fosslight-util 2.1.29__tar.gz → 2.1.30__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.
- {fosslight_util-2.1.29/src/fosslight_util.egg-info → fosslight_util-2.1.30}/PKG-INFO +1 -1
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/setup.py +1 -1
- fosslight_util-2.1.30/src/fosslight_util/get_pom_license.py +120 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30/src/fosslight_util.egg-info}/PKG-INFO +1 -1
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util.egg-info/SOURCES.txt +1 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/LICENSE +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/MANIFEST.in +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/README.md +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/requirements.txt +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/setup.cfg +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/__init__.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/_get_downloadable_url.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/compare_yaml.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/constant.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/correct.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/cover.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/download.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/exclude.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/help.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/oss_item.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/output_format.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/parsing_yaml.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/read_excel.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/resources/licenses.json +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/set_log.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/spdx_licenses.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/timer_thread.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/write_cyclonedx.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/write_excel.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/write_opossum.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/write_scancodejson.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/write_spdx.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/write_txt.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util/write_yaml.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util.egg-info/entry_points.txt +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util.egg-info/requires.txt +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util.egg-info/top_level.txt +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/tests/test_cyclonedx.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/tests/test_download.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/tests/test_opossum.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/tests/test_spdx_licenses.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/tests/test_text.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/tests/test_write_output.py +0 -0
- {fosslight_util-2.1.29 → fosslight_util-2.1.30}/tests/test_write_yaml.py +0 -0
|
@@ -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 ''
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{fosslight_util-2.1.29 → fosslight_util-2.1.30}/src/fosslight_util.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|