Init
This commit is contained in:
48
old_scripts/convert_man.py
Normal file
48
old_scripts/convert_man.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
ROCKY_VERSION = "8.10"
|
||||
MAN_PATH = f"./export/{ROCKY_VERSION}/"
|
||||
HTML_BASE_PATH = f"./html_data2/{ROCKY_VERSION}/"
|
||||
|
||||
def process_file(file):
|
||||
rpm_name = file.parts[3]
|
||||
man_context = file.parts[7]
|
||||
man_filename = file.name.replace('.gz', '').rsplit('.', 1)[0]
|
||||
|
||||
output_folder = Path(HTML_BASE_PATH) / rpm_name / man_context
|
||||
output_folder.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
print(man_filename)
|
||||
|
||||
try:
|
||||
html_content = subprocess.check_output(
|
||||
f'zcat "{file}" | mandoc -T html -O fragment 2>/tmp/mandoc_error.log | python3 ./apply_template.py --rpm_name "{rpm_name}" --file_name "{man_filename}"',
|
||||
shell=True,
|
||||
text=True
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
print(f"Error processing file: {file}")
|
||||
with open('/tmp/mandoc_error.log', 'r') as error_log:
|
||||
print(error_log.read())
|
||||
return
|
||||
|
||||
title = ""
|
||||
for line in html_content.splitlines():
|
||||
if '<h1>NAME</h1>' in line:
|
||||
title = line.split('<p>')[1].split('</p>')[0].strip()
|
||||
break
|
||||
title = title or man_filename
|
||||
|
||||
if html_content:
|
||||
with open(output_folder / f"{man_filename}.html", 'w') as f:
|
||||
f.write(html_content)
|
||||
|
||||
def main():
|
||||
for root, _, files in os.walk(MAN_PATH):
|
||||
for file in files:
|
||||
process_file(Path(root) / file)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user