[Reproducible-commits] [debbindiff] 01/03: Normalize locale env. vars and always use UTF-8
Jérémy Bobbio
lunar at moszumanska.debian.org
Mon Mar 23 21:08:13 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository debbindiff.
commit 0268c3d25e8bf1e33180e9d357f1cfb79f3a152a
Author: Jérémy Bobbio <lunar at debian.org>
Date: Mon Mar 23 21:39:52 2015 +0100
Normalize locale env. vars and always use UTF-8
---
debbindiff.py | 16 ++++++++++++++++
debbindiff/comparators/cpio.py | 3 +--
debbindiff/comparators/directory.py | 9 ++++-----
debbindiff/comparators/gettext.py | 3 +--
debbindiff/comparators/gzip.py | 3 +--
debbindiff/comparators/pdf.py | 3 +--
debbindiff/comparators/png.py | 3 +--
debbindiff/comparators/squashfs.py | 5 ++---
debbindiff/comparators/zip.py | 3 +--
9 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/debbindiff.py b/debbindiff.py
index f02ebbb..a4141bd 100755
--- a/debbindiff.py
+++ b/debbindiff.py
@@ -23,6 +23,7 @@ from __future__ import print_function
import argparse
from contextlib import contextmanager
import logging
+import os
import sys
import traceback
from debbindiff import logger, VERSION
@@ -80,11 +81,26 @@ class ListToolsAction(argparse.Action):
sys.exit(0)
+def set_locale():
+ """Normalize locale so external tool gives us stable and properly
+ encoded output"""
+
+ for var in ['LANGUAGE', 'LC_ALL']:
+ if var in os.environ:
+ del os.environ[var]
+ for var in ['LANG', 'LC_NUMERIC', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY',
+ 'LC_MESSAGES', 'LC_PAPER', 'LC_NAME', 'LC_ADDRESS',
+ 'LC_TELEPHONE', 'LC_MEASUREMENT', 'LC_IDENTIFICATION']:
+ os.environ[var] = 'C'
+ os.environ['LC_CTYPE'] = 'C.UTF-8'
+
+
def main():
parser = create_parser()
parsed_args = parser.parse_args(sys.argv[1:])
if parsed_args.debug:
logger.setLevel(logging.DEBUG)
+ set_locale()
differences = debbindiff.comparators.compare_files(
parsed_args.file1, parsed_args.file2)
if len(differences) > 0:
diff --git a/debbindiff/comparators/cpio.py b/debbindiff/comparators/cpio.py
index 754d723..3132577 100644
--- a/debbindiff/comparators/cpio.py
+++ b/debbindiff/comparators/cpio.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
-import locale
import subprocess
import os.path
import debbindiff.comparators
@@ -31,7 +30,7 @@ def get_cpio_content(path, verbose=False):
cmd = ['cpio', '--quiet', '-tF', path]
if verbose:
cmd = ['cpio', '-tvF', path]
- return subprocess.check_output(cmd, stderr=subprocess.PIPE, shell=False).decode(locale.getpreferredencoding())
+ return subprocess.check_output(cmd, stderr=subprocess.PIPE, shell=False).decode('utf-8')
@tool_required('cpio')
diff --git a/debbindiff/comparators/directory.py b/debbindiff/comparators/directory.py
index 976dae3..fd7fe54 100644
--- a/debbindiff/comparators/directory.py
+++ b/debbindiff/comparators/directory.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
-import locale
import os.path
import re
import subprocess
@@ -28,12 +27,12 @@ import debbindiff.comparators
def ls(path):
- return subprocess.check_output(['ls', path], shell=False).decode(locale.getpreferredencoding())
+ return subprocess.check_output(['ls', path], shell=False).decode('utf-8')
@tool_required('stat')
def stat(path):
- output = subprocess.check_output(['stat', path], shell=False).decode(locale.getpreferredencoding())
+ output = subprocess.check_output(['stat', path], shell=False).decode('utf-8')
output = re.sub(r'^\s*File:.*$', '', output, flags=re.MULTILINE)
output = re.sub(r'Inode: [0-9]+', '', output)
return output
@@ -42,7 +41,7 @@ def stat(path):
@tool_required('lsattr')
def lsattr(path):
try:
- output = subprocess.check_output(['lsattr', '-d', path], shell=False, stderr=subprocess.STDOUT).decode(locale.getpreferredencoding())
+ output = subprocess.check_output(['lsattr', '-d', path], shell=False, stderr=subprocess.STDOUT).decode('utf-8')
return output.split()[0]
except subprocess.CalledProcessError as e:
if e.returncode == 1:
@@ -52,7 +51,7 @@ def lsattr(path):
@tool_required('getfacl')
def getfacl(path):
- return subprocess.check_output(['getfacl', '-p', '-c', path], shell=False).decode(locale.getpreferredencoding())
+ return subprocess.check_output(['getfacl', '-p', '-c', path], shell=False).decode('utf-8')
def compare_meta(path1, path2):
diff --git a/debbindiff/comparators/gettext.py b/debbindiff/comparators/gettext.py
index 0b477d1..20400ea 100644
--- a/debbindiff/comparators/gettext.py
+++ b/debbindiff/comparators/gettext.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
-import locale
import subprocess
from debbindiff.comparators.utils import binary_fallback, tool_required
from debbindiff.difference import Difference
@@ -25,7 +24,7 @@ from debbindiff.difference import Difference
@tool_required('msgunfmt')
def msgunfmt(path):
- return subprocess.check_output(['msgunfmt', path], shell=False).decode(locale.getpreferredencoding())
+ return subprocess.check_output(['msgunfmt', path], shell=False).decode('utf-8')
@binary_fallback
diff --git a/debbindiff/comparators/gzip.py b/debbindiff/comparators/gzip.py
index 6eb990c..6272864 100644
--- a/debbindiff/comparators/gzip.py
+++ b/debbindiff/comparators/gzip.py
@@ -18,7 +18,6 @@
# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
from contextlib import contextmanager
-import locale
import subprocess
import os.path
import debbindiff.comparators
@@ -43,7 +42,7 @@ def decompress_gzip(path):
@tool_required('file')
def get_gzip_metadata(path):
- return subprocess.check_output(['file', '--brief', path]).decode(locale.getpreferredencoding())
+ return subprocess.check_output(['file', '--brief', path]).decode('utf-8')
@binary_fallback
diff --git a/debbindiff/comparators/pdf.py b/debbindiff/comparators/pdf.py
index 195fd82..8add5f2 100644
--- a/debbindiff/comparators/pdf.py
+++ b/debbindiff/comparators/pdf.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
-import locale
import subprocess
from debbindiff.comparators.utils import binary_fallback, tool_required
from debbindiff.difference import Difference, get_source
@@ -35,7 +34,7 @@ def uncompress(path):
def pdftotext(path):
return subprocess.check_output(
['pdftotext', path, '-'],
- shell=False, close_fds=True).decode(locale.getpreferredencoding())
+ shell=False, close_fds=True).decode('utf-8')
@binary_fallback
diff --git a/debbindiff/comparators/png.py b/debbindiff/comparators/png.py
index 214fa7b..85e630b 100644
--- a/debbindiff/comparators/png.py
+++ b/debbindiff/comparators/png.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
-import locale
import subprocess
from debbindiff.comparators.utils import binary_fallback, tool_required
from debbindiff.difference import Difference
@@ -32,7 +31,7 @@ def sng(path):
p.wait()
if p.returncode != 0:
return 'sng exited with error %d\n%s' % (p.returncode, err)
- return out.decode(locale.getpreferredencoding())
+ return out.decode('utf-8')
@binary_fallback
def compare_png_files(path1, path2, source=None):
diff --git a/debbindiff/comparators/squashfs.py b/debbindiff/comparators/squashfs.py
index 3896125..cee7c47 100644
--- a/debbindiff/comparators/squashfs.py
+++ b/debbindiff/comparators/squashfs.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
-import locale
import subprocess
import os.path
import debbindiff.comparators
@@ -33,10 +32,10 @@ def get_squashfs_content(path, verbose=True):
if verbose:
# first get superblock information
cmd = ['unsquashfs', '-s', path]
- content = subprocess.check_output(cmd, shell=False).decode(locale.getpreferredencoding())
+ content = subprocess.check_output(cmd, shell=False).decode('utf-8')
# and then the verbose file listing
cmd = ['unsquashfs', '-d', '', '-lls', path]
- return content + subprocess.check_output(cmd, shell=False).decode(locale.getpreferredencoding())
+ return content + subprocess.check_output(cmd, shell=False).decode('utf-8')
@tool_required('unsquashfs')
diff --git a/debbindiff/comparators/zip.py b/debbindiff/comparators/zip.py
index c892da0..dc08d67 100644
--- a/debbindiff/comparators/zip.py
+++ b/debbindiff/comparators/zip.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
-import locale
import os.path
import re
import subprocess
@@ -34,7 +33,7 @@ def get_zipinfo(path, verbose=False):
cmd = ['zipinfo', '-v', path]
else:
cmd = ['zipinfo', path]
- output = subprocess.check_output(cmd, shell=False).decode(locale.getpreferredencoding())
+ output = subprocess.check_output(cmd, shell=False).decode('utf-8')
# the full path appears in the output, we need to remove it
return re.sub(re.escape(path), os.path.basename(path), output)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debbindiff.git
More information about the Reproducible-commits
mailing list