/usr/share/doc/devhelp/tools/man2xml.py is in devhelp 3.18.1-1ubuntu5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | #!/usr/bin/env python
import os
import os.path
import string
# Add $GNOME_PATH/man too
MAN_PATH = ["/usr/man", "/usr/share/man", "/usr/local/man"]
MAN_SUBS = ["man1", "man2", "man3", "man4", "man5",
"man6", "man7", "man8", "man9"]
MAN_NAME = { "man1" : "Applications",
"man2" : "System Calls",
"man3" : "Library Functions",
"man4" : "Devices",
"man5" : "Configuration Files",
"man6" : "Games",
"man7" : "Conventions",
"man8" : "System Administration",
"man9" : "Kernel Routines"}
# 1. Get a list of all mandirs
chapters = []
for mandir in MAN_PATH:
dir_list = os.listdir (mandir)
for dir in dir_list:
if os.path.isdir (mandir + "/" + dir) and dir in MAN_SUBS:
chapters.append (mandir + "/" + dir)
# 2. Get a list of all manpages
man_pages = {}
funcs = []
for mandir in chapters:
list = os.listdir (mandir)
for file in list:
# Extract the name of the man page
name, section = string.split (file, ".", 1)
if section[-3:] == ".gz":
section = section[:-3]
man = os.path.basename (mandir)
filename = mandir + "/" + file
# Check out section 2* and 3*, but not 3pm
if section in ['2', '3'] and section[-2:] != "pm":
# Remove perl funtions
if string.find (name, "::") == -1:
funcs.append ((name, filename))
# Does the the dict have the key?
if not man_pages.has_key (man):
man_pages[man] = []
if name == "." or not name:
continue
man_pages[man].append ((name, filename))
# 3. Print out xml
print '<?xml version="1.0"?>'
print '<book title="Man pages">'
print
# 3.1 Print chapters
# Chapters
chapters.sort()
written = []
print '<chapters>'
for chap in chapters:
name = os.path.basename (chap)
if not man_pages.has_key (name):
continue
if name in written:
continue
written.append (name)
print ' <chapter name="%s">' % MAN_NAME[name]
list = man_pages[name]
list.sort()
for name, page in list:
print ' <sub name="%s" link="%s"/>' % (name, page)
print ' </chapter>'
print
print '</chapters>'
print
# 3.2 print functions
# Functions
funcs.sort()
print '<functions>'
for name, file in funcs:
print ' <function name="%s" link="%s"/>' % (name, file)
print '</functions>'
print
print '</book>'
|