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