daemon: Some code reorganization to make XML support more modular.

This commit is contained in:
tgoff0@gmail.com 2014-12-15 18:22:46 +00:00
parent b1c2f19cbe
commit dee5a1670e
5 changed files with 832 additions and 796 deletions

View file

@ -0,0 +1,33 @@
#
# CORE
# Copyright (c)2011-2013 the Boeing Company.
# See the LICENSE file included in this distribution.
#
# author: Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com>
#
'''
Helpers for loading and saving XML files. savesessionxml(session, filename) is
the main public interface here.
'''
import os.path
from core.netns import nodes
from xmlparser import CoreDocumentParser
from xmlwriter import CoreDocumentWriter
def opensessionxml(session, filename, start=False, nodecls=nodes.CoreNode):
''' Import a session from the EmulationScript XML format.
'''
doc = CoreDocumentParser(session, filename, start, nodecls)
if start:
session.name = os.path.basename(filename)
session.filename = filename
session.node_count = str(session.getnodecount())
session.instantiate()
def savesessionxml(session, filename):
''' Export a session to the EmulationScript XML format.
'''
doc = CoreDocumentWriter(session)
doc.writexml(filename)