1from bgenOutput import * 2 3class GeneratorGroup: 4 5 def __init__(self, prefix): 6 self.prefix = prefix 7 self.generators = [] 8 9 def add(self, g, dupcheck=0): 10 if dupcheck: 11 if g in self.generators: 12 print 'DUP', g.name 13 return 14 g.setprefix(self.prefix) 15 self.generators.append(g) 16 17 def generate(self): 18 for g in self.generators: 19 g.generate() 20 Output() 21 Output("static PyMethodDef %s_methods[] = {", self.prefix) 22 IndentLevel() 23 for g in self.generators: 24 g.reference() 25 Output("{NULL, NULL, 0}") 26 DedentLevel() 27 Output("};") 28 29 30def _test(): 31 void = None 32 from bgenGenerator import FunctionGenerator 33 group = GeneratorGroup("spam") 34 eggs = FunctionGenerator(void, "eggs") 35 group.add(eggs) 36 print "/* START */" 37 group.generate() 38 39if __name__ == "__main__": 40 _test() 41