3 from optparse import OptionParser
9 def __init__(self, fname):
16 def read(self, fname):
22 if current == self.legal:
23 if line.strip() == "#": counter += 1
25 if counter == 2: current = self.doc
26 if line[0] != "#": current = self.code
37 s = "Snippet: %s\n" % self.name
38 s += " Legal: %d lines\n" % len(self.legal)
39 s += " Doc: %d lines\n" % len(self.doc)
40 s += " Code: %d lines\n" % len(self.code)
44 def parseCommandLine():
45 parser = OptionParser(usage = """
46 %prog [-o FILE] snippet1 snippet2 ... build Makefile.rules from snippets
47 %prog --split Makfile.rules
49 parser.add_option("-s", "--split",
50 action="store", dest="split", default=False, metavar="RULES",
51 help="Split given Makefile.rules to the original snippets")
52 parser.add_option("-o", "--output",
53 action="store", dest="output", default=False, metavar="RULES",
54 help="Split given Makefile.rules to the original snippets")
55 (options, args) = parser.parse_args()
58 def splitRules(rules):
61 def buildRules(snippets, output):
63 f = open(output, "w+")
70 parts.append(Snippet(snip))
72 for type in ['legal', 'doc', 'code']:
74 f.writelines(snip.__dict__[type])
78 (options, args) = parseCommandLine()
80 splitRules(options.split)
82 buildRules(args, options.output)
85 if __name__ == "__main__": main()