Add generic parser for /etc/man.conf

- Also rename get_paths_from_manpath() to get_paths_from_man_locations()
This commit is contained in:
Aaron Bieber 2017-12-11 07:08:02 -07:00 committed by Fabian Homborg
parent 277cd30520
commit db0ff0bcde

View File

@ -857,7 +857,7 @@ def parse_and_output_man_pages(paths, output_directory, show_progress):
add_diagnostic("Successfully parsed %d / %d pages" % (successful_count, total_count), BRIEF_VERBOSE) add_diagnostic("Successfully parsed %d / %d pages" % (successful_count, total_count), BRIEF_VERBOSE)
flush_diagnostics(sys.stderr) flush_diagnostics(sys.stderr)
def get_paths_from_manpath(): def get_paths_from_man_locations():
# Return all the paths to man(1) and man(8) files in the manpath # Return all the paths to man(1) and man(8) files in the manpath
import subprocess, os import subprocess, os
proc = None proc = None
@ -866,7 +866,6 @@ def get_paths_from_manpath():
parent_paths = os.getenv("MANPATH").strip().split(':') parent_paths = os.getenv("MANPATH").strip().split(':')
else: else:
# Some systems have manpath, others have `man --path` (like Haiku). # Some systems have manpath, others have `man --path` (like Haiku).
# TODO: Deal with systems that have neither (OpenBSD)
for prog in [['manpath'], ['man', '--path']]: for prog in [['manpath'], ['man', '--path']]:
try: try:
proc = subprocess.Popen(prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc = subprocess.Popen(prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@ -876,10 +875,18 @@ def get_paths_from_manpath():
manpath, err_data = proc.communicate() manpath, err_data = proc.communicate()
parent_paths = manpath.decode().strip().split(':') parent_paths = manpath.decode().strip().split(':')
if (not parent_paths) or (proc and proc.returncode > 0): if (not parent_paths) or (proc and proc.returncode > 0):
# HACK: Use some fallback in case we can't get anything else. # HACK: Use some fallbacks in case we can't get anything else.
# `mandoc` does not provide `manpath` or `man --path` and $MANPATH might not be set, so just use the default for mandoc (minus /usr/X11R6/man, because that's not relevant). # `mandoc` does not provide `manpath` or `man --path` and $MANPATH might not be set.
# The alternative is reading its config file (/etc/man.conf) # The alternative is reading its config file (/etc/man.conf)
sys.stderr.write("Unable to get the manpath, falling back to /usr/share/man:/usr/local/share/man. Please set $MANPATH if that is not correct.\n") if os.path.isfile('/etc/man.conf'):
data = open('/etc/man.conf', 'r')
for line in data:
if ('manpath' in line or 'MANPATH' in line):
p = line.split(' ')[1]
p = p.split()[0]
parent_paths.append(p)
if (not parent_paths):
sys.stderr.write("Unable to get the manpath, falling back to /usr/share/man:/usr/local/share/man. Please set $MANPATH if that is not correct.\n")
parent_paths = ["/usr/share/man", "/usr/local/share/man"] parent_paths = ["/usr/share/man", "/usr/local/share/man"]
result = [] result = []
for parent_path in parent_paths: for parent_path in parent_paths:
@ -943,8 +950,8 @@ if __name__ == "__main__":
assert False, "unhandled option" assert False, "unhandled option"
if use_manpath: if use_manpath:
# Fetch all man1 and man8 files from the manpath # Fetch all man1 and man8 files from the manpath or man.conf
file_paths.extend(get_paths_from_manpath()) file_paths.extend(get_paths_from_man_locations())
if cleanup_directories: if cleanup_directories:
for cleanup_dir in cleanup_directories: for cleanup_dir in cleanup_directories: