3 from optparse import OptionParser
10 def __init__(self, fname):
17 def read(self, fname):
23 if current == self.legal:
24 if line.strip() == "#": counter += 1
26 if counter == 2: current = self.doc
28 if line[0] != "#": current = self.code
39 s = "Snippet: %s\n" % self.name
40 s += " Legal: %d lines\n" % len(self.legal)
41 s += " Doc: %d lines\n" % len(self.doc)
42 s += " Code: %d lines\n" % len(self.code)
46 def parseCommandLine():
47 parser = OptionParser(usage = """
48 %prog [-o FILE] snippet1 snippet2 ... build Makefile.rules from snippets
49 %prog --split Makfile.rules
51 parser.add_option("-s", "--split",
52 action="store", dest="split", default=False, metavar="RULES",
53 help="Split given Makefile.rules to the original snippets")
54 parser.add_option("-o", "--output",
55 action="store", dest="output", default=False, metavar="RULES",
56 help="Output built Makefile.rules to file RULES")
57 (options, args) = parser.parse_args()
60 def splitRules(rules):
63 def buildRules(snippets, output):
65 f = open(output, "w+")
72 parts.append(Snippet(snip))
74 for type in ['legal', 'doc', 'code']:
76 if len(snip.__dict__[type]) == 0: continue
77 firstLine = string.rstrip(snip.__dict__[type][0])
78 f.write(firstLine.ljust(60)+" #@omk@%s\n"%snip.name)
79 f.writelines(snip.__dict__[type][1:])
83 (options, args) = parseCommandLine()
85 splitRules(options.split)
87 buildRules(args, options.output)
90 if __name__ == "__main__": main()