Commit aa0bf7e0 by Kazuhiko Shiozaki

downloadunpacked: support .xz and .lz archives.

1 parent e3e15b9f
......@@ -27,6 +27,7 @@
import os
import logging
import shutil
import subprocess
import tarfile
import zc.buildout
import tempfile
......@@ -70,6 +71,24 @@ class Recipe:
options['target'] = self.destination
options.setdefault('extract-directory', '')
self.environ = {}
self.original_environment = os.environ.copy()
environment_section = self.options.get('environment-section', '').strip()
if environment_section and environment_section in buildout:
# Use environment variables from the designated config section.
self.environ.update(buildout[environment_section])
for variable in self.options.get('environment', '').splitlines():
if variable.strip():
try:
key, value = variable.split('=', 1)
self.environ[key.strip()] = value
except ValueError:
raise zc.buildout.UserError('Invalid environment variable definition: %s', variable)
# Extrapolate the environment variables using values from the current
# environment.
for key in self.environ:
self.environ[key] = self.environ[key] % os.environ
def install(self):
if self.parts is not None:
if not os.path.isdir(self.parts):
......@@ -83,7 +102,20 @@ class Recipe:
self.logger.debug('Created working directory %r' % extract_dir)
try:
patch_archive_util()
setuptools.archive_util.unpack_archive(path, extract_dir)
# ad-hoc support for .xz and .lz archive
hdr = file(path).read(6)
if hdr == '\xfd7zXZ\x00':
new_path = os.path.join(extract_dir, os.path.basename(path))
file(new_path, 'w').write(subprocess.check_output(['xzcat', path], env=self.environ))
setuptools.archive_util.unpack_archive(new_path, extract_dir)
os.unlink(new_path)
elif hdr.startswith('LZIP'):
new_path = os.path.join(extract_dir, os.path.basename(path))
file(new_path, 'w').write(subprocess.check_output(['lunzip', '-c', path], env=self.environ))
setuptools.archive_util.unpack_archive(new_path, extract_dir)
os.unlink(new_path)
else:
setuptools.archive_util.unpack_archive(path, extract_dir)
finally:
unpatch_archive_util()
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!