File indexing completed on 2023-03-17 10:51:56
0001 from __future__ import print_function
0002 from __future__ import absolute_import
0003
0004
0005
0006
0007
0008
0009 from bs4 import BeautifulSoup
0010 import sys, os, copy
0011
0012 htmlFullPath = None
0013 htmlFilePath = None
0014 htmlFileName = None
0015 fileNameTemplate = None
0016 htmlPage = None
0017 tableClassName = 'directory'
0018
0019
0020
0021 def extractPages(configFileFlag = False):
0022
0023 pages = {'A':[]}
0024
0025 table = htmlPage.find('table', {'class' : tableClassName})
0026 for row in table.findAll('tr'):
0027
0028
0029
0030
0031
0032 styleFlag = False
0033 if 'style' in row: styleFlag = True
0034
0035 if not styleFlag: firstLetter = row.findAll('td')[0].text[0].upper()
0036
0037 if firstLetter not in pages:
0038 pages[firstLetter] = []
0039
0040 if configFileFlag:
0041 url = row.find('a')['href']
0042 if '_cff' in url or '_cfi' in url or '_cfg' in url:
0043 pages[firstLetter].append(row)
0044 else:
0045 pages[firstLetter].append(row)
0046 return pages
0047
0048
0049
0050 def extractPagesForPackage():
0051
0052 pages = {}
0053 table = htmlPage.find('table', {'class' : tableClassName})
0054 for row in table.findAll('tr'):
0055
0056 name = row.findAll('td')[0].text
0057
0058 name = name[name.find(' '):name.find('/')].strip()
0059
0060 if name not in pages: pages[name] = []
0061 pages[name].append(row)
0062 return pages
0063
0064
0065 def generateTab(items, curr, tabClass = 'tabs3'):
0066 itemTagMap = {}; tab = ''
0067 for item in items:
0068 fn = fileNameTemplate % item.replace(' ', '')
0069 if item != curr: tab += '<li><a href="%s">%s</a></li>' % (fn, item)
0070 else: tab += '<li class="current"><a href="%s">%s</a></li>'%(fn, item)
0071 return '<div class="%s"><ul class="tablist">%s</ul></div>' % (tabClass,tab)
0072
0073 if __name__ == "__main__":
0074 if len(sys.argv) < 2:
0075 sys.stderr.write("not enough parameter!\n")
0076 sys.exit(1)
0077
0078
0079 htmlFullPath = sys.argv[1]
0080 htmlFilePath = os.path.split(htmlFullPath)[0]
0081 htmlFileName = os.path.split(htmlFullPath)[1]
0082 fileNameTemplate = htmlFileName.replace('.html', '_%s.html')
0083
0084
0085 with open(htmlFullPath) as f:
0086 htmlPage = f.read()
0087 htmlPage = BeautifulSoup(htmlPage)
0088
0089
0090
0091
0092
0093
0094
0095 if htmlFileName == 'packageDocumentation.html':
0096 pages = extractPagesForPackage()
0097 destTabClassName = 'tabs'
0098 elif htmlFileName == 'configfiles.html':
0099 pages = extractPages(configFileFlag = True)
0100 destTabClassName = 'tabs2'
0101 else:
0102 pages = extractPages()
0103 destTabClassName = 'tabs2'
0104
0105 allRows = []
0106 pageNames = pages.keys(); pageNames.sort()
0107 for page in pageNames:
0108 allRows = allRows + pages[page]
0109 pages['All'] = allRows
0110 pageNames.append('All')
0111
0112
0113 table = htmlPage.find('table', {'class' : tableClassName})
0114
0115 for row in table.findAll('tr'):
0116 row.extract()
0117
0118
0119 for page in pageNames:
0120 print('generating %s...' % (fileNameTemplate % page))
0121 temp = BeautifulSoup(str(htmlPage))
0122 table = temp.find('table', {'class' : tableClassName})
0123 oldTab = temp.find('div', {'class' : destTabClassName})
0124 newTab = generateTab(pageNames, page)
0125 oldTab.replaceWith(BeautifulSoup(oldTab.prettify() + str(newTab)))
0126 for row in pages[page]:
0127 table.append(row)
0128
0129
0130 page = page.replace(' ', '_')
0131 with open('%s/%s'%(htmlFilePath, fileNameTemplate % page), 'w') as f:
0132 f.write(str(temp))