From 39988f97508c13eb9256d4f0df4f16544e700cf5 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 23 Oct 2014 18:03:29 -0400 Subject: [PATCH] Remove spurious decodes (follow-up to RB 1193) Testing Done: Ran test_archive Reviewed at https://rbcommons.com/s/twitter/r/1209/ --- src/python/pants/fs/archive.py | 11 ++++++----- tests/python/pants_test/fs/test_archive.py | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/python/pants/fs/archive.py b/src/python/pants/fs/archive.py index 951d5f8c196..57c59123c01 100644 --- a/src/python/pants/fs/archive.py +++ b/src/python/pants/fs/archive.py @@ -18,6 +18,7 @@ from pants.util.contextutil import open_tar, open_zip from pants.util.dirutil import safe_walk +from pants.util.strutil import ensure_text class Archiver(AbstractClass): @@ -48,9 +49,9 @@ def __init__(self, mode, extension): self.extension = extension def create(self, basedir, outdir, name, prefix=None): - tarpath = os.path.join(outdir, '%s.%s' % (name.decode('utf-8'), self.extension)) + basedir = ensure_text(basedir) + tarpath = os.path.join(outdir, '%s.%s' % (ensure_text(name), self.extension)) with open_tar(tarpath, self.mode, dereference=True, errorlevel=1) as tar: - basedir = basedir.decode('utf-8') tar.add(basedir, arcname=prefix or '.') return tarpath @@ -86,13 +87,13 @@ def create(self, basedir, outdir, name, prefix=None): zippath = os.path.join(outdir, '%s.zip' % name) with open_zip(zippath, 'w', compression=ZIP_DEFLATED) as zip: for root, _, files in safe_walk(basedir): - root = root.decode('utf-8') + root = ensure_text(root) for file in files: - file = file.decode('utf-8') + file = ensure_text(file) full_path = os.path.join(root, file) relpath = os.path.relpath(full_path, basedir) if prefix: - relpath = os.path.join(prefix.decode('utf-8'), relpath) + relpath = os.path.join(ensure_text(prefix), relpath) zip.write(full_path, relpath) return zippath diff --git a/tests/python/pants_test/fs/test_archive.py b/tests/python/pants_test/fs/test_archive.py index 7376c938460..7fb5a43f61b 100644 --- a/tests/python/pants_test/fs/test_archive.py +++ b/tests/python/pants_test/fs/test_archive.py @@ -17,10 +17,10 @@ class ArchiveTest(unittest.TestCase): def _listtree(self, root, empty_dirs): listing = set() for path, dirs, files in safe_walk(root): - relpath = os.path.normpath(os.path.relpath(path, root)).decode('utf-8') + relpath = os.path.normpath(os.path.relpath(path, root)) if empty_dirs: - listing.update(os.path.normpath(os.path.join(relpath, d.decode('utf-8'))) for d in dirs) - listing.update(os.path.normpath(os.path.join(relpath, f.decode('utf-8'))) for f in files) + listing.update(os.path.normpath(os.path.join(relpath, d)) for d in dirs) + listing.update(os.path.normpath(os.path.join(relpath, f)) for f in files) return listing def round_trip(self, archiver, empty_dirs):