def check_4_4_1():
    # Check that there is only one Vcs field.
    vcs_fields = []
    with open('debian/control') as f:
        source = next(Deb822.iter_paragraphs(f))
        for name in source:
            if name.lower() == 'vcs-browser':
                continue
            if name.lower().startswith('vcs-'):
                vcs_fields.append(name)
    if len(vcs_fields) > 1:
        raise UpgradeCheckFailure(
            "5.6.26", "package has more than one Vcs-<type> field")

    # Check that Files entries don't refer to directories.
    # They must be wildcards *in* the directories.
    try:
        with open('debian/copyright', 'r') as f:
            copyright = Copyright(f, strict=False)
            for para in copyright.all_files_paragraphs():
                for glob in para.files:
                    if os.path.isdir(glob):
                        raise UpgradeCheckFailure(
                            "copyright-format",
                            "Wildcards are required to match the contents of "
                            "directories")
    except FileNotFoundError:
        pass
    except NotMachineReadableError:
        pass
示例#2
0
    def add_copyright_file(self, pkg_name, copyright):

        # remove illegal characters from copyright
        copyright, _ = remove_re.subn('', copyright)

        xmlpkg = self.pkglist.append('pkglicense')
        xmlpkg.et.attrib['name'] = pkg_name
        txtnode = xmlpkg.append('text')
        txtnode.et.text = copyright

        bytesio = io.StringIO(unicode(txtnode.et.text))
        try:
            c = Copyright(bytesio)
            files = []

            for cc in c.all_files_paragraphs():
                files.append((cc.files, cc.license.synopsis, cc.copyright))

            xmlpkg.append('machinereadable')
            xmllic = xmlpkg.append('debian_licenses')
            seen = []
            for f in files:
                if f[1] in seen:
                    continue
                seen.append(f[1])
                ll = xmllic.append('license')
                ll.et.text = f[1]

            detailed = xmlpkg.append('detailed')
            for f in files:
                ff = detailed.append('files')
                for g in f[0]:
                    gg = ff.append('glob')
                    gg.et.text = g

                ll = ff.append('license')
                ll.et.text = f[1]

                cc = ff.append('copyright')
                cc.et.text = f[2]

            return

        except Exception as e:
            pass

        bytesio.seek(0)
        #textio = io.TextIOWrapper (bytesio, encoding='iso-8859-1')

        c = do_heuristics(bytesio)

        if not c is None:
            lics = get_heuristics_license_list(c)
            xmlpkg.append('heuristics')
            xmllic = xmlpkg.append('debian_licenses')
            for i in lics:
                l = xmllic.append('license')
                l.et.text = i

            return

        # Heuristics did not find anything either
        # just return
        return
示例#3
0
    def add_copyright_file(self, pkg_name, copyright_text):

        # pylint: disable=too-many-locals

        # remove illegal characters from copyright_text
        copyright_text, _ = remove_re.subn('', copyright_text)

        xmlpkg = self.pkglist.append('pkglicense')
        xmlpkg.et.attrib['name'] = pkg_name
        txtnode = xmlpkg.append('text')
        txtnode.et.text = copyright_text

        bytesio = io.StringIO(unicode(txtnode.et.text))
        try:
            c = Copyright(bytesio)
            files = []

            for cc in c.all_files_paragraphs():
                files.append((cc.files, cc.license.synopsis, cc.copyright))

            xmlpkg.append('machinereadable')
            xmllic = xmlpkg.append('debian_licenses')
            seen = []
            for f in files:
                if f[1] in seen:
                    continue
                seen.append(f[1])
                ll = xmllic.append('license')
                ll.et.text = f[1]

            detailed = xmlpkg.append('detailed')
            for f in files:
                ff = detailed.append('files')
                for g in f[0]:
                    gg = ff.append('glob')
                    gg.et.text = g

                ll = ff.append('license')
                ll.et.text = f[1]

                cc = ff.append('copyright')
                cc.et.text = f[2]

            return

        except Exception:
            pass

        bytesio.seek(0)

        c = do_heuristics(bytesio)

        if c is not None:
            lics = get_heuristics_license_list(c)
            xmlpkg.append('heuristics')
            xmllic = xmlpkg.append('debian_licenses')
            for i in lics:
                ltag = xmllic.append('license')
                ltag.et.text = i

            return

        # Heuristics did not find anything either
        # just return
        return
    def add_copyright_file(self, pkg_name, copyright_text):

        # pylint: disable=too-many-locals

        # remove illegal characters from copyright_text
        copyright_text, _ = remove_re.subn('', copyright_text)

        xmlpkg = self.pkglist.append('pkglicense')
        xmlpkg.et.attrib['name'] = pkg_name
        txtnode = xmlpkg.append('text')
        txtnode.et.text = copyright_text
        # in Python2 'txtnode.et.text' is a binary string whereas in Python3 it
        # is a unicode string. So make sure that 'txtnode.et.text' ends up as a
        # unicode string in both Python2 and Python3.
        bytesio = io.StringIO(
            txtnode.et.text.encode(encoding='utf-8',
                                   errors='replace').decode(encoding='utf-8',
                                                            errors='replace'))
        try:
            c = Copyright(bytesio, strict=True)

            files = []

            # Note!  Getters of cc can throw nasty exceptions!
            for cc in c.all_files_paragraphs():
                files.append((cc.files, cc.license.synopsis, cc.copyright))

        except (NotMachineReadableError, MachineReadableFormatError) as E:
            logging.warning("Error in copyright of package '%s': %s", pkg_name,
                            E)
        except Warning as W:
            logging.warning("Warning in copyrigh of package '%s' : %s",
                            pkg_name, W)
        else:

            xmlpkg.append('machinereadable')
            xmllic = xmlpkg.append('debian_licenses')
            seen = []
            for f in files:
                if f[1] in seen:
                    continue
                seen.append(f[1])
                ll = xmllic.append('license')
                ll.et.text = f[1]

            detailed = xmlpkg.append('detailed')
            for f in files:
                ff = detailed.append('files')
                for g in f[0]:
                    gg = ff.append('glob')
                    gg.et.text = g

                ll = ff.append('license')
                ll.et.text = f[1]

                cc = ff.append('copyright')
                cc.et.text = f[2]

            return

        bytesio.seek(0)

        c = do_heuristics(bytesio)

        if c is not None:
            lics = get_heuristics_license_list(c)
            xmlpkg.append('heuristics')
            xmllic = xmlpkg.append('debian_licenses')
            for i in lics:
                ltag = xmllic.append('license')
                ltag.et.text = i

            return

        # Heuristics did not find anything either
        # just return
        return