Merge #160 Fix insertion of comments, parsing of os-release, and bump status to "production"
This commit is contained in:
commit
d93c49914c
3 changed files with 28 additions and 20 deletions
|
@ -1,4 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import ast
|
||||||
import configparser
|
import configparser
|
||||||
import contextlib
|
import contextlib
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
@ -52,26 +53,33 @@ def sortify(func):
|
||||||
return sorted(func(*args, **kwargs))
|
return sorted(func(*args, **kwargs))
|
||||||
return functools.update_wrapper(wrapper, func)
|
return functools.update_wrapper(wrapper, func)
|
||||||
|
|
||||||
def get_default_target():
|
def read_os_release():
|
||||||
try:
|
try:
|
||||||
os_release_file = open('/etc/os-release')
|
f = open('/etc/os-release')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
os_release_file = open('/usr/lib/os-release')
|
f = open('/usr/lib/os-release')
|
||||||
with os_release_file:
|
|
||||||
conf = configparser.ConfigParser()
|
for line in f:
|
||||||
conf.read_file(itertools.chain(["[os-release]"], os_release_file))
|
line = line.rstrip()
|
||||||
os_release = conf["os-release"]
|
if not line or line.startswith('#'):
|
||||||
|
continue
|
||||||
|
m = re.match(r'([A-Z][A-Z_0-9]+)=(.*)', line)
|
||||||
|
if m:
|
||||||
|
name, val = m.groups()
|
||||||
|
if val and val[0] in '"\'':
|
||||||
|
val = ast.literal_eval(val)
|
||||||
|
yield name, val
|
||||||
|
|
||||||
|
def get_default_target():
|
||||||
|
os_release = dict(read_os_release())
|
||||||
os_id = os_release.get("ID")
|
os_id = os_release.get("ID")
|
||||||
os_like = os_release.get("ID_LIKE")
|
# ID_LIKE is a space-separated list of identifiers like ID
|
||||||
if os_like is not None:
|
os_like = os_release.get("ID_LIKE", "").split()
|
||||||
os_like = shlex.split(os_like)
|
|
||||||
else:
|
|
||||||
os_like = []
|
|
||||||
|
|
||||||
# Order matters here!
|
# Order matters here!
|
||||||
if os_id == "mageia" or ("mageia" in os_like):
|
if "mageia" in (os_id, *os_like):
|
||||||
return "mageia"
|
return "mageia"
|
||||||
elif os_id == "fedora" or ("fedora" in os_like):
|
elif "fedora" in (os_id, *os_like):
|
||||||
return "fedora"
|
return "fedora"
|
||||||
elif "suse" in os_like:
|
elif "suse" in os_like:
|
||||||
return "opensuse"
|
return "opensuse"
|
||||||
|
|
|
@ -26,7 +26,7 @@ def dump_sdpx_to_fedora_map(file):
|
||||||
print(f"{k} → {v}", file=file)
|
print(f"{k} → {v}", file=file)
|
||||||
|
|
||||||
def translate_license_fedora(license):
|
def translate_license_fedora(license):
|
||||||
comments = ''
|
comments = []
|
||||||
final = []
|
final = []
|
||||||
for tag in license.split():
|
for tag in license.split():
|
||||||
# We accept all variant cases, but output lowercase which is what Fedora LicensingGuidelines specify
|
# We accept all variant cases, but output lowercase which is what Fedora LicensingGuidelines specify
|
||||||
|
@ -43,18 +43,18 @@ def translate_license_fedora(license):
|
||||||
|
|
||||||
mapped = spdx_to_fedora_map().get(key, None)
|
mapped = spdx_to_fedora_map().get(key, None)
|
||||||
if mapped is None:
|
if mapped is None:
|
||||||
comments += f'# FIXME: Upstream uses unknown SPDX tag {fulltag}!'
|
comments += [f'# FIXME: Upstream uses unknown SPDX tag {fulltag}!']
|
||||||
final.append(tag)
|
final.append(tag)
|
||||||
elif mapped == '':
|
elif mapped == '':
|
||||||
comments += f"# FIXME: Upstream SPDX tag {fulltag} not listed in Fedora's good licenses list.\n"
|
comments += [f"# FIXME: Upstream SPDX tag {fulltag} not listed in Fedora's good licenses list.",
|
||||||
comments += "# FIXME: This package might not be allowed in Fedora!\n"
|
"# FIXME: This package might not be allowed in Fedora!"]
|
||||||
final.append(tag)
|
final.append(tag)
|
||||||
else:
|
else:
|
||||||
final.append(mapped)
|
final.append(mapped)
|
||||||
if mapped != tag:
|
if mapped != tag:
|
||||||
print(f'Upstream license tag {fulltag} translated to {mapped}',
|
print(f'Upstream license tag {fulltag} translated to {mapped}',
|
||||||
file=_sys.stderr)
|
file=_sys.stderr)
|
||||||
return (' '.join(final), comments or None)
|
return (' '.join(final), '\n'.join(comments) or None)
|
||||||
|
|
||||||
def translate_license(target, license):
|
def translate_license(target, license):
|
||||||
license = translate_slashes(license)
|
license = translate_slashes(license)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -41,7 +41,7 @@ ARGS = dict(
|
||||||
author_email="ignatenkobrain@fedoraproject.org",
|
author_email="ignatenkobrain@fedoraproject.org",
|
||||||
url="https://pagure.io/fedora-rust/rust2rpm",
|
url="https://pagure.io/fedora-rust/rust2rpm",
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Development Status :: 4 - Beta",
|
"Development Status :: 5 - Production/Stable",
|
||||||
"Intended Audience :: Developers",
|
"Intended Audience :: Developers",
|
||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
"Operating System :: POSIX :: Linux",
|
"Operating System :: POSIX :: Linux",
|
||||||
|
|
Loading…
Reference in a new issue