#!/usr/bin/env python # # Copyright (C) 2001 Leonardo J. Milano (lmilano@udel.edu) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # You can also get a copy of the license at: # http://www.gnu.org/copyleft/gpl.html #### imports import os import sys import string import fileinput class Params: def __init__(self): file_in = "" file_out = "" def parse_command_line(): if len(sys.argv) >= 3: p.file_in = os.path.abspath(sys.argv[1]) p.file_out = os.path.abspath(sys.argv[2]) else: print 'Usage: ./mk_doc.py file_input file_output' sys.exit() if not os.access(p.file_in, os.F_OK): print p.file_in, 'does not exist, exiting ...' print 'Usage: ./mk_doc.py file_input file_output' sys.exit() def parse_line(line,string_list): flag=0 stripped_line=string.replace(line,' ','') for a_string in string_list: try: tmp=string.index(stripped_line,a_string) except ValueError: pass else: if tmp==0: # look for the first word in line only flag = 1 if flag == 1: return "matched" else: return "failed" def parse_file(): g=open(p.file_out, "w") for line in fileinput.input(p.file_in): # result = parse_line(line,["import","class", "def", '####', "'", '"']) # verbose result = parse_line(line,["import","class", "def", '####']) # more quiet if result == "matched": g.write(line) g.close() p=Params() parse_command_line() parse_file()