Пример #1
0
def restore(pool):
    copy_pool = Node(other_node=pool)

    for inx in range(len(SYSTEM.children)):
        if SYSTEM.children[inx].name == POOL.name:
            SYSTEM.children[inx].children.append(copy_pool)
            copy_pool.parent = SYSTEM.children[inx]
            break

    global OBJECTS

    def restore_node(node):
        for child in node.children:
            if child.terminal:
                child.handle_id()
                n = weakref.ref(child)
                OBJECTS[child.name][child.id] = n

                if child.type != child.name:
                   OBJECTS[child.type][child.id] = n

            restore_node(child)

    copy_pool.handle_id()
    OBJECTS[POOL.name][copy_pool.id] = weakref.ref(copy_pool)

    # restore NTP
    for child in SYSTEM.children:
        if child.name == NTP.name:
            OBJECTS[NTP.name][child.id] = weakref.ref(child)
            break

    restore_node(copy_pool)
Пример #2
0
from model.model_fixtures import load_all
from core.parser import Node
from core.parser import OBJECTS
from collections import defaultdict
import weakref

[globals().update(obj) for obj in load_all()]

system = Node(name="*", terminal=False)
system.add(Node(POOL.name, terminal=False))
system.add(Node(NTP.name, terminal=False))
NTP.create(system)

globals().update({"SYSTEM" : system})

def restore(pool):
    copy_pool = Node(other_node=pool)

    for inx in range(len(SYSTEM.children)):
        if SYSTEM.children[inx].name == POOL.name:
            SYSTEM.children[inx].children.append(copy_pool)
            copy_pool.parent = SYSTEM.children[inx]
            break

    global OBJECTS

    def restore_node(node):
        for child in node.children:
            if child.terminal:
                child.handle_id()
                n = weakref.ref(child)