Skip to content

Commit

Permalink
Merge branch '1.0.x' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Apr 10, 2017
2 parents c8be408 + 1770495 commit a864447
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 40 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
[![Coverage Status](https://codecov.io/github/ViDA-NYU/reprozip/coverage.svg?branch=master)](https://codecov.io/github/ViDA-NYU/reprozip?branch=master)
[![Code Health](https://landscape.io/github/ViDA-NYU/reprozip/master/landscape.png)](https://landscape.io/github/ViDA-NYU/reprozip/master)
[![Documentation Status](https://readthedocs.org/projects/reprozip/badge/?version=latest)](https://docs.reprozip.org/en/latest/)
[![Matrix](https://img.shields.io/badge/chat-matrix.org-brightgreen.svg)](https://riot.im/app/#/room/#reprozip:matrix.org)
[![status](http://joss.theoj.org/papers/b578b171263c73f64dfb9d040ca80fe0/status.svg)](http://joss.theoj.org/papers/b578b171263c73f64dfb9d040ca80fe0)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.60654.svg)](https://doi.org/10.5281/zenodo.60654)
[![Matrix](https://img.shields.io/badge/chat-matrix.org-blue.svg)](https://riot.im/app/#/room/#reprozip:matrix.org)
[![status](https://img.shields.io/badge/JOSS-10.21105%2Fjoss.00107-green.svg)](http://joss.theoj.org/papers/b578b171263c73f64dfb9d040ca80fe0)
[![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.237968-green.svg)](https://doi.org/10.5281/zenodo.237968)

ReproZip
========
Expand Down
58 changes: 37 additions & 21 deletions reprounzip-docker/reprounzip/unpackers/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def docker_setup_build(args):

logging.info("Calling 'docker build'...")
try:
retcode = subprocess.call(['docker', 'build', '-t'] +
retcode = subprocess.call(args.docker_cmd.split() + ['build', '-t'] +
args.docker_option + [image, '.'],
cwd=target.path)
except OSError:
Expand Down Expand Up @@ -309,7 +309,7 @@ def docker_reset(args):
"reset")
else:
logging.info("Removing image %s", image.decode('ascii'))
retcode = subprocess.call(['docker', 'rmi', image])
retcode = subprocess.call(args.docker_cmd.split() + ['rmi', image])
if retcode != 0:
logging.warning("Can't remove previous image, docker returned %d",
retcode)
Expand Down Expand Up @@ -477,7 +477,8 @@ def docker_run(args):
if args.detach:
logging.info("Start container %s (detached)",
container.decode('ascii'))
retcode = interruptible_call(['docker', 'run', b'--name=' + container,
retcode = interruptible_call(args.docker_cmd.split() +
['run', b'--name=' + container,
'-h', hostname,
'-d', '-t'] +
args.docker_option +
Expand All @@ -490,7 +491,8 @@ def docker_run(args):

# Run command in container
logging.info("Starting container %s", container.decode('ascii'))
retcode = interruptible_call(['docker', 'run', b'--name=' + container,
retcode = interruptible_call(args.docker_cmd.split() +
['run', b'--name=' + container,
'-h', hostname,
'-i', '-t'] +
args.docker_option +
Expand All @@ -501,7 +503,8 @@ def docker_run(args):
sys.exit(1)

# Get exit status from "docker inspect"
out = subprocess.check_output(['docker', 'inspect', container])
out = subprocess.check_output(args.docker_cmd.split() +
['inspect', container])
outjson = json.loads(out.decode('ascii'))
if (outjson[0]["State"]["Running"] is not False or
outjson[0]["State"]["Paused"] is not False):
Expand All @@ -514,22 +517,23 @@ def docker_run(args):
new_image = make_unique_name(b'reprounzip_image_')
logging.info("Committing container %s to image %s",
container.decode('ascii'), new_image.decode('ascii'))
subprocess.check_call(['docker', 'commit', container, new_image])
subprocess.check_call(args.docker_cmd.split() +
['commit', container, new_image])

# Update image name
unpacked_info['current_image'] = new_image
write_dict(target, unpacked_info)

# Remove the container
logging.info("Destroying container %s", container.decode('ascii'))
retcode = subprocess.call(['docker', 'rm', container])
retcode = subprocess.call(args.docker_cmd.split() + ['rm', container])
if retcode != 0:
logging.error("Error deleting container %s", container.decode('ascii'))

# Untag previous image, unless it is the initial_image
if image != unpacked_info['initial_image']:
logging.info("Untagging previous image %s", image.decode('ascii'))
subprocess.check_call(['docker', 'rmi', image])
subprocess.check_call(args.docker_cmd.split() + ['rmi', image])

# Update input file status
metadata_update_run(config, unpacked_info, selected_runs)
Expand All @@ -539,8 +543,10 @@ def docker_run(args):


class ContainerUploader(FileUploader):
def __init__(self, target, input_files, files, unpacked_info):
def __init__(self, target, input_files, files, unpacked_info,
docker_cmd='docker'):
self.unpacked_info = unpacked_info
self.docker_cmd = docker_cmd
FileUploader.__init__(self, target, input_files, files)

def prepare_upload(self, files):
Expand Down Expand Up @@ -591,7 +597,8 @@ def finalize(self):
# TODO : restore permissions?

image = make_unique_name(b'reprounzip_image_')
retcode = subprocess.call(['docker', 'build', '-t', image, '.'],
retcode = subprocess.call(self.docker_cmd +
['build', '-t', image, '.'],
cwd=self.build_directory.path)
if retcode != 0:
logging.critical("docker build failed with code %d", retcode)
Expand All @@ -601,7 +608,8 @@ def finalize(self):
if from_image != self.unpacked_info['initial_image']:
logging.info("Untagging previous image %s",
from_image.decode('ascii'))
retcode = subprocess.call(['docker', 'rmi', from_image])
retcode = subprocess.call(self.docker_cmd +
['rmi', from_image])
if retcode != 0:
logging.warning("Can't remove previous image, docker "
"returned %d", retcode)
Expand All @@ -621,21 +629,24 @@ def docker_upload(args):
input_files = unpacked_info.setdefault('input_files', {})

try:
ContainerUploader(target, input_files, files, unpacked_info)
ContainerUploader(target, input_files, files, unpacked_info,
docker_cmd=args.docker_cmd.split())
finally:
write_dict(target, unpacked_info)


class ContainerDownloader(FileDownloader):
def __init__(self, target, files, image, all_=False):
def __init__(self, target, files, image, all_=False, docker_cmd='docker'):
self.image = image
self.docker_cmd = docker_cmd
FileDownloader.__init__(self, target, files, all_=all_)

def prepare_download(self, files):
# Create a container from the image
self.container = make_unique_name(b'reprounzip_dl_')
logging.info("Creating container %s", self.container.decode('ascii'))
subprocess.check_call(['docker', 'create',
subprocess.check_call(self.docker_cmd +
['create',
b'--name=' + self.container,
self.image])

Expand All @@ -644,9 +655,10 @@ def download(self, remote_path, local_path):
# a file name (#4272)
tmpdir = Path.tempdir(prefix='reprozip_docker_output_')
try:
ret = subprocess.call(['docker', 'cp',
self.container + b':' + remote_path.path,
tmpdir.path])
ret = subprocess.call(self.docker_cmd +
['cp',
self.container + b':' + remote_path.path,
tmpdir.path])
if ret != 0:
logging.critical("Can't get output file: %s", remote_path)
return False
Expand All @@ -657,7 +669,7 @@ def download(self, remote_path, local_path):

def finalize(self):
logging.info("Removing container %s", self.container.decode('ascii'))
retcode = subprocess.call(['docker', 'rm', self.container])
retcode = subprocess.call(self.docker_cmd + ['rm', self.container])
if retcode != 0:
logging.warning("Can't remove temporary container, docker "
"returned %d", retcode)
Expand All @@ -677,7 +689,8 @@ def docker_download(args):
image = unpacked_info['current_image']
logging.debug("Downloading from image %s", image.decode('ascii'))

ContainerDownloader(target, files, image, all_=args.all)
ContainerDownloader(target, files, image,
all_=args.all, docker_cmd=args.docker_cmd.split())


@target_must_exist
Expand All @@ -696,12 +709,12 @@ def docker_destroy_docker(args):
image = unpacked_info.pop('current_image')
if image != initial_image:
logging.info("Destroying image %s...", image.decode('ascii'))
retcode = subprocess.call(['docker', 'rmi', image])
retcode = subprocess.call(args.docker_cmd.split() + ['rmi', image])
if retcode != 0:
logging.error("Error deleting image %s", image.decode('ascii'))

logging.info("Destroying image %s...", initial_image.decode('ascii'))
retcode = subprocess.call(['docker', 'rmi', initial_image])
retcode = subprocess.call(args.docker_cmd.split() + ['rmi', initial_image])
if retcode != 0:
logging.error("Error deleting image %s", initial_image.decode('ascii'))

Expand Down Expand Up @@ -767,6 +780,9 @@ def setup(parser, **kwargs):
output_id:filename extracts the output file to the corresponding local
path
"""
parser.add_argument('--docker-cmd', action='store', default='docker',
help="Change the Docker command; split on spaces")

subparsers = parser.add_subparsers(title="actions",
metavar='', help=argparse.SUPPRESS)

Expand Down
1 change: 1 addition & 0 deletions reprounzip-qt/reprounzip_qt/reprounzip_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def shell_escape(s):
if not s or any(c not in safe_shell_chars for c in s):
return '"%s"' % (s.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('`', '\\`')
.replace('$', '\\$'))
else:
return s
Expand Down
2 changes: 1 addition & 1 deletion reprounzip/reprounzip/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ def save_config(filename, runs, packages, other_files, reprozip_version,
# If you want to include additional files in the pack, you can list additional
# patterns of files that will be included
additional_patterns:
# Example:
#additional_patterns:
# - /etc/apache2/** # Everything under apache2/
# - /var/log/apache2/*.log # Log files directly under apache2/
# - /var/lib/lxc/*/rootfs/home/**/*.py # All Python files of all users in
Expand Down
1 change: 1 addition & 0 deletions reprounzip/reprounzip/unpackers/common/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def shell_escape(s):
if not s or any(c not in safe_shell_chars for c in s):
return '"%s"' % (s.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('`', '\\`')
.replace('$', '\\$'))
else:
return s
Expand Down
6 changes: 3 additions & 3 deletions reprounzip/reprounzip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __getattr__(self, name,
stdout, stderr = sys.stdout, sys.stderr
else:
izip = itertools.izip
irange = xrange
irange = xrange # noqa: F821
iteritems = dict.iteritems
itervalues = dict.itervalues
listvalues = dict.values
Expand All @@ -83,8 +83,8 @@ def __getattr__(self, name,
int_types = int,
unicode_ = str
else:
int_types = int, long
unicode_ = unicode
int_types = int, long # noqa: F821
unicode_ = unicode # noqa: F821


def flatten(n, l):
Expand Down
2 changes: 1 addition & 1 deletion reprozip/reprozip/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ def save_config(filename, runs, packages, other_files, reprozip_version,
# If you want to include additional files in the pack, you can list additional
# patterns of files that will be included
additional_patterns:
# Example:
#additional_patterns:
# - /etc/apache2/** # Everything under apache2/
# - /var/log/apache2/*.log # Log files directly under apache2/
# - /var/lib/lxc/*/rootfs/home/**/*.py # All Python files of all users in
Expand Down
1 change: 1 addition & 0 deletions reprozip/reprozip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def shell_escape(s):
if not s or any(c not in safe_shell_chars for c in s):
return '"%s"' % (s.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('`', '\\`')
.replace('$', '\\$'))
else:
return s
Expand Down
17 changes: 9 additions & 8 deletions reprozip/reprozip/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ def canonicalize_config(packages, other_files, additional_patterns,
sort_packages):
"""Expands ``additional_patterns`` from the configuration file.
"""
add_files = expand_patterns(additional_patterns)
if add_files:
if additional_patterns:
add_files = expand_patterns(additional_patterns)
logging.info("Found %d files from expanding additional_patterns...",
len(add_files))
if sort_packages:
add_files, add_packages = identify_packages(add_files)
else:
add_packages = []
other_files, packages = combine_files(add_files, add_packages,
other_files, packages)
if add_files:
if sort_packages:
add_files, add_packages = identify_packages(add_files)
else:
add_packages = []
other_files, packages = combine_files(add_files, add_packages,
other_files, packages)
return packages, other_files


Expand Down
6 changes: 3 additions & 3 deletions reprozip/reprozip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __getattr__(self, name,
stdout, stderr = sys.stdout, sys.stderr
else:
izip = itertools.izip
irange = xrange
irange = xrange # noqa: F821
iteritems = dict.iteritems
itervalues = dict.itervalues
listvalues = dict.values
Expand All @@ -83,8 +83,8 @@ def __getattr__(self, name,
int_types = int,
unicode_ = str
else:
int_types = int, long
unicode_ = unicode
int_types = int, long # noqa: F821
unicode_ = unicode # noqa: F821


def flatten(n, l):
Expand Down

0 comments on commit a864447

Please sign in to comment.