Skip to content

Commit

Permalink
Merge branch '0.6.x' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed May 4, 2015
2 parents 1491f6d + 9b2163f commit 0f003e6
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 66 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Bugfixes:
* Fixes reprounzip-vistrails failing because of reporting
* Fixes invalid escaping in VisTrails XML workflow
* Fixes docker run failing to read Docker's JSON output on Python 3
* Fixes mounting too many filesystems in chroot

Features:
* Adds Debian 8 'Jessie' to Vagrant boxes & Docker images
* Adds Ubuntu 15.04 'Vivid' to Vagrant boxes & Docker images

0.6.2 (2015-03-16)
------------------
Expand Down
26 changes: 15 additions & 11 deletions reprounzip-docker/reprounzip/unpackers/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,33 @@ def select_image(runs):
return 'ubuntu', 'ubuntu:12.04'
elif version == '14.04':
return 'ubuntu', 'ubuntu:14.04'
elif version == '14.10':
return 'ubuntu', 'ubuntu:14.10'
else:
if version != '14.10':
logging.warning("using Ubuntu 14.10 'Utopic' instead of '%s'",
if version != '15.04':
logging.warning("using Ubuntu 15.04 'Vivid' instead of '%s'",
version)
return 'ubuntu', 'ubuntu:14.10'
return 'ubuntu', 'ubuntu:15.04'

# Debian
else:
if distribution != 'debian':
logging.warning("unsupported distribution %s, using Debian",
distribution)
version = '7'
version = '8'

if version == '6' or version.startswith('squeeze'):
if (version == '6' or version.startswith('6.') or
version.startswith('squeeze')):
return 'debian', 'debian:squeeze'
elif version == '8' or version.startswith('jessie'):
return 'debian', 'debian:jessie'
elif (version == '7' or version.startswith('7.') or
version.startswith('wheezy')):
return 'debian', 'debian:wheezy'
else:
if (version != '7' and not version.startswith('7.') and
not version.startswith('wheezy')):
logging.warning("using Debian 7 'Wheezy' instead of '%s'",
if (version != '8' and not version.startswith('8.') and
not version.startswith('jessie')):
logging.warning("using Debian 8 'Jessie' instead of '%s'",
version)
return 'debian', 'debian:wheezy'
return 'debian', 'debian:jessie'


def write_dict(filename, dct):
Expand Down
31 changes: 21 additions & 10 deletions reprounzip-vagrant/reprounzip/unpackers/vagrant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,40 @@ def select_box(runs):
return 'ubuntu', 'hashicorp/precise32'
else: # architecture == 'x86_64'
return 'ubuntu', 'hashicorp/precise64'
if version != '14.04':
logging.warning("using Ubuntu 14.04 'Trusty' instead of '%s'",
if version == '14.04':
if architecture == 'i686':
return 'ubuntu', 'ubuntu/trusty32'
else: # architecture == 'x86_64'
return 'ubuntu', 'ubuntu/trusty64'
if version != '15.04':
logging.warning("using Ubuntu 15.04 'Vivid' instead of '%s'",
version)
if architecture == 'i686':
return 'ubuntu', 'ubuntu/trusty32'
return 'ubuntu', 'ubuntu/vivid32'
else: # architecture == 'x86_64':
return 'ubuntu', 'ubuntu/trusty64'
return 'ubuntu', 'ubuntu/vivid64'

# Debian
else:
if distribution != 'debian':
logging.warning("unsupported distribution %s, using Debian",
distribution)
version = '7'
version = '8'

if (version != '7' and not version.startswith('7.') and
not version.startswith('wheezy')):
logging.warning("using Debian 7 'Wheezy' instead of '%s'", version)
if (version == '7' or version.startswith('7.') or
version.startswith('wheezy')):
if architecture == 'i686':
return 'debian', 'remram/debian-7-i386'
else: # architecture == 'x86_64'
return 'debian', 'remram/debian-7-amd64'
if (version != '8' and not version.startswith('8.') and
not version.startswith('jessie')):
logging.warning("using Debian 8 'Jessie' instead of '%s'", version)

if architecture == 'i686':
return 'debian', 'remram/debian-7-i386'
return 'debian', 'remram/debian-8-i386'
else: # architecture == 'x86_64':
return 'debian', 'remram/debian-7-amd64'
return 'debian', 'remram/debian-8-amd64'


def write_dict(filename, dct):
Expand Down
12 changes: 3 additions & 9 deletions reprounzip/reprounzip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from __future__ import absolute_import, print_function, unicode_literals

import argparse
import codecs
import locale
import logging
from pkg_resources import iter_entry_points
Expand All @@ -26,6 +25,7 @@
submit_usage_report, record_usage
from reprounzip import signals
from reprounzip.unpackers.common import UsageError
from reprounzip.utils import StreamWriter


__version__ = '0.6'
Expand Down Expand Up @@ -77,14 +77,8 @@ def main():

# Encoding for output streams
if str == bytes: # PY2
writer = codecs.getwriter(locale.getpreferredencoding())
o_stdout, o_stderr = sys.stdout, sys.stderr
sys.stdout = writer(sys.stdout)
sys.stdout.buffer = o_stdout
sys.stderr = writer(sys.stderr)
sys.stderr.buffer = o_stderr
else:
sys.stdin = sys.stdin.buffer
sys.stderr = StreamWriter(sys.stderr)
sys.stdout = StreamWriter(sys.stdout)

# Parses command-line

Expand Down
8 changes: 7 additions & 1 deletion reprounzip/reprounzip/unpackers/common/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ def make_unique_name(prefix):
return prefix + next(unique_names)


safe_shell_chars = set("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789"
"-+=/:.,%_")


def shell_escape(s):
"""Given bl"a, returns "bl\\"a".
"""
if isinstance(s, bytes):
s = s.decode('utf-8')
if any(c in s for c in string.whitespace + '*$\\"\''):
if any(c not in safe_shell_chars for c in s):
return '"%s"' % (s.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('$', '\\$'))
Expand Down
4 changes: 2 additions & 2 deletions reprounzip/reprounzip/unpackers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,11 @@ def chroot_mount(args):
target = Path(args.target[0])
read_dict(target / '.reprounzip', 'chroot')

for m in ('/dev', '/proc'):
for m in ('/dev', '/dev/pts', '/proc'):
d = join_root(target / 'root', Path(m))
d.mkdir(parents=True)
logging.info("Mounting %s on %s...", m, d)
subprocess.check_call(['mount', '-o', 'rbind', m, str(d)])
subprocess.check_call(['mount', '-o', 'bind', m, str(d)])

write_dict(target / '.reprounzip', {'mounted': True}, 'chroot')

Expand Down
25 changes: 25 additions & 0 deletions reprounzip/reprounzip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

from __future__ import unicode_literals

import codecs
import contextlib
import email.utils
import locale
import logging
import os
from rpaths import Path
Expand Down Expand Up @@ -60,6 +62,29 @@ def escape(s):
return s.replace('\\', '\\\\').replace('"', '\\"')


class StreamWriter(object):
def __init__(self, stream):
writer = codecs.getwriter(locale.getpreferredencoding())
self._writer = writer(stream, 'replace')
self.buffer = stream

def writelines(self, lines):
self.write(str('').join(lines))

def write(self, obj):
if isinstance(obj, bytes):
self.buffer.write(obj)
else:
self._writer.write(obj)

def __getattr__(self, name,
getattr=getattr):

""" Inherit all other methods from the underlying stream.
"""
return getattr(self._writer, name)


class CommonEqualityMixin(object):
"""Common mixin providing comparison by comparing ``__dict__`` attributes.
"""
Expand Down
11 changes: 3 additions & 8 deletions reprozip/reprozip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from __future__ import unicode_literals

import argparse
import codecs
import locale
import logging
import os
Expand All @@ -29,7 +28,7 @@
submit_usage_report, record_usage
import reprozip.pack
import reprozip.tracer.trace
from reprozip.utils import PY3, unicode_
from reprozip.utils import PY3, unicode_, StreamWriter


def shell_escape(s):
Expand Down Expand Up @@ -226,12 +225,8 @@ def main():

# Encoding for output streams
if str == bytes: # PY2
writer = codecs.getwriter(locale.getpreferredencoding())
o_stdout, o_stderr = sys.stdout, sys.stderr
sys.stdout = writer(sys.stdout)
sys.stdout.buffer = o_stdout
sys.stderr = writer(sys.stderr)
sys.stderr.buffer = o_stderr
sys.stderr = StreamWriter(sys.stderr)
sys.stdout = StreamWriter(sys.stdout)

# http://bugs.python.org/issue13676
# This prevents reprozip from reading argv and envp arrays from trace
Expand Down
25 changes: 25 additions & 0 deletions reprozip/reprozip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

from __future__ import unicode_literals

import codecs
import contextlib
import email.utils
import locale
import logging
import os
from rpaths import Path
Expand Down Expand Up @@ -60,6 +62,29 @@ def escape(s):
return s.replace('\\', '\\\\').replace('"', '\\"')


class StreamWriter(object):
def __init__(self, stream):
writer = codecs.getwriter(locale.getpreferredencoding())
self._writer = writer(stream, 'replace')
self.buffer = stream

def writelines(self, lines):
self.write(str('').join(lines))

def write(self, obj):
if isinstance(obj, bytes):
self.buffer.write(obj)
else:
self._writer.write(obj)

def __getattr__(self, name,
getattr=getattr):

""" Inherit all other methods from the underlying stream.
"""
return getattr(self._writer, name)


class CommonEqualityMixin(object):
"""Common mixin providing comparison by comparing ``__dict__`` attributes.
"""
Expand Down
52 changes: 27 additions & 25 deletions tests/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,31 +203,33 @@ def functional_tests(raise_warnings, interactive, run_vagrant, run_docker):
# Unpack chroot
check_call(sudo + rpuz + ['chroot', 'setup', '--bind-magic-dirs',
'simple.rpz', 'simplechroot'])
# Run chroot
check_call(sudo + rpuz + ['chroot', 'run', 'simplechroot'])
output_in_chroot = join_root(Path('simplechroot/root'),
orig_output_location)
with output_in_chroot.open(encoding='utf-8') as fp:
assert fp.read().strip() == '42'
# Get output file
check_call(sudo + rpuz + ['chroot', 'download', 'simplechroot',
'arg:output1.txt'])
with Path('output1.txt').open(encoding='utf-8') as fp:
assert fp.read().strip() == '42'
# Replace input file
check_call(sudo + rpuz + ['chroot', 'upload', 'simplechroot',
'%s:arg' % (tests / 'simple_input2.txt')])
check_call(sudo + rpuz + ['chroot', 'upload', 'simplechroot'])
# Run again
check_call(sudo + rpuz + ['chroot', 'run', 'simplechroot'])
output_in_chroot = join_root(Path('simplechroot/root'),
orig_output_location)
with output_in_chroot.open(encoding='utf-8') as fp:
assert fp.read().strip() == '36'
# Delete with wrong command (should fail)
assert call(rpuz + ['directory', 'destroy', 'simplechroot']) != 0
# Delete chroot
check_call(sudo + rpuz + ['chroot', 'destroy', 'simplechroot'])
try:
# Run chroot
check_call(sudo + rpuz + ['chroot', 'run', 'simplechroot'])
output_in_chroot = join_root(Path('simplechroot/root'),
orig_output_location)
with output_in_chroot.open(encoding='utf-8') as fp:
assert fp.read().strip() == '42'
# Get output file
check_call(sudo + rpuz + ['chroot', 'download', 'simplechroot',
'arg:output1.txt'])
with Path('output1.txt').open(encoding='utf-8') as fp:
assert fp.read().strip() == '42'
# Replace input file
check_call(sudo + rpuz + ['chroot', 'upload', 'simplechroot',
'%s:arg' % (tests / 'simple_input2.txt')])
check_call(sudo + rpuz + ['chroot', 'upload', 'simplechroot'])
# Run again
check_call(sudo + rpuz + ['chroot', 'run', 'simplechroot'])
output_in_chroot = join_root(Path('simplechroot/root'),
orig_output_location)
with output_in_chroot.open(encoding='utf-8') as fp:
assert fp.read().strip() == '36'
# Delete with wrong command (should fail)
assert call(rpuz + ['directory', 'destroy', 'simplechroot']) != 0
finally:
# Delete chroot
check_call(sudo + rpuz + ['chroot', 'destroy', 'simplechroot'])

if not (tests / 'vagrant').exists():
check_call(['sudo', 'sh', '-c',
Expand Down

0 comments on commit 0f003e6

Please sign in to comment.