doc/website/tools/hardware-notes-creator.py
Sergio Carlavilla Delgado 989d921f5d Migrate doc to Hugo/AsciiDoctor
I'm very pleased to announce the release of
our new website and documentation using
the new toolchain with Hugo and AsciiDoctor.

To get more information about the new toolchain
please read the FreeBSD Documentation Project Primer[1],
Hugo docs[2] and AsciiDoctor docs[3].

Acknowledgment:
Benedict Reuschling <bcr@>
Glen Barber <gjb@>
Hiroki Sato <hrs@>
Li-Wen Hsu <lwhsu@>
Sean Chittenden <seanc@>
The FreeBSD Foundation

[1] https://docs.FreeBSD.org/en/books/fdp-primer/
[2] https://gohugo.io/documentation/
[3] https://docs.asciidoctor.org/home/

Approved by:    doceng, core
2021-01-26 00:31:29 +01:00

64 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
"""
BSD 2-Clause License
Copyright (c) 2020-2021, The FreeBSD Project
Copyright (c) 2020-2021, Sergio Carlavilla <carlavilla@FreeBSD.org>
This script will generate the Table of Contents of the Handbook
"""
#!/usr/bin/env python3
import sys, getopt
import ntpath
import subprocess
import os
manPagesPath = ""
def loadManPages(manPagesDir):
manPagesPaths = []
for root, _, files in os.walk(manPagesDir):
for file in files:
if file.endswith(".4"):
manPagesPaths.append(os.path.join(root, file))
return manPagesPaths
def createHardwareNotesDirectory(path):
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s " % path)
def main(argv):
try:
opts, args = getopt.getopt(argv,"hp:",["path="])
except getopt.GetoptError:
print('hardware-notes-creator.py -p <path>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('hardware-notes-creator.py -p <path>')
sys.exit()
elif opt in ("-p", "--path"):
manPagesPath = arg
manPages = loadManPages("/home/carlavilla/Projects/base/src/share/man/man4/")
createHardwareNotesDirectory('/home/carlavilla/Projects/testsssss')
for manPage in manPages:
manPageParsed = subprocess.getoutput("mandoc -Tmarkdown " + manPage + " | sed -n '/# HARDWARE/,/#/{/#/!p;}'")
if len(manPageParsed) > 0:
manPageName = ntpath.basename(manPage).replace(".4", "")
with open('/home/carlavilla/Projects/testsssss/{}.adoc'.format(manPageName), 'w', encoding = 'utf-8') as manPageFile:
manPageFile.write(manPageParsed)
if __name__ == "__main__":
main(sys.argv[1:])