DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
conffwk.dal Namespace Reference

Classes

class  DalBase
class  DalType
class  FSMData
class  FSMTransition
class  FSMxTransition
class  FSMAction

Functions

 __strcmp__ (v1, v2)
 __recmp__ (pat, v)
 prettyprint_cardinality (not_null, multivalue)
 prettyprint_range (attr)
 prettyprint_doc (entry)
 get_classes (m)
 generate (configuration, other_dals=[])
 module (name, schema, other_dals=[], backend='oksconflibs', db=None)

Variables

dict __dal__ = {}

Detailed Description

Contains the base class for DAL types and auxiliary methods.

This module defines the PyDALBase class that is used as the base type for all
DAL classes. A few utilities are also available.

Function Documentation

◆ __recmp__()

__recmp__ ( pat,
v )

Definition at line 23 of file dal.py.

23def __recmp__(pat, v):
24 return pat.match(v) is not None
25
26

◆ __strcmp__()

__strcmp__ ( v1,
v2 )

Definition at line 19 of file dal.py.

19def __strcmp__(v1, v2):
20 return v1 == v2
21
22

◆ generate()

generate ( configuration,
other_dals = [] )
Generates the DAL python access layer for the configuration passed.

This method will generate the python DAL access layer for all classes
declared through the conffwk.Configuration object passed. If this file
includes other schemas, the classes for those schemas will also be
generated, unless, classes with matching names are passed through the
"other_dals" parameters.

This method will re-use classes generated in other calls to this method,
either directly (in DAL binding to a python module) or while you created
Configuration type objects. So, you can call this as many times as you want
without incurring in much overhead.

Keyword parameters:

configuration -- The conffwk.Configuration object that you want the prepare
the DAL for.

other_dals -- This is a list of classes that contain other DALs that should
be considered for the inheritance structure of the classes that are going
to be generated here. These classes will not be regenerated. This parameter
can be either a list of modules or classes that won't be regenerated, but
re-used by this generation method.

Returns the DAL classes you asked for.

Definition at line 606 of file dal.py.

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 # we can save a few loops here, we order by number of bases
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 # generate what we need to
663 while ordered:
664 next = ordered[0] # gets the first one, no matter what it is
665
666 # if I generated this before, just re-use the class,
667 # so python can check the types in the way the user expects
668 if next in __dal__:
669 klasses.append(__dal__[next])
670 other_classes[next] = __dal__[next]
671
672 # else, I need to generate a brand new class here and
673 # add it to my __dal__
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: # cannot yet generate for this one, rotate
679 ordered.append(next)
680 else: # we can generate this one now
681 klasses.append(DalType(next, tuple(bases),
682 {'__schema__':
683 configuration.__schema__[next]}))
684 # so we can use this next time
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

◆ get_classes()

get_classes ( m)
Returns a map with classes in a module, the key is the class name.

Definition at line 594 of file dal.py.

594def get_classes(m):
595 """Returns a map with classes in a module, the key is the class name."""
596
597 # assesses all classes from other modules, correlate with names
598 map = {}
599 for k in dir(m):
600 if k.find('__') == 0:
601 continue
602 map[k] = getattr(m, k)
603 return map
604
605

◆ module()

module ( name,
schema,
other_dals = [],
backend = 'oksconflibs',
db = None )
Creates a new python module with the OKS schema files passed as
parameter.

This method creates a new module for the user, using the schema files
passed as parameter. Classes from other DALs are not re-created, but just
re-used. This is an example usage:

import conffwk.dal
dal = conffwk.dal.module('dal', 'dal/schema/core.schema.xml')
DFdal = conffwk.dal.module('DFdal', 'DFConfiguration/schema/df.schema.xml',
                          [dal])

This will generate two python dals in the current context. One that binds
everything available in the first schema file and a second one that binds
everything else defined in the DF OKS schema file.

Keyword parameters:

name -- The name of the python module to create. It should match the name
of the variable you are attributing to, but it is not strictly required by
the python interpreter, just a good practice.

schema -- This is a list of OKS schema files that should be considered. You
can also pass OKS datafiles to this one, which actually includes the schema
files you want to have a DAL for. It will just work.

other_dals -- This is a list of other DAL modules that I'll not regenerate,
and which classes will *not* make part of the returned module. In fact,
this parameter is only used to restrict the amount of output classes since
once class is generated internally, it is not regenerated a second time.
In other words creating twice the same DAL implies in almost no overhead.

backend -- This is the OKS backend to use when retrieving the schemas. By
default it is set to 'oksconflibs', which is what we

Definition at line 695 of file dal.py.

695def module(name, schema, other_dals=[], backend='oksconflibs', db=None):
696 """Creates a new python module with the OKS schema files passed as
697 parameter.
698
699 This method creates a new module for the user, using the schema files
700 passed as parameter. Classes from other DALs are not re-created, but just
701 re-used. This is an example usage:
702
703 import conffwk.dal
704 dal = conffwk.dal.module('dal', 'dal/schema/core.schema.xml')
705 DFdal = conffwk.dal.module('DFdal', 'DFConfiguration/schema/df.schema.xml',
706 [dal])
707
708 This will generate two python dals in the current context. One that binds
709 everything available in the first schema file and a second one that binds
710 everything else defined in the DF OKS schema file.
711
712 Keyword parameters:
713
714 name -- The name of the python module to create. It should match the name
715 of the variable you are attributing to, but it is not strictly required by
716 the python interpreter, just a good practice.
717
718 schema -- This is a list of OKS schema files that should be considered. You
719 can also pass OKS datafiles to this one, which actually includes the schema
720 files you want to have a DAL for. It will just work.
721
722 other_dals -- This is a list of other DAL modules that I'll not regenerate,
723 and which classes will *not* make part of the returned module. In fact,
724 this parameter is only used to restrict the amount of output classes since
725 once class is generated internally, it is not regenerated a second time.
726 In other words creating twice the same DAL implies in almost no overhead.
727
728 backend -- This is the OKS backend to use when retrieving the schemas. By
729 default it is set to 'oksconflibs', which is what we
730 """
731 import types
732 from .Configuration import Configuration
733
734 retval = types.ModuleType(name)
735 if isinstance(schema, str):
736 schema = [schema]
737 for s in schema:
738 if db is None:
739 db = Configuration(backend + ':' + s)
740 else:
741 db.load(s)
742 db.__core_init__()
743
744 for k in generate(db, other_dals):
745 retval.__dict__[k.pyclassName()] = k
746 return retval
747

◆ prettyprint_cardinality()

prettyprint_cardinality ( not_null,
multivalue )
Returns a nice string representation for an object cardinality

Definition at line 27 of file dal.py.

27def prettyprint_cardinality(not_null, multivalue):
28 """Returns a nice string representation for an object cardinality"""
29 if not_null:
30 if multivalue:
31 return '1..*'
32 else:
33 return '1..1'
34
35 else:
36 if multivalue:
37 return '0..*'
38 else:
39 return '0..1'
40
41

◆ prettyprint_doc()

prettyprint_doc ( entry)
Pretty prints a schema Cache entry, to be used by __doc__ strings

Definition at line 51 of file dal.py.

51def prettyprint_doc(entry):
52 """Pretty prints a schema Cache entry, to be used by __doc__ strings"""
53 from .schema import oks_types
54
55 akeys = list(entry['attribute'].keys())
56 akeys.sort()
57 retval = ' Attributes:'
58 if len(akeys) == 0:
59 retval += ' None'
60 retval += '\n'
61 for k in akeys:
62 retval += ' - "' + k + '": ' + \
63 entry['attribute'][k]['description'].strip() + '\n'
64 retval += ' oks-type: ' + entry['attribute'][k]['type'] + '\n'
65 retval += ' cardinality: ' + \
66 prettyprint_cardinality(entry['attribute'][k]['not-null'],
67 entry['attribute'][k]['multivalue']) + '\n'
68 if entry['attribute'][k]['range']:
69 retval += ' range: ' + \
70 prettyprint_range(entry['attribute'][k]) + '\n'
71 if entry['attribute'][k]['init-value']:
72 retval += ' initial value: ' + \
73 str(entry['attribute'][k]['init-value']) + '\n'
74
75 rkeys = list(entry['relation'].keys())
76 rkeys.sort()
77 retval += '\n Relationships:'
78 if len(rkeys) == 0:
79 retval += ' None'
80 retval += '\n'
81 for k in rkeys:
82 retval += ' - "' + k + '": ' + \
83 entry['relation'][k]['description'].strip() + '\n'
84 retval += ' oks-class: ' + entry['relation'][k]['type'] + '\n'
85 retval += ' cardinality: ' + \
86 prettyprint_cardinality(entry['relation'][k]['not-null'],
87 entry['relation'][k]['multivalue']) + '\n'
88 retval += ' aggregated: ' + \
89 str(entry['relation'][k]['aggregation']) + '\n'
90 return retval[:-1]
91
92

◆ prettyprint_range()

prettyprint_range ( attr)
Prints the range of an attribute in a nice way

Definition at line 42 of file dal.py.

42def prettyprint_range(attr):
43 """Prints the range of an attribute in a nice way"""
44 to_print = list(attr['range']) # copy
45 for k in range(len(to_print)):
46 if isinstance(to_print[k], tuple):
47 to_print[k] = '..'.join([str(i) for i in to_print[k]])
48 return ', '.join([str(i) for i in to_print])
49
50

Variable Documentation

◆ __dal__

dict conffwk.dal.__dal__ = {}
private

Definition at line 14 of file dal.py.