Skip to content

Instantly share code, notes, and snippets.

@FGtatsuro
Created December 28, 2011 09:18
Show Gist options
  • Save FGtatsuro/1527287 to your computer and use it in GitHub Desktop.
Save FGtatsuro/1527287 to your computer and use it in GitHub Desktop.
generate method list from javadoc
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import os.path
import sys
import lxml.html
import xlwt
def is_method(method):
if method.find('(') == -1:
return False
if method.find(')') == -1:
return False
return True
def write_on_sheet(doc_file, sheet, start, xpath_exp='//a/@name', debug=True):
root = lxml.html.parse(doc_file)
methods = [method for method in root.xpath(xpath_exp) if is_method(method)]
methods.sort()
# write
sheet.write(start, 0, os.path.basename(doc_file.split('.')[0])) # remove extention
for method in methods:
if debug:
print method
sheet.write(start, 1, method)
start += 1
return start
def main():
if len(sys.argv) != 2:
print 'Error'
sys.exit(1)
doc_files = []
extention = 'html'
exclude = 'package-'
for path, dirs, files in os.walk(sys.argv[1]):
doc_files.extend([os.path.join(path, f) for f in files if (f.find(exclude) == -1) and (f.find(extention) != -1)])
# excel file
book_name = 'method_list.xls'
sheet_name = 'All Methods'
if os.path.exists(book_name):
try:
os.remove(book_name)
except ex:
print "Sheet can't be removed"
print ex
sys.exit(1)
wb = xlwt.Workbook()
ws = wb.add_sheet(sheet_name)
start = 0
print doc_files
for doc_file in doc_files:
start = write_on_sheet(doc_file, ws, start)
wb.save(book_name)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment