commit
87851b0ada
|
@ -17,7 +17,7 @@ class AppDataCheck(AbstractFilesCheck):
|
|||
super().__init__(config, output, r'/usr/share/appdata/.*\.(appdata|metainfo).xml$')
|
||||
|
||||
def check_file(self, pkg, filename):
|
||||
root = pkg.dirName()
|
||||
root = pkg.dir_name()
|
||||
f = root + filename
|
||||
cmd = self.cmd + f
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class BashismsCheck(AbstractFilesCheck):
|
|||
self.use_early_fail = '[-e]' in output
|
||||
|
||||
def check_file(self, pkg, filename):
|
||||
root = pkg.dirName()
|
||||
root = pkg.dir_name()
|
||||
pkgfile = pkg.files[filename]
|
||||
filepath = root + filename
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ class DBusPolicyCheck(AbstractCheck):
|
|||
try:
|
||||
if any(f.startswith(d) for d in DBUS_DIRECTORIES):
|
||||
send_policy_seen = False
|
||||
lf = pkg.dirName() + f
|
||||
lf = pkg.dir_name() + f
|
||||
xml = parse(lf)
|
||||
for policy in xml.getElementsByTagName('policy'):
|
||||
send_policy_seen = self._check_allow_policy_element(pkg, f, policy) or send_policy_seen
|
||||
|
|
|
@ -17,7 +17,7 @@ class LogrotateCheck(AbstractCheck):
|
|||
|
||||
if f.startswith('/etc/logrotate.d/'):
|
||||
try:
|
||||
for n, o in self.parselogrotateconf(pkg.dirName(), f).items():
|
||||
for n, o in self.parselogrotateconf(pkg.dir_name(), f).items():
|
||||
if n in dirs and dirs[n] != o:
|
||||
self.output.add_info('E', pkg, 'logrotate-duplicate', n)
|
||||
else:
|
||||
|
|
|
@ -92,7 +92,7 @@ class MenuCheck(AbstractCheck):
|
|||
elif not update_menus_regex.search(postun):
|
||||
self.output.add_info('E', pkg, 'postun-without-update-menus')
|
||||
|
||||
directory = pkg.dirName()
|
||||
directory = pkg.dir_name()
|
||||
for f in menus:
|
||||
# remove comments and handle cpp continuation lines
|
||||
text = subprocess.run(('/lib/cpp', directory + f), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=ENGLISH_ENVIROMENT).stdout.decode()
|
||||
|
|
|
@ -42,7 +42,7 @@ class MenuXDGCheck(AbstractFilesCheck):
|
|||
self._has_binary(pkg, root, cfp, filename)
|
||||
|
||||
def check_file(self, pkg, filename):
|
||||
root = pkg.dirName()
|
||||
root = pkg.dir_name()
|
||||
f = root + filename
|
||||
try:
|
||||
command = subprocess.run(('desktop-file-validate', f), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=ENGLISH_ENVIROMENT)
|
||||
|
|
|
@ -27,7 +27,7 @@ class PkgConfigCheck(AbstractFilesCheck):
|
|||
return
|
||||
|
||||
try:
|
||||
with open(pkg.dirName() + '/' + filename, 'r', encoding='utf-8') as pc_file:
|
||||
with open(pkg.dir_name() + '/' + filename, 'r', encoding='utf-8') as pc_file:
|
||||
for line in pc_file:
|
||||
self._check_invalid_pkgconfig_file(pkg, filename, line)
|
||||
self._check_invalid_libs_dir(pkg, filename, line)
|
||||
|
|
|
@ -17,11 +17,11 @@ class SignatureCheck(AbstractCheck):
|
|||
invalid_sig_regex = re.compile(r'invalid OpenPGP signature')
|
||||
|
||||
def check(self, pkg):
|
||||
retcode, output = pkg.checkSignature()
|
||||
retcode, output = pkg.check_signature()
|
||||
|
||||
# Skip all signature checks if checkSignature output is empty
|
||||
# Skip all signature checks if check_signature output is empty
|
||||
if output is None:
|
||||
print_warning(f'No output from checkSignature() for '
|
||||
print_warning(f'No output from check_signature() for '
|
||||
f'{pkg.filename}. Skipping signature checks.')
|
||||
return
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ from rpmlint.color import Color
|
|||
from rpmlint.config import Config
|
||||
from rpmlint.filter import Filter
|
||||
from rpmlint.helpers import print_warning, string_center
|
||||
from rpmlint.pkg import FakePkg, getInstalledPkgs, Pkg
|
||||
from rpmlint.pkg import FakePkg, get_installed_pkgs, Pkg
|
||||
from rpmlint.version import __version__
|
||||
|
||||
|
||||
|
@ -157,7 +157,7 @@ class Lint(object):
|
|||
def _load_installed_rpms(self, packages):
|
||||
existing_packages = []
|
||||
for name in packages:
|
||||
pkg = getInstalledPkgs(name)
|
||||
pkg = get_installed_pkgs(name)
|
||||
if pkg:
|
||||
existing_packages.extend(pkg)
|
||||
else:
|
||||
|
@ -238,18 +238,12 @@ class Lint(object):
|
|||
def _expand_filelist(self, files):
|
||||
packages = []
|
||||
for pkg in files:
|
||||
if pkg.is_file() and self._check_valid_suffix(pkg):
|
||||
if pkg.is_file() and pkg.suffix in ('.rpm', '.spm', '.spec'):
|
||||
packages.append(pkg)
|
||||
elif pkg.is_dir():
|
||||
packages.extend(self._expand_filelist(pkg.iterdir()))
|
||||
return packages
|
||||
|
||||
@staticmethod
|
||||
def _check_valid_suffix(filename):
|
||||
if any(ext == filename.suffix for ext in ['.rpm', '.spm', '.spec']):
|
||||
return True
|
||||
return False
|
||||
|
||||
def validate_file(self, pname, is_last):
|
||||
try:
|
||||
if pname.suffix == '.rpm' or pname.suffix == '.spm':
|
||||
|
|
|
@ -401,7 +401,7 @@ class Pkg(AbstractPkg):
|
|||
|
||||
# record decompression and extraction time
|
||||
start = time.monotonic()
|
||||
self.dirname = self.dir_name(dirname, verbose)
|
||||
self.dirname = self._extract_rpm(dirname, verbose)
|
||||
self.extraction_time = time.monotonic() - start
|
||||
self.current_linenum = None
|
||||
|
||||
|
@ -426,11 +426,11 @@ class Pkg(AbstractPkg):
|
|||
|
||||
(self.requires, self.prereq, self.provides, self.conflicts,
|
||||
self.obsoletes, self.recommends, self.suggests, self.enhances,
|
||||
self.supplements) = self._gatherDepInfo()
|
||||
self.supplements) = self._gather_dep_info()
|
||||
|
||||
self.req_names = [x[0] for x in self.requires + self.prereq]
|
||||
|
||||
self.files = self._gatherFilesInfo()
|
||||
self.files = self._gather_files_info()
|
||||
self.config_files = [x.name for x in self.files.values() if x.is_config]
|
||||
self.doc_files = [x.name for x in self.files.values() if x.is_doc]
|
||||
self.ghost_files = [x.name for x in self.files.values() if x.is_ghost]
|
||||
|
@ -474,14 +474,10 @@ class Pkg(AbstractPkg):
|
|||
return val
|
||||
|
||||
# return the name of the directory where the package is extracted
|
||||
def dirName(self):
|
||||
def dir_name(self):
|
||||
return self.dirname
|
||||
|
||||
def dir_name(self, dirname, verbose):
|
||||
return self._extract(dirname, verbose)
|
||||
|
||||
# extract rpm contents
|
||||
def _extract(self, dirname, verbose):
|
||||
def _extract_rpm(self, dirname, verbose):
|
||||
if not Path(dirname).is_dir():
|
||||
print_warning('Unable to access dir %s' % dirname)
|
||||
elif dirname == '/':
|
||||
|
@ -508,7 +504,7 @@ class Pkg(AbstractPkg):
|
|||
self.extracted = True
|
||||
return dirname
|
||||
|
||||
def checkSignature(self):
|
||||
def check_signature(self):
|
||||
ret = subprocess.run(('rpm', '-Kv', self.filename),
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
env=ENGLISH_ENVIROMENT)
|
||||
|
@ -534,7 +530,7 @@ class Pkg(AbstractPkg):
|
|||
def read_with_mmap(self, filename):
|
||||
"""Mmap a file, return it's content decoded."""
|
||||
try:
|
||||
with open(Path(self.dirName() or '/', filename.lstrip('/'))) as in_file:
|
||||
with open(Path(self.dir_name() or '/', filename.lstrip('/'))) as in_file:
|
||||
return mmap.mmap(in_file.fileno(), 0, mmap.MAP_SHARED, mmap.PROT_READ).read().decode()
|
||||
except Exception:
|
||||
return ''
|
||||
|
@ -550,8 +546,7 @@ class Pkg(AbstractPkg):
|
|||
return ret
|
||||
|
||||
# extract information about the files
|
||||
def _gatherFilesInfo(self):
|
||||
|
||||
def _gather_files_info(self):
|
||||
ret = {}
|
||||
flags = self.header[rpm.RPMTAG_FILEFLAGS]
|
||||
modes = self.header[rpm.RPMTAG_FILEMODES]
|
||||
|
@ -582,7 +577,7 @@ class Pkg(AbstractPkg):
|
|||
for idx, file in enumerate(files):
|
||||
pkgfile = PkgFile(file)
|
||||
pkgfile.path = os.path.normpath(os.path.join(
|
||||
self.dirName() or '/', pkgfile.name.lstrip('/')))
|
||||
self.dir_name() or '/', pkgfile.name.lstrip('/')))
|
||||
pkgfile.flags = flags[idx]
|
||||
pkgfile.mode = modes[idx]
|
||||
pkgfile.user = byte_to_string(users[idx])
|
||||
|
@ -661,7 +656,7 @@ class Pkg(AbstractPkg):
|
|||
xs.append(DepInfo(name, flags[loop], evr))
|
||||
return xs, prereq
|
||||
|
||||
def _gatherDepInfo(self):
|
||||
def _gather_dep_info(self):
|
||||
_requires = []
|
||||
_prereq = []
|
||||
_provides = []
|
||||
|
@ -726,7 +721,7 @@ class Pkg(AbstractPkg):
|
|||
return prog
|
||||
|
||||
|
||||
def getInstalledPkgs(name):
|
||||
def get_installed_pkgs(name):
|
||||
"""Get list of installed package objects by name."""
|
||||
|
||||
pkgs = []
|
||||
|
@ -765,7 +760,7 @@ class InstalledPkg(Pkg):
|
|||
def cleanup(self):
|
||||
pass
|
||||
|
||||
def checkSignature(self):
|
||||
def check_signature(self):
|
||||
return (0, 'fake: pgp md5 OK')
|
||||
|
||||
|
||||
|
@ -794,7 +789,7 @@ class FakePkg(AbstractPkg):
|
|||
string content.
|
||||
"""
|
||||
basename = name.replace(os.path.sep, '_')
|
||||
path = os.path.join(self.dirName(), basename)
|
||||
path = os.path.join(self.dir_name(), basename)
|
||||
with open(path, 'w') as out:
|
||||
out.write(content)
|
||||
pkg_file = PkgFile(name)
|
||||
|
@ -818,7 +813,7 @@ class FakePkg(AbstractPkg):
|
|||
# HACK: reuse the real Pkg's logic
|
||||
return Pkg.readlink(self, pkgfile)
|
||||
|
||||
def dirName(self):
|
||||
def dir_name(self):
|
||||
if not self.dirname:
|
||||
self.__tmpdir = tempfile.TemporaryDirectory(prefix='rpmlint.%s.' % Path(self.name).name)
|
||||
self.dirname = self.__tmpdir.name
|
||||
|
|
|
@ -5,7 +5,7 @@ import tempfile
|
|||
|
||||
import rpm
|
||||
from rpmlint.helpers import byte_to_string, print_warning
|
||||
from rpmlint.pkg import getInstalledPkgs, Pkg
|
||||
from rpmlint.pkg import get_installed_pkgs, Pkg
|
||||
|
||||
|
||||
class Rpmdiff(object):
|
||||
|
@ -141,7 +141,7 @@ class Rpmdiff(object):
|
|||
return Pkg(name, tmpdir)
|
||||
except TypeError:
|
||||
pass
|
||||
inst = getInstalledPkgs(str(name))
|
||||
inst = get_installed_pkgs(str(name))
|
||||
if not inst:
|
||||
raise KeyError(f'No installed packages by name {name}')
|
||||
if len(inst) > 1:
|
||||
|
|
Loading…
Reference in New Issue