Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 41 lines (35 sloc) 1.58 KB
#!/usr/bin/env python
import fnmatch
import os
import gzip
import subprocess
import sqlite3
# Start with clean database
if os.access('manpages.db', os.F_OK):
conn = sqlite3.connect('manpages.db')
# Create tables
conn.execute('''CREATE TABLE IF NOT EXISTS "android_metadata" (locale TEXT DEFAULT 'en_US')''')
conn.execute('''CREATE TABLE manpages (_id INTEGER PRIMARY KEY, section TEXT, name TEXT, description TEXT, html TEXT)''')
cur = conn.cursor()
#for root, dirnames, filenames in os.walk('/usr/share/man'):
for section in range(0,10):
dirname = '/usr/share/man/man{0}'.format(section)
for filename in fnmatch.filter(os.listdir(dirname), '*.gz'):
print(os.path.join(dirname, filename))
f =, filename))
troff_data =
pid = subprocess.Popen(["groff", "-mandoc", "-i", "-T", "html"],
stdin = subprocess.PIPE,
stdout = subprocess.PIPE)
html = pid.communicate(troff_data)[0]
name = '.'.join(filename.split('.')[:-2])
subsection = filename.split('.')[-2]
description = subprocess.check_output(["apropos", "-s", str(section), "-e", name])
if len(description) > 0:
description = str(description.splitlines()[0])
description = description.split(' - ', 1)[1].strip(" '")
cur.execute('''INSERT INTO manpages (section, name, description, html) VALUES (?, ?, ?, ?)''',
(subsection, name, description, html))