Beispiel #1
0
    def write_licenses(self, f, pkglist, xml_fname=None):
        licence_xml = copyright_xml()
        for pkg in pkglist:
            copyright_file = os.path.join('/usr/share/doc', pkg, 'copyright')
            copyright_fname = self.fname(copyright_file)
            try:
                with io.open(copyright_fname,
                             "r",
                             encoding='utf-8',
                             errors='replace') as lic:
                    lic_text = lic.read()
            except IOError as e:
                logging.exception("Error while processing license file %s",
                                  copyright_fname)
                lic_text = u"Error while processing license file %s: '%s'" % (
                    copyright_file, e.strerror)
            # in Python2 'pkg' is a binary string whereas in Python3 it is a
            # unicode string. So make sure that pkg ends up as a unicode string
            # in both Python2 and Python3.
            pkg = pkg.encode(encoding='utf-8').decode(encoding='utf-8')

            if f is not None:
                f.write(pkg)
                f.write(u":\n======================================"
                        "==========================================")
                f.write(u"\n")
                f.write(lic_text)
                f.write(u"\n\n")

            if xml_fname is not None:
                licence_xml.add_copyright_file(pkg, lic_text)

        if xml_fname is not None:
            licence_xml.write(xml_fname)
Beispiel #2
0
    def write_licenses(self, f, log, xml_fname=None):
        licence_xml = copyright_xml()
        for d in self.listdir("usr/share/doc/", skiplinks=True):
            try:
                with io.open(os.path.join(d, "copyright"), "rb") as lic:
                    lic_text = lic.read()
            except IOError as e:
                log.printo("Error while processing license file %s: '%s'" %
                           (os.path.join(d, "copyright"), e.strerror))
                lic_text = "Error while processing license file %s: '%s'" % (
                    os.path.join(d, "copyright"), e.strerror)

            lic_text = unicode(lic_text, encoding='utf-8', errors='replace')

            if f is not None:
                f.write(unicode(os.path.basename(d)))
                f.write(u":\n======================================"
                        "==========================================")
                f.write(u"\n")
                f.write(lic_text)
                f.write(u"\n\n")

            if xml_fname is not None:
                licence_xml.add_copyright_file(os.path.basename(d), lic_text)

        if xml_fname is not None:
            licence_xml.write(xml_fname)
Beispiel #3
0
    def write_licenses(self, f, pkglist, xml_fname=None):
        licence_xml = copyright_xml()
        for pkg in pkglist:
            copyright_file = os.path.join('/usr/share/doc', pkg, 'copyright')
            copyright_fname = self.fname(copyright_file)
            try:
                with io.open(copyright_fname, "rb") as lic:
                    lic_text = lic.read()
            except IOError as e:
                logging.exception("Error while processing license file %s",
                                  copyright_fname)
                lic_text = "Error while processing license file %s: '%s'" % (
                    copyright_file, e.strerror)

            lic_text = unicode(lic_text, encoding='utf-8', errors='replace')

            if f is not None:
                f.write(unicode(pkg))
                f.write(u":\n======================================"
                        "==========================================")
                f.write(u"\n")
                f.write(lic_text)
                f.write(u"\n\n")

            if xml_fname is not None:
                licence_xml.add_copyright_file(pkg, lic_text)

        if xml_fname is not None:
            licence_xml.write(xml_fname)