forked from sjdaniels/coldbox.dashdocs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cbdoc2set.py
66 lines (53 loc) · 2.43 KB
/
cbdoc2set.py
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
#!/usr/local/bin/python
import os, re, sqlite3, sys
from bs4 import BeautifulSoup, NavigableString, Tag
docsetroot = sys.argv[1]
print docsetroot
db = sqlite3.connect(os.path.join(docsetroot,'Contents/Resources/docSet.dsidx'))
cur = db.cursor()
print 'Rebuilding Search Index'
try: cur.execute('DROP TABLE searchIndex;')
except: pass
cur.execute('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);')
cur.execute('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);')
docpath = os.path.join(docsetroot,'Contents/Resources/Documents')
funcpages = []
# index the Class pages
page = open(os.path.join(docpath,'allclasses-frame.html')).read()
soup = BeautifulSoup(page)
any = re.compile('.*')
for tag in soup.find_all('a', {'href':any}):
name = tag.text.strip()
if len(name) > 0:
path = tag.attrs['href'].strip()
if path.split('#')[0] not in ('index.html', 'allclasses-frame.html', 'overview-frame.html', 'overview-summary.html'):
cur.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?,?,?)', (name, 'Class', path))
funcpages.append(path)
print 'name: %s, path: %s' % (name, path)
# index the Package pages
page = open(os.path.join(docpath,'overview-frame.html')).read()
soup = BeautifulSoup(page)
any = re.compile('.*')
for tag in soup.find_all('a', {'href':any}):
name = tag.text.strip()
if len(name) > 0:
path = tag.attrs['href'].strip()
if path.split('#')[0] not in ('index.html', 'allclasses-frame.html', 'overview-frame.html', 'overview-summary.html'):
cur.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?,?,?)', (name, 'Package', path))
print 'name: %s, path: %s' % (name, path)
# index all of the methods found on Class pages
for funcpage in funcpages:
pagepath = funcpage.split('/')
pagefile = pagepath[len(pagepath)-1]
page = open(os.path.join(docpath,funcpage)).read()
soup = BeautifulSoup(page)
any = re.compile('.*')
for tag in soup.find_all('a', {'href':any}):
name = tag.text.strip()
if len(name) > 0:
path = tag.attrs['href'].strip()
if path.split('#')[0] == pagefile:
cur.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?,?,?)', (name, 'Method', ''.join([funcpage,'#',path.split('#')[1]])))
print 'name: %s, path: %s' % (name, ''.join([funcpage,'#',path.split('#')[1]]))
db.commit()
db.close()