# 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)


import sys
from optparse import OptionParser
from elbepack.treeutils import etree
from elbepack.validate import validate_xml

    oparser = OptionParser(
        usage="usage: %prog pin_versions [options] <xmlfile>")
    oparser.add_option("--skip-validation", action="store_true",
                       dest="skip_validation", default=False,
                       help="Skip xml schema validation")

    (opt, args) = oparser.parse_args(argv)

    if len(args) != 1:
        print("Wrong number of arguments")
        oparser.print_help()
        sys.exit(20)

    if not opt.skip_validation:
        validation = validate_xml(args[0])
        if validation:
            print("xml validation failed. Bailing out")
            for i in validation:
                print(i)
            sys.exit(20)

    try:
        xml = etree(args[0])
    except BaseException:
        print("Error reading xml file!")
        sys.exit(20)

    if not xml.has("fullpkgs"):
        print("xml file does not have fullpkgs node")

# 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/commands/pin_versions.py
import sys
from optparse import OptionParser
from elbepack.treeutils import etree
from elbepack.validate import validate_xml


    oparser = OptionParser(
        usage="usage: %prog pin_versions [options] <xmlfile>")
    oparser.add_option("--skip-validation", action="store_true",
                       dest="skip_validation", default=False,
                       help="Skip xml schema validation")

    (opt, args) = oparser.parse_args(argv)

    if len(args) != 1:
        print("Wrong number of arguments")
        oparser.print_help()
        sys.exit(20)

    if not opt.skip_validation:
        validation = validate_xml(args[0])
        if validation:
            print("xml validation failed. Bailing out")
            for i in validation:
                print(i)
            sys.exit(20)

    try:
        xml = etree(args[0])
    except BaseException:
        print("Error reading xml file!")
        sys.exit(20)

    if not xml.has("fullpkgs"):
        print("xml file does not have fullpkgs node")

        sys.exit(20)