Source code for libka.pkgedit.ka_copyright_file

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# pylint: disable=line-too-long
# kate: space-indent on; indent-width 4; replace-tabs on; indent-mode python; remove-trailing-space modified;
# vim: expandtab ts=4
# pylint: enable=line-too-long

############################################################################
#   Copyright © 2023 José Manuel Santamaría Lema <panfaust@gmail.com>      #
#                                                                          #
#   This program is free software; you can redistribute it and/or modify   #
#   it under the terms of the GNU General Public License as published by   #
#   the Free Software Foundation; either version 2 of the License, or      #
#   (at your option) any later version.                                    #
############################################################################

"""This module just provides the KAControlFile class"""

import tempfile
import os
import re
import shutil
import warnings

from debian import deb822
from debian.debian_support import Version

from libka.pkgedit.wrap_control import wrap_field
from libka.ka_data_utils import read_json_data_file

[docs] class KACopyrightFile(): """Class to represent a debian/copyright file""" def __init__(self, file_path='debian/copyright'): self._file_path = file_path self._file_parsed = False # def sanitize(self): # """Sanitizes a debian/control file so it won't trigger bugs from python-debian # or wrap-and-sort, see, for instance: # # https://git.launchpad.net/~kubuntu-packagers/kubuntu-packaging/+git/cantor/commit/?id=7422c21f # # https://git.launchpad.net/~kubuntu-packagers/kubuntu-packaging/+git/cantor/commit/?id=a90b3e90""" # #Open original and new control files # orig_control_file = open(self._file_path, 'r') # new_control_fd, new_control_path = tempfile.mkstemp(text=True) # new_control_file = os.fdopen(new_control_fd, mode='w') # for line in orig_control_file: # #Replace lines containing only whitespaces or tabs with blank lines # line = re.sub('^[ \t]*$', '', line) # #Write the line to the new control file only if it's not a comment # if re.match('^[ \t]*#', line) is None: # new_control_file.write(line) # #Close files # orig_control_file.close() # new_control_file.close() # #Move and delete the temporary file # shutil.copy(new_control_path, self._file_path) # os.remove(new_control_path) #
[docs] def parse_file(self): """Parses a debian/copyright file""" # self.sanitize() self._file_parsed = True copyright_file = deb822.Packages.iter_paragraphs(open(self._file_path, 'r')) self._first_paragraph = next(copyright_file) copyright_file.close()
[docs] def files_excluded(self): """Returns the list of files exluded in tarball repacking""" #Parse debian/copyright file if it wasn't already if not self._file_parsed: self.parse_file() #Get files excluded as a python list if 'Files-Excluded' in self._first_paragraph: files_excluded_str = self._first_paragraph['Files-Excluded'] files_excluded = re.split(r'\s+', files_excluded_str) else: files_excluded = [] #Return result return files_excluded