]> rtime.felk.cvut.cz Git - omk.git/commitdiff
Added first version of omkbuild script.
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 28 Apr 2006 00:00:00 +0000 (00:00 +0000)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 28 Apr 2006 00:00:00 +0000 (00:00 +0000)
This version is not fully functional yet.

darcs-hash:20060428000011-f2ef6-1ff4aab4d8b6bea1d4c0dc213f0b87c219690705.gz

omkbuild.py [new file with mode: 0755]

diff --git a/omkbuild.py b/omkbuild.py
new file mode 100755 (executable)
index 0000000..e88b294
--- /dev/null
@@ -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()