-
-
Save kijuky/fb4afa98bed209a9659b to your computer and use it in GitHub Desktop.
パッケージ名の追加(不完全)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() | |
if doc_file.find('class-use') != -1: | |
return start | |
# write | |
sheet.write(start, 0, ".".join(doc_file.split('\\')[:-1])) | |
sheet.write(start, 1, os.path.basename(doc_file.split('.')[0])) # remove extention | |
for method in methods: | |
if debug: | |
print method | |
sheet.write(start, 2, 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, cell_overwrite_ok=True) | |
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