Пример #1
0
def post_install_clean_up():
    """Do some post-processing on the installation to clean things like property inheritance"""

    # Find all the intermediate properties that are using a base class and create an appropriate
    # inherited class that matches the inheriance of its parent class
    # Example:  say someone registers   "graph/colors/red"
    # We end up with  _BaseGraphColors, where _BaseGraph has a property 'colors' which points to it
    # Now, regular old Graph(_BaseGraph) did get any commands installed at colors specifically, so it inherits property 'color' which points to _BaseGraphColors
    # This makes things awkward because the Graph class installation doesn't know about the property color, since it wasn't installed there.
    # It becomes much more straightforward in Graph gets its own proeprty 'colors' (overriding inheritance) which points to a class GraphColors
    # So in this method, we look for this situation, now that installation is complete.
    installable_classes = metaprog.get_installable_classes()
    for cls in installable_classes:
        installation = metaprog.get_installation(cls)
        if installation:
            for name in dir(cls):
                member = getattr(cls, name)
                if metaprog.is_intermediate_property(member):
                    if name not in cls.__dict__:  # is inherited...
                        path =metaprog.InstallPath(installation.install_path.entity_type + '/' + name)
                        new_class = metaprog._create_class(path)  # create new, appropriate class to avoid inheritance
                        installation.add_property(cls, name, new_class)
                        metaprog.get_installation(new_class).keep_me = True  # mark its installation so it will survive the next for loop
            # Some added properties may access intermediate classes which did not end up
            # receiving any commands. They are empty and should not appear in the API.  We
            # will take a moment to delete them.  This approach seemed much better than writing
            # special logic to calculate fancy inheritance and awkwardly insert classes into
            # the hierarchy on-demand.
            for name, intermediate_cls in installation.intermediates.items():
                intermediate_installation = metaprog.get_installation(intermediate_cls)
                if not intermediate_installation.commands and not hasattr(intermediate_installation, "keep_me"):
                    delattr(cls, name)
                    del installation.intermediates[name]
Пример #2
0
def post_install_clean_up():
    """Do some post-processing on the installation to clean things like property inheritance"""

    # Find all the intermediate properties that are using a base class and create an appropriate
    # inherited class that matches the inheriance of its parent class
    # Example:  say someone registers   "graph/colors/red"
    # We end up with  _BaseGraphColors, where _BaseGraph has a property 'colors' which points to it
    # Then we see  "graph:titan/colors/blue"
    # We get TitanGraphColors(_BaseGraphColors) and TitaGraph has a property 'colors' which points to it
    # Now, regular old Graph(_BaseGraph) did get any commands installed at colors specifically, so it inherits property 'color' which points to _BaseGraphColors
    # This makes things awkward because the Graph class installation doesn't know about the property color, since it wasn't installed there.
    # It becomes much more straightforward in Graph gets its own proeprty 'colors' (overriding inheritance) which points to a class GraphColors
    # So in this method, we look for this situation, now that installation is complete.
    installable_classes = metaprog.get_installable_classes()
    for cls in installable_classes:
        installation = metaprog.get_installation(cls)
        if installation:
            for name in dir(cls):
                member = getattr(cls, name)
                if metaprog.is_intermediate_property(member):
                    if name not in cls.__dict__:  # is inherited...
                        path =metaprog.InstallPath(installation.install_path.entity_type + '/' + name)
                        new_class = metaprog._create_class(path)  # create new, appropriate class to avoid inheritance
                        installation.add_property(cls, name, new_class)
                        metaprog.get_installation(new_class).keep_me = True  # mark its installation so it will survive the next for loop
            # Some added properties may access intermediate classes which did not end up
            # receiving any commands. They are empty and should not appear in the API.  We
            # will take a moment to delete them.  This approach seemed much better than writing
            # special logic to calculate fancy inheritance and awkwardly insert classes into
            # the hierarchy on-demand.
            for name, intermediate_cls in installation.intermediates.items():
                intermediate_installation = metaprog.get_installation(intermediate_cls)
                if not intermediate_installation.commands and not hasattr(intermediate_installation, "keep_me"):
                    delattr(cls, name)
                    del installation.intermediates[name]
Пример #3
0
 def collect(o, a):
     try:
         if not metaprog.is_intermediate_property(a):
             info._add(o, a.command)
     except:
         pass
Пример #4
0
 def collect(o, a):
     try:
         if not metaprog.is_intermediate_property(a):
             info._add(o, a.command)
     except:
         pass