Commit aa0bf7e0 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

downloadunpacked: support .xz and .lz archives.

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,6 +102,19 @@ class Recipe:
self.logger.debug('Created working directory %r' % extract_dir)
try:
patch_archive_util()
# 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()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment