From b01389db001da0ccd012c4a9318ea09791b8bf1a Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Fri, 28 Apr 2006 00:00:00 +0000 Subject: [PATCH] Added first version of omkbuild script. This version is not fully functional yet. darcs-hash:20060428000011-f2ef6-1ff4aab4d8b6bea1d4c0dc213f0b87c219690705.gz --- omkbuild.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 omkbuild.py diff --git a/omkbuild.py b/omkbuild.py new file mode 100755 index 0000000..e88b294 --- /dev/null +++ b/omkbuild.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +from optparse import OptionParser +import os +import sys + +class Snippet: + + def __init__(self, fname): + self.name = "" + self.legal = [] + self.doc = [] + self.code = [] + self.read(fname) + + def read(self, fname): + self.name = fname + f = open(fname, "r") + current = self.legal + counter = 0 + for line in f: + if current == self.legal: + if line.strip() == "#": counter += 1 + else: counter = 0 + if counter == 2: current = self.doc + if line[0] != "#": current = self.code + + current.append(line) + + if not self.doc: + self.doc = self.legal + self.legal = [] + + f.close + + def __str__(self): + s = "Snippet: %s\n" % self.name + s += " Legal: %d lines\n" % len(self.legal) + s += " Doc: %d lines\n" % len(self.doc) + s += " Code: %d lines\n" % len(self.code) + return s + + +def parseCommandLine(): + parser = OptionParser(usage = """ + %prog [-o FILE] snippet1 snippet2 ... build Makefile.rules from snippets + %prog --split Makfile.rules + """) + parser.add_option("-s", "--split", + action="store", dest="split", default=False, metavar="RULES", + help="Split given Makefile.rules to the original snippets") + parser.add_option("-o", "--output", + action="store", dest="output", default=False, metavar="RULES", + help="Split given Makefile.rules to the original snippets") + (options, args) = parser.parse_args() + return options, args + +def splitRules(rules): + pass + +def buildRules(snippets, output): + if output: + f = open(output, "w+") + else: + f = sys.stdout + + parts = [] + + for snip in snippets: + parts.append(Snippet(snip)) + + for type in ['legal', 'doc', 'code']: + for snip in parts: + f.writelines(snip.__dict__[type]) + f.close() + +def main(): + (options, args) = parseCommandLine() + if options.split: + splitRules(options.split) + else: + buildRules(args, options.output) + + +if __name__ == "__main__": main() -- 2.39.2