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
def get_files_excluded(tree, subpath='', top_level=False): if top_level: path = os.path.join(subpath, 'copyright') else: path = os.path.join(subpath, 'debian', 'copyright') with tree.get_file(path) as f: try: copyright = Copyright(f, strict=False) except NotMachineReadableError: return [] try: return copyright.header["Files-Excluded"].split() except KeyError: return []
def do_heuristics(fp): c = Copyright() num_licenses = 0 for l in fp.readlines(): if l.startswith("License:"): num_licenses += 1 _, v = l.split(":", 1) data = {"License": v.strip()} lic_para = LicenseParagraph(data) c.add_license_paragraph(lic_para) if num_licenses > 0: return c else: return None
def _copyright(self) -> Optional[Copyright]: if self._copyright_val == 0: copyright_path = self.root / ".reuse/dep5" try: with copyright_path.open() as fp: self._copyright_val = Copyright(fp) except OSError: _LOGGER.debug("no .reuse/dep5 file, or could not read it") except DebianError: _LOGGER.exception(_(".reuse/dep5 has syntax errors")) # This check is a bit redundant, but otherwise I'd have to repeat # this line under each exception. if not self._copyright_val: self._copyright_val = None return self._copyright_val
groups = copyright_.get_group_dict(options) for fileinfo in filetree: if fileinfo.group: continue if isinstance(fileinfo, DirInfo): continue file_key = fileinfo.get_group_key(options) group = groups.setdefault(file_key, Group(file_key)) group.add_file(fileinfo) fileinfo.group = group licenses = set() c = Copyright() # Print files paragraphs for _, group in sorted(groups.items(), key=lambda i: i[1].sort_key(options)): if not group.copyright_block_valid(): continue licenses.update(group.licenses.keys()) if options.glob: files = group.files.get_patterns() else: files = group.files.sorted_members() if group.copyrights: holders = '\n '.join(group.copyrights.sorted_members())
def copyright(): """Create a dep5 Copyright object.""" with (RESOURCES_DIRECTORY / "fake_repository/.reuse/dep5").open() as fp: return Copyright(fp)
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
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