Set english locale for subprocess runs. Fixes #415

This commit is contained in:
Tomáš Chvátal 2020-04-01 09:50:56 +02:00 committed by Tomáš Chvátal
parent 91a23456c6
commit 4396a99585
13 changed files with 40 additions and 24 deletions

View File

@ -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:

View File

@ -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):

View File

@ -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)

View File

@ -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]

View File

@ -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

View File

@ -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)

View File

@ -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]

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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