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