584def generate(configuration, other_dals=[]):
585 """Generates the DAL python access layer for the configuration passed.
586
587 This method will generate the python DAL access layer for all classes
588 declared through the conffwk.Configuration object passed. If this file
589 includes other schemas, the classes for those schemas will also be
590 generated, unless, classes with matching names are passed through the
591 "other_dals" parameters.
592
593 This method will re-use classes generated in other calls to this method,
594 either directly (in DAL binding to a python module) or while you created
595 Configuration type objects. So, you can call this as many times as you want
596 without incurring in much overhead.
597
598 Keyword parameters:
599
600 configuration -- The conffwk.Configuration object that you want the prepare
601 the DAL for.
602
603 other_dals -- This is a list of classes that contain other DALs that should
604 be considered for the inheritance structure of the classes that are going
605 to be generated here. These classes will not be regenerated. This parameter
606 can be either a list of modules or classes that won't be regenerated, but
607 re-used by this generation method.
608
609 Returns the DAL classes you asked for.
610 """
611 from types import ModuleType as module
612
613 klasses = []
614
615 other_classes = {}
616 for k in other_dals:
617 if isinstance(k, module):
618 other_classes.update(get_classes(k))
619 else:
620 other_classes[k.pyclassName()] = k
621
622
623 to_generate = {}
624 for k in configuration.classes():
625 if k in other_classes:
626 continue
627
628 N = len(configuration.superclasses(k))
629 if N in to_generate:
630 to_generate[N].append(k)
631 else:
632 to_generate[N] = [k]
633
634 ordered = []
635 run_order = list(to_generate.keys())
636 run_order.sort()
637 for k in run_order:
638 ordered += to_generate[k]
639
640
641 while ordered:
642 next = ordered[0]
643
644
645
646 if next in __dal__:
647 klasses.append(__dal__[next])
648 other_classes[next] = __dal__[next]
649
650
651
652 else:
653 bases = configuration.superclasses(next)
654 bases = [other_classes.get(k, None) for k in bases]
655 bases.append(DalBase)
656 if None in bases:
657 ordered.append(next)
658 else:
659 klasses.append(DalType(next, tuple(bases),
660 {'__schema__':
661 configuration.__schema__[next]}))
662
663 other_classes[next] = klasses[-1]
664 klasses[-1].__doc__ = prettyprint_doc(
665 configuration.__schema__[next])
666 __dal__[next] = klasses[-1]
667
668 del ordered[0]
669
670 return klasses
671
672