[-] export distros
Some checks are pending
Shellcheck / check (push) Waiting to run

This commit is contained in:
Azalea 2026-04-07 07:42:18 +00:00
parent 9cc0f9a111
commit c147a2ffc6
2 changed files with 3 additions and 95 deletions

View File

@ -170,8 +170,8 @@ if __name__ == '__main__':
args = parser.parse_args()
pre_check()
# export_distros() # Removed: not needed anymore for python distro generation
edit_versions(args.version)
finalize_neofetch()
post_check()
create_release(args.version)

View File

@ -97,98 +97,6 @@ def generate_help(max_len: int, leading: str):
return wrap(out, max_len, leading)
def match_condition(match: str) -> str:
"""
Convert simple glob match condition to python
"""
match = [s.strip() for s in match.split("|")]
conds = []
for m in match:
stripped = m.strip("*'\"").lower()
if '*' in stripped or '"' in stripped:
print(f"TODO: Cannot properly parse: {m}")
# Exact matches
if m.strip("*") == m:
conds.append(f"name == '{stripped}'")
continue
# Both sides are *
if m.startswith("*") and m.endswith("*"):
conds.append(f"(name.startswith('{stripped}') or name.endswith('{stripped}'))")
continue
# Ends with *
if m.endswith("*"):
conds.append(f"name.startswith('{stripped}')")
continue
# Starts with *
if m.startswith("*"):
conds.append(f"name.endswith('{stripped}')")
continue
return ' or '.join(conds)
def export_distro(d: AsciiArt) -> str:
"""
Export distro to a python script
"""
# Escape variable name
varname = d.name.lower()
for s in string.punctuation + ' ':
varname = varname.replace(s, '_')
# Remove accents
varname = unicodedata.normalize('NFKD', varname).encode('ascii', 'ignore').decode('utf-8')
# Escape/unescape ascii
ascii = d.ascii.replace("\\\\", "\\")
quotes = '"""'
if '"""' in ascii:
quotes = "'''"
if "'''" in ascii:
print(f"TODO: Cannot escape ascii because both \"\"\" and ''' exist: {ascii}")
script = f"""# This file is automatically generated. Please do not modify.
from . import AsciiArt
{varname} = AsciiArt(match=r'''{d.match}''', color='{d.color}', ascii=r{quotes}
{ascii}
{quotes})
"""
write(Path(__file__).parent.parent / f'hyfetch/distros/{varname}.py', script)
# Generate python script for identifying the distro
return f"""
if {match_condition(d.match)}:
from .{varname} import {varname}
return {varname}
"""
def export_distros():
distros = parse_ascii_distros()
# print('\n'.join(d.match for d in distros))
py = """# This file is automatically generated. Please do not modify.
from __future__ import annotations
from . import AsciiArt
def detect(name: str) -> AsciiArt | None:
if not name:
return None
name = name.lower()
"""
py += '\n'.join(export_distro(d).strip('\n') for d in distros)
write(Path(__file__).parent.parent / f'hyfetch/distros/distro_detector.py', py)
if __name__ == '__main__':
# print(generate_help(100, ' ' * 32))
# print(generate_help(100, '# '))
export_distros()
print(generate_help(100, '# '))