# Path: elbepack/treeutils.py
# class etree(ebase):
#     def __init__(self, fname):
#         if fname is not None:
#             parser = XMLParser(huge_tree=True, remove_comments=False)
#             et = parse(fname, parser=parser)
#         else:
#             et = ElementTree(file=None)
# 
#         ebase.__init__(self, et)
# 
#     def write(self, fname, encoding=None):
#         # Make sure, that we end with a newline
#         self.et.getroot().tail = '\n'
#         self.et.write(fname, encoding=encoding)
# 
#     def tostring(self):
#         return self.et.tostring()
# 
#     def ensure_child(self, tag):
#         retval = self.et.find("./" + tag)
#         if retval is not None:
#             return elem(retval)
#         return elem(SubElement(self.et.getroot(), tag))
# 
#     def set_child_position(self, child, pos):
#         root = self.et.getroot()
#         root.remove(child.et)
#         root.insert(pos, child.et)
# 
#     def setroot(self, tag):
#         retval = elem(Element(tag))
#         # pylint: disable=protected-access
#         self.et._setroot(retval.et)
#         return retval
# 
#     @property
#     def root(self):
#         return elem(self.et.getroot())
# 
# Path: elbepack/validate.py
# def validate_xml(fname):
#     if os.path.getsize(fname) > (1 << 30):
#         return ["%s is greater than 1 GiB. "
#                 "Elbe does not support files of this size." % fname]
# 
#     schema_file = "https://www.linutronix.de/projects/Elbe/dbsfed.xsd"
#     parser = XMLParser(huge_tree=True)
#     schema_tree = etree.parse(schema_file)
#     schema = etree.XMLSchema(schema_tree)
# 
#     try:
#         xml = parse(fname, parser=parser)
# 
#         if schema.validate(xml):
#             return validate_xml_content(xml)
#     except etree.XMLSyntaxError:
#         return ["XML Parse error\n" + str(sys.exc_info()[1])]
#     except BaseException:
#         return ["Unknown Exception during validation\n" +
#                 str(sys.exc_info()[1])]
# 
#     # We have errors, return them in string form...
#     return error_log_to_strings(schema.error_log)
# 
# Path: elbepack/xmldefaults.py
# class ElbeDefaults:
# 
#     def __init__(self, build_type):
# 
#         assert build_type in defaults, ("Invalid buildtype %s\n"
#                                         "Valid buildtypes are:\n  - %s" %
#                                         (build_type, "\n  - ".join(defaults.keys())))
# 
#         self.defaults = defaults[build_type]
#         self.defaults["nicmac"] = get_random_mac()
# 
#         self.generic_defaults = archindep_defaults
# 
#     def __getitem__(self, key):
#         if key in self.defaults:
#             return self.defaults[key]
#         if key in self.generic_defaults:
#             return self.generic_defaults[key]
# 
#         return None
# 
# Path: elbepack/version.py



import os
import re
from urllib.error import URLError
from urllib.request import (urlopen, install_opener, build_opener,
                            HTTPPasswordMgrWithDefaultRealm,
                            HTTPBasicAuthHandler)
from elbepack.treeutils import etree
from elbepack.validate import validate_xml
from elbepack.xmldefaults import ElbeDefaults
from elbepack.version import elbe_version, is_devel
            tree.append_treecopy(e)

    def get_initvmnode_from(self, other):
        ivm = other.node('initvm')
        if ivm is None:
            raise NoInitvmNode()

        tree = self.xml.ensure_child('initvm')
        tree.clear()

        for e in ivm:
            tree.append_treecopy(e)

        self.xml.set_child_position(tree, 0)

    def get_initvm_codename(self):
        if self.has("initvm/suite"):
            return self.text("initvm/suite")
        return None

    def set_cdrom_mirror(self, abspath):
        mirror = self.node("project/mirror")
        mirror.clear()
        cdrom = mirror.ensure_child("cdrom")
        cdrom.set_text(abspath)

    def dump_elbe_version(self):
        if is_devel:
            ver_text = elbe_version + '-devel'
        else:

# Path: elbepack/treeutils.py
# class etree(ebase):
#     def __init__(self, fname):
#         if fname is not None:
#             parser = XMLParser(huge_tree=True, remove_comments=False)
#             et = parse(fname, parser=parser)
#         else:
#             et = ElementTree(file=None)
# 
#         ebase.__init__(self, et)
# 
#     def write(self, fname, encoding=None):
#         # Make sure, that we end with a newline
#         self.et.getroot().tail = '\n'
#         self.et.write(fname, encoding=encoding)
# 
#     def tostring(self):
#         return self.et.tostring()
# 
#     def ensure_child(self, tag):
#         retval = self.et.find("./" + tag)
#         if retval is not None:
#             return elem(retval)
#         return elem(SubElement(self.et.getroot(), tag))
# 
#     def set_child_position(self, child, pos):
#         root = self.et.getroot()
#         root.remove(child.et)
#         root.insert(pos, child.et)
# 
#     def setroot(self, tag):
#         retval = elem(Element(tag))
#         # pylint: disable=protected-access
#         self.et._setroot(retval.et)
#         return retval
# 
#     @property
#     def root(self):
#         return elem(self.et.getroot())
# 
# Path: elbepack/validate.py
# def validate_xml(fname):
#     if os.path.getsize(fname) > (1 << 30):
#         return ["%s is greater than 1 GiB. "
#                 "Elbe does not support files of this size." % fname]
# 
#     schema_file = "https://www.linutronix.de/projects/Elbe/dbsfed.xsd"
#     parser = XMLParser(huge_tree=True)
#     schema_tree = etree.parse(schema_file)
#     schema = etree.XMLSchema(schema_tree)
# 
#     try:
#         xml = parse(fname, parser=parser)
# 
#         if schema.validate(xml):
#             return validate_xml_content(xml)
#     except etree.XMLSyntaxError:
#         return ["XML Parse error\n" + str(sys.exc_info()[1])]
#     except BaseException:
#         return ["Unknown Exception during validation\n" +
#                 str(sys.exc_info()[1])]
# 
#     # We have errors, return them in string form...
#     return error_log_to_strings(schema.error_log)
# 
# Path: elbepack/xmldefaults.py
# class ElbeDefaults:
# 
#     def __init__(self, build_type):
# 
#         assert build_type in defaults, ("Invalid buildtype %s\n"
#                                         "Valid buildtypes are:\n  - %s" %
#                                         (build_type, "\n  - ".join(defaults.keys())))
# 
#         self.defaults = defaults[build_type]
#         self.defaults["nicmac"] = get_random_mac()
# 
#         self.generic_defaults = archindep_defaults
# 
#     def __getitem__(self, key):
#         if key in self.defaults:
#             return self.defaults[key]
#         if key in self.generic_defaults:
#             return self.generic_defaults[key]
# 
#         return None
# 
# Path: elbepack/version.py



# Path: elbepack/elbexml.py
import os
import re
from urllib.error import URLError
from urllib.request import (urlopen, install_opener, build_opener,
                            HTTPPasswordMgrWithDefaultRealm,
                            HTTPBasicAuthHandler)
from elbepack.treeutils import etree
from elbepack.validate import validate_xml
from elbepack.xmldefaults import ElbeDefaults
from elbepack.version import elbe_version, is_devel

            tree.append_treecopy(e)

    def get_initvmnode_from(self, other):
        ivm = other.node('initvm')
        if ivm is None:
            raise NoInitvmNode()

        tree = self.xml.ensure_child('initvm')
        tree.clear()

        for e in ivm:
            tree.append_treecopy(e)

        self.xml.set_child_position(tree, 0)

    def get_initvm_codename(self):
        if self.has("initvm/suite"):
            return self.text("initvm/suite")
        return None

    def set_cdrom_mirror(self, abspath):
        mirror = self.node("project/mirror")
        mirror.clear()
        cdrom = mirror.ensure_child("cdrom")
        cdrom.set_text(abspath)

    def dump_elbe_version(self):
        if is_devel:
            ver_text = elbe_version + '-devel'
        else:

            ver_text = elbe_version