Skip to content

Commit

Permalink
Always extracts config.yml from pack file
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Sep 8, 2014
1 parent f8083e4 commit b77af22
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
15 changes: 11 additions & 4 deletions reprounzip-docker/reprounzip/unpackers/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import sys
import tarfile

from reprounzip.common import Package
from reprounzip.common import Package, load_config
from reprounzip.unpackers.common import COMPAT_OK, COMPAT_MAYBE, \
composite_action, target_must_exist, make_unique_name, shell_escape, \
load_config, select_installer, join_root, FileDownloader, get_runs
select_installer, join_root, FileDownloader, get_runs
from reprounzip.utils import unicode_, iteritems


Expand Down Expand Up @@ -92,8 +92,15 @@ def docker_setup_create(args):
logging.critical("Target directory exists")
sys.exit(1)

# Unpacks configuration file
tar = tarfile.open(str(pack), 'r:*')
member = tar.getmember('METADATA/config.yml')
member.name = 'config.yml'
tar.extract(member, str(target))
tar.close()

# Loads config
runs, packages, other_files = load_config(pack)
runs, packages, other_files = load_config(target / 'config.yml', True)

if args.base_image:
target_distribution = None
Expand Down Expand Up @@ -193,7 +200,7 @@ def docker_run(args):
cmdline = args.cmdline

# Loads config
runs, packages, other_files = load_config(target / 'experiment.rpz')
runs, packages, other_files = load_config(target / 'config.yml', True)

selected_runs = get_runs(runs, args.run, cmdline)

Expand Down
16 changes: 12 additions & 4 deletions reprounzip-vagrant/reprounzip/unpackers/vagrant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
import sys
import tarfile

from reprounzip.common import load_config
from reprounzip.unpackers.common import COMPAT_OK, COMPAT_MAYBE, \
composite_action, target_must_exist, make_unique_name, shell_escape, \
load_config, select_installer, busybox_url, join_root, FileUploader, \
FileDownloader, get_runs
select_installer, busybox_url, join_root, FileUploader, FileDownloader, \
get_runs
from reprounzip.unpackers.vagrant.interaction import interactive_shell
from reprounzip.utils import unicode_, iteritems

Expand Down Expand Up @@ -136,8 +137,15 @@ def vagrant_setup_create(args):
use_chroot = args.use_chroot
mount_bind = args.bind_magic_dirs

# Unpacks configuration file
tar = tarfile.open(str(pack), 'r:*')
member = tar.getmember('METADATA/config.yml')
member.name = 'config.yml'
tar.extract(member, str(target))
tar.close()

# Loads config
runs, packages, other_files = load_config(pack)
runs, packages, other_files = load_config(target / 'config.yml', True)

if args.base_image and args.base_image[0]:
target_distribution = None
Expand Down Expand Up @@ -285,7 +293,7 @@ def vagrant_run(args):
cmdline = args.cmdline

# Loads config
runs, packages, other_files = load_config(target / 'experiment.rpz')
runs, packages, other_files = load_config(target / 'config.yml', True)

selected_runs = get_runs(runs, args.run, cmdline)

Expand Down
10 changes: 6 additions & 4 deletions reprounzip/reprounzip/unpackers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,9 @@ def run(self, files):

def get_runs_from_config(self):
# Loads config
runs, packages, other_files = load_config(
self.target / 'experiment.rpz')
runs, packages, other_files = reprounzip.common.load_config(
self.target / 'config.yml',
canonical=True)
return runs

def prepare_upload(self, files):
Expand Down Expand Up @@ -347,8 +348,9 @@ def run(self, files):

def get_runs_from_config(self):
# Loads config
runs, packages, other_files = load_config(
self.target / 'experiment.rpz')
runs, packages, other_files = reprounzip.common.load_config(
self.target / 'config.yml',
canonical=True)
return runs

def prepare_download(self, files):
Expand Down
38 changes: 14 additions & 24 deletions reprounzip/reprounzip/unpackers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,20 @@ def directory_create(args):
logging.critical("Not unpacking on POSIX system")
sys.exit(1)

# Unpacks configuration file
tar = tarfile.open(str(pack), 'r:*')
member = tar.getmember('METADATA/config.yml')
member.name = 'config.yml'
tar.extract(member, str(target))

# Loads config
runs, packages, other_files = load_config(pack)
runs, packages, other_files = load_config_file(target / 'config.yml', True)

target.mkdir()
root = (target / 'root').absolute()
root.mkdir()

# Unpacks files
tar = tarfile.open(str(pack), 'r:*')
if any('..' in m.name or m.name.startswith('/') for m in tar.getmembers()):
logging.critical("Tar archive contains invalid pathnames")
sys.exit(1)
Expand All @@ -140,11 +145,6 @@ def directory_create(args):
if linkname.is_absolute:
m.linkname = join_root(root, PosixPath(m.linkname)).path
tar.extractall(str(root), members)

# Unpacks configuration file
member = tar.getmember('METADATA/config.yml')
member.name = 'config.yml'
tar.extract(member, str(target))
tar.close()

# Gets library paths
Expand Down Expand Up @@ -302,8 +302,14 @@ def chroot_create(args):
# We can only restore owner/group of files if running as root
restore_owner = should_restore_owner(args.restore_owner)

# Unpacks configuration file
tar = tarfile.open(str(pack), 'r:*')
member = tar.getmember('METADATA/config.yml')
member.name = 'config.yml'
tar.extract(member, str(target))

# Loads config
runs, packages, other_files = load_config(pack)
runs, packages, other_files = load_config_file(target / 'config.yml', True)

target.mkdir()
root = (target / 'root').absolute()
Expand Down Expand Up @@ -335,7 +341,6 @@ def chroot_create(args):
dest.chown(stat.st_uid, stat.st_gid)

# Unpacks files
tar = tarfile.open(str(pack), 'r:*')
if any('..' in m.name or m.name.startswith('/') for m in tar.getmembers()):
logging.critical("Tar archive contains invalid pathnames")
sys.exit(1)
Expand All @@ -349,11 +354,6 @@ def chroot_create(args):
m.uid = uid
m.gid = gid
tar.extractall(str(root), members)

# Unpacks configuration file
member = tar.getmember('METADATA/config.yml')
member.name = 'config.yml'
tar.extract(member, str(target))
tar.close()

# Sets up /bin/sh and /usr/bin/env, downloading busybox if necessary
Expand Down Expand Up @@ -497,11 +497,6 @@ def __init__(self, target, input_files, files, type_, param_restore_owner):
self.param_restore_owner = param_restore_owner
FileUploader.__init__(self, target, input_files, files)

def get_runs_from_config(self):
runs, packages, other_files = load_config_file(
self.target / 'config.yml', True)
return runs

def prepare_upload(self, files):
self.restore_owner = (self.type == 'chroot' and
should_restore_owner(self.param_restore_owner))
Expand Down Expand Up @@ -539,11 +534,6 @@ def __init__(self, target, files, type_):
self.type = type_
FileDownloader.__init__(self, target, files)

def get_runs_from_config(self):
runs, packages, other_files = load_config_file(
self.target / 'config.yml', True)
return runs

def prepare_download(self, files):
self.root = (self.target / 'root').absolute()

Expand Down

0 comments on commit b77af22

Please sign in to comment.