diff --git a/rpmlint/checks/AppDataCheck.py b/rpmlint/checks/AppDataCheck.py index f8eb421f..98bc3a63 100644 --- a/rpmlint/checks/AppDataCheck.py +++ b/rpmlint/checks/AppDataCheck.py @@ -2,6 +2,7 @@ import subprocess from xml.etree import ElementTree from rpmlint.checks.AbstractCheck import AbstractFilesCheck +from rpmlint.helpers import ENGLISH_ENVIROMENT class AppDataCheck(AbstractFilesCheck): @@ -22,7 +23,7 @@ class AppDataCheck(AbstractFilesCheck): validation_failed = False try: - r = subprocess.run(cmd.split()) + r = subprocess.run(cmd.split(), env=ENGLISH_ENVIROMENT) if r.returncode != 0: validation_failed = True except FileNotFoundError: diff --git a/rpmlint/checks/BashismsCheck.py b/rpmlint/checks/BashismsCheck.py index b910fffe..2f8a828d 100644 --- a/rpmlint/checks/BashismsCheck.py +++ b/rpmlint/checks/BashismsCheck.py @@ -2,6 +2,7 @@ import stat import subprocess from rpmlint.checks.AbstractCheck import AbstractFilesCheck +from rpmlint.helpers import ENGLISH_ENVIROMENT class BashismsCheck(AbstractFilesCheck): @@ -28,14 +29,14 @@ class BashismsCheck(AbstractFilesCheck): potential bash issues. """ try: - r = subprocess.run(['dash', '-n', filepath]) + r = subprocess.run(['dash', '-n', filepath], env=ENGLISH_ENVIROMENT) if r.returncode == 2: self.output.add_info('W', pkg, 'bin-sh-syntax-error', filename) except (FileNotFoundError, UnicodeDecodeError): pass try: - r = subprocess.run(['checkbashisms', filepath]) + r = subprocess.run(['checkbashisms', filepath], env=ENGLISH_ENVIROMENT) if r.returncode == 1: self.output.add_info('W', pkg, 'potential-bashisms', filename) except (FileNotFoundError, UnicodeDecodeError): diff --git a/rpmlint/checks/FilesCheck.py b/rpmlint/checks/FilesCheck.py index 04fd919e..d5ec553d 100644 --- a/rpmlint/checks/FilesCheck.py +++ b/rpmlint/checks/FilesCheck.py @@ -17,7 +17,7 @@ import subprocess import rpm from rpmlint.checks.AbstractCheck import AbstractCheck -from rpmlint.helpers import byte_to_string +from rpmlint.helpers import byte_to_string, ENGLISH_ENVIROMENT from rpmlint.pkg import catcmd, is_utf8, is_utf8_bytestr # must be kept in sync with the filesystem package @@ -850,7 +850,7 @@ class FilesCheck(AbstractCheck): (catcmd(f), quote(pkgfile.path), quote(self.man_warn_category), os.devnull), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - env=dict(os.environ, LC_ALL='en_US.UTF-8')) + env=ENGLISH_ENVIROMENT) for line in command.stdout.decode().split('\n'): res = man_warn_regex.search(line) diff --git a/rpmlint/checks/MenuCheck.py b/rpmlint/checks/MenuCheck.py index 1392de5b..191d80ce 100644 --- a/rpmlint/checks/MenuCheck.py +++ b/rpmlint/checks/MenuCheck.py @@ -12,6 +12,7 @@ import subprocess import rpm from rpmlint.checks.AbstractCheck import AbstractCheck +from rpmlint.helpers import ENGLISH_ENVIROMENT menu_file_regex = re.compile(r'^/usr/lib/menu/([^/]+)$') @@ -95,7 +96,7 @@ class MenuCheck(AbstractCheck): directory = pkg.dirName() for f in menus: # remove comments and handle cpp continuation lines - text = subprocess.run(('/lib/cpp', directory + f), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode() + text = subprocess.run(('/lib/cpp', directory + f), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=ENGLISH_ENVIROMENT).stdout.decode() if text.endswith('\n'): text = text[:-1] diff --git a/rpmlint/checks/MenuXDGCheck.py b/rpmlint/checks/MenuXDGCheck.py index 536f559c..c679a951 100644 --- a/rpmlint/checks/MenuXDGCheck.py +++ b/rpmlint/checks/MenuXDGCheck.py @@ -11,6 +11,7 @@ from pathlib import Path import subprocess from rpmlint.checks.AbstractCheck import AbstractFilesCheck +from rpmlint.helpers import ENGLISH_ENVIROMENT STANDARD_BIN_DIRS = ('/bin', '/sbin', '/usr/bin', '/usr/sbin') @@ -43,7 +44,7 @@ class MenuXDGCheck(AbstractFilesCheck): def check_file(self, pkg, filename): root = pkg.dirName() f = root + filename - command = subprocess.run(('desktop-file-validate', f), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + command = subprocess.run(('desktop-file-validate', f), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=ENGLISH_ENVIROMENT) text = command.stdout.decode() if command.returncode: error_printed = False diff --git a/rpmlint/checks/PostCheck.py b/rpmlint/checks/PostCheck.py index 449d2c14..7b94e965 100644 --- a/rpmlint/checks/PostCheck.py +++ b/rpmlint/checks/PostCheck.py @@ -15,7 +15,7 @@ import tempfile import rpm from rpmlint import pkg as Pkg from rpmlint.checks.AbstractCheck import AbstractCheck -from rpmlint.helpers import byte_to_string +from rpmlint.helpers import byte_to_string, ENGLISH_ENVIROMENT # shells that grok the -n switch for debugging @@ -63,7 +63,7 @@ def check_syntax_script(prog, commandline, script): try: tmpfile.write(script) tmpfile.close() - ret = subprocess.run((prog, commandline, tmpname)) + ret = subprocess.run((prog, commandline, tmpname), env=ENGLISH_ENVIROMENT) finally: tmpfile.close() os.remove(tmpname) diff --git a/rpmlint/checks/SpecCheck.py b/rpmlint/checks/SpecCheck.py index 9547d443..dcc3dfc5 100644 --- a/rpmlint/checks/SpecCheck.py +++ b/rpmlint/checks/SpecCheck.py @@ -14,7 +14,7 @@ from urllib.parse import urlparse import rpm from rpmlint import pkg as Pkg from rpmlint.checks.AbstractCheck import AbstractCheck -from rpmlint.helpers import readlines +from rpmlint.helpers import ENGLISH_ENVIROMENT, readlines # Don't check for hardcoded library paths in biarch packages DEFAULT_BIARCH_PACKAGES = '^(gcc|glibc)' @@ -563,7 +563,7 @@ class SpecCheck(AbstractCheck): # capture and print them nicely, so we do it once each way :P outcmd = subprocess.run( - ('rpm', '-q', '--qf=', '-D', '_sourcedir %s' % Path(self._spec_file).parent, '--specfile', self._spec_file), stdout=subprocess.PIPE) + ('rpm', '-q', '--qf=', '-D', '_sourcedir %s' % Path(self._spec_file).parent, '--specfile', self._spec_file), stdout=subprocess.PIPE, env=ENGLISH_ENVIROMENT) text = outcmd.stdout.decode() if text.endswith('\n'): text = text[:-1] diff --git a/rpmlint/helpers.py b/rpmlint/helpers.py index 086e395d..d4a6a3ec 100644 --- a/rpmlint/helpers.py +++ b/rpmlint/helpers.py @@ -1,11 +1,15 @@ # File containing various helper functions used across rpmlint +import os from shutil import get_terminal_size import sys from rpmlint.color import Color +ENGLISH_ENVIROMENT = dict(os.environ, LC_ALL='en_US') + + def string_center(message, filler=' '): """ Create string centered of the terminal diff --git a/rpmlint/lddparser.py b/rpmlint/lddparser.py index 99d47545..597155de 100644 --- a/rpmlint/lddparser.py +++ b/rpmlint/lddparser.py @@ -1,6 +1,8 @@ import re import subprocess +from rpmlint.helpers import ENGLISH_ENVIROMENT + class LddParser: """ @@ -47,7 +49,7 @@ class LddParser: def parse_dependencies(self): r = subprocess.run(['ldd', '-u', self.pkgfile_path], encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) if r.returncode == 0: return @@ -65,7 +67,7 @@ class LddParser: def parse_undefined_symbols(self): r = subprocess.run(['ldd', '-r', self.pkgfile_path], encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) # here ldd should always return 0 if r.returncode != 0: self.parsing_failed_reason = r.stderr @@ -82,7 +84,7 @@ class LddParser: # run c++filt demangler for all collected symbols if self.undefined_symbols: r = subprocess.run(['c++filt'] + self.undefined_symbols, encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) if r.returncode != 0: self.parsing_failed_reason = r.stderr else: diff --git a/rpmlint/objdumpparser.py b/rpmlint/objdumpparser.py index 07616833..738d228c 100644 --- a/rpmlint/objdumpparser.py +++ b/rpmlint/objdumpparser.py @@ -1,5 +1,7 @@ import subprocess +from rpmlint.helpers import ENGLISH_ENVIROMENT + class ObjdumpParser: """ @@ -30,7 +32,7 @@ class ObjdumpParser: def parse_dwarf_compilation_units(self): r = subprocess.run(['objdump', '--dwarf=info', '--dwarf-depth=1', self.pkgfile_path], encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) # here ldd should always return 0 if r.returncode != 0: self.parsing_failed_reason = r.stderr diff --git a/rpmlint/pkg.py b/rpmlint/pkg.py index 7c7df56d..efc149f5 100644 --- a/rpmlint/pkg.py +++ b/rpmlint/pkg.py @@ -20,7 +20,7 @@ try: except ImportError: _magic = None import rpm -from rpmlint.helpers import byte_to_string, print_warning +from rpmlint.helpers import byte_to_string, ENGLISH_ENVIROMENT, print_warning from rpmlint.pkgfile import PkgFile @@ -471,12 +471,12 @@ class Pkg(AbstractPkg): command_str = \ 'rpm2cpio %(f)s | cpio -id -D %(d)s ; chmod -R +rX %(d)s' % \ {'f': quote(str(self.filename)), 'd': quote(dirname)} - subprocess.run(command_str, shell=True) + subprocess.run(command_str, shell=True, env=ENGLISH_ENVIROMENT) self.extracted = True return dirname def checkSignature(self): - ret = subprocess.run(('rpm', '-K', self.filename), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + ret = subprocess.run(('rpm', '-K', self.filename), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=ENGLISH_ENVIROMENT) text = ret.stdout.decode() if text.endswith('\n'): text = text[:-1] diff --git a/rpmlint/readelfparser.py b/rpmlint/readelfparser.py index 957b02b4..1139df06 100644 --- a/rpmlint/readelfparser.py +++ b/rpmlint/readelfparser.py @@ -2,6 +2,8 @@ from itertools import dropwhile, takewhile import re import subprocess +from rpmlint.helpers import ENGLISH_ENVIROMENT + class ElfSection: """ @@ -83,7 +85,7 @@ class ElfSectionInfo: def parse(self): r = subprocess.run(['readelf', '-W', '-S', self.path], encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) if r.returncode != 0: self.parsing_failed_reason = r.stderr return @@ -142,7 +144,7 @@ class ElfProgramHeaderInfo: def parse(self): r = subprocess.run(['readelf', '-W', '-l', self.path], encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) if r.returncode != 0: self.parsing_failed_reason = r.stderr return @@ -210,7 +212,7 @@ class ElfDynamicSectionInfo: def parse(self): r = subprocess.run(['readelf', '-W', '-d', self.path], encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) if r.returncode != 0: self.parsing_failed_reason = r.stderr return @@ -268,7 +270,7 @@ class ElfSymbolTableInfo: def parse(self): r = subprocess.run(['readelf', '-W', '-s', self.path], encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) if r.returncode != 0: self.parsing_failed_reason = r.stderr return @@ -302,7 +304,7 @@ class ElfCommentInfo: def parse(self): r = subprocess.run(['readelf', '-p', '.comment', self.path], encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) if r.returncode != 0: self.parsing_failed_reason = r.stderr return diff --git a/rpmlint/stringsparser.py b/rpmlint/stringsparser.py index 52b60405..b2c95498 100644 --- a/rpmlint/stringsparser.py +++ b/rpmlint/stringsparser.py @@ -1,5 +1,7 @@ import subprocess +from rpmlint.helpers import ENGLISH_ENVIROMENT + class StringsParser: """ @@ -14,7 +16,7 @@ class StringsParser: def parse(self): r = subprocess.run(['strings', self.pkgfile_path], encoding='utf8', - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT) if r.returncode != 0: self.parsing_failed_reason = r.stderr return