# 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/version.py

# 
# Path: elbepack/shellhelper.py
# def system_out(cmd, stdin=None, allow_fail=False, env_add=None):
#     """system_out() - Wrapper around command_out().
# 
#     On failure, raises an exception if allow_fail=False, on success,
#     returns the output of cmd.
# 
#     --
# 
#     >>> system_out("false") # doctest: +ELLIPSIS
#     Traceback (most recent call last):
#     ...
#     elbepack.shellhelper.CommandError: ...
# 
#     >>> system_out("false", allow_fail=True)
#     ''
# 
#     """
#     code, out = command_out(cmd, stdin=stdin, env_add=env_add)
# 
#     if code != 0:
#         if not allow_fail:
#             raise CommandError(cmd, code)
# 
#     return out


from optparse import OptionParser
from datetime import datetime
from tempfile import NamedTemporaryFile
from elbepack.treeutils import etree
from elbepack.version import elbe_version
from elbepack.shellhelper import system_out
import sys
import os
import io
                sp.et.text = '\n'
                for l in mapping.get_override(pkg_name):
                    ll = sp.append('license')
                    ll.et.text = l

        if opt.use_nomos:
            nomos_l = scan_nomos(pkg.text('text'))
            if nomos_l[0] != 'No_license_found':
                nomos_node = pkg.append('nomos_licenses')
                nomos_node.et.text = '\n'
                for l in nomos_l:
                    ll = nomos_node.append('license')
                    ll.et.text = l

        if errors:
            for e in errors:
                ee = pkg.append('error')
                ee.et.text = e
            err_pkg += 1
        elif opt.only_errors:
            # No Errors, and only_errors is active
            # Remove package node
            tree.root.remove_child(pkg)

    if opt.tagvalue is not None:
        with io.open(opt.tagvalue, "wt", encoding='utf-8') as fp:
            fp.write(u'SPDXVersion: SPDX-1.2\n')
            fp.write(u'DataLicense: CC0-1.0\n')
            fp.write(u'\n')
            fp.write(u'## Creation Information\n')

# 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/version.py

# 
# Path: elbepack/shellhelper.py
# def system_out(cmd, stdin=None, allow_fail=False, env_add=None):
#     """system_out() - Wrapper around command_out().
# 
#     On failure, raises an exception if allow_fail=False, on success,
#     returns the output of cmd.
# 
#     --
# 
#     >>> system_out("false") # doctest: +ELLIPSIS
#     Traceback (most recent call last):
#     ...
#     elbepack.shellhelper.CommandError: ...
# 
#     >>> system_out("false", allow_fail=True)
#     ''
# 
#     """
#     code, out = command_out(cmd, stdin=stdin, env_add=env_add)
# 
#     if code != 0:
#         if not allow_fail:
#             raise CommandError(cmd, code)
# 
#     return out


# Path: elbepack/commands/parselicence.py
from optparse import OptionParser
from datetime import datetime
from tempfile import NamedTemporaryFile
from elbepack.treeutils import etree
from elbepack.version import elbe_version
from elbepack.shellhelper import system_out
import sys
import os
import io

                sp.et.text = '\n'
                for l in mapping.get_override(pkg_name):
                    ll = sp.append('license')
                    ll.et.text = l

        if opt.use_nomos:
            nomos_l = scan_nomos(pkg.text('text'))
            if nomos_l[0] != 'No_license_found':
                nomos_node = pkg.append('nomos_licenses')
                nomos_node.et.text = '\n'
                for l in nomos_l:
                    ll = nomos_node.append('license')
                    ll.et.text = l

        if errors:
            for e in errors:
                ee = pkg.append('error')
                ee.et.text = e
            err_pkg += 1
        elif opt.only_errors:
            # No Errors, and only_errors is active
            # Remove package node
            tree.root.remove_child(pkg)

    if opt.tagvalue is not None:
        with io.open(opt.tagvalue, "wt", encoding='utf-8') as fp:
            fp.write(u'SPDXVersion: SPDX-1.2\n')
            fp.write(u'DataLicense: CC0-1.0\n')
            fp.write(u'\n')
            fp.write(u'## Creation Information\n')

            fp.write(u'Creator: Tool: elbe-%s\n' % elbe_version)