本文整理汇总了Python中reprounzip.unpackers.common.join_root函数的典型用法代码示例。如果您正苦于以下问题:Python join_root函数的具体用法?Python join_root怎么用?Python join_root使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了join_root函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: extract_original_input
def extract_original_input(self, input_name, input_path, temp):
tar = tarfile.open(str(self.target / 'inputs.tar.gz'), 'r:*')
member = tar.getmember(str(join_root(PosixPath(''), input_path)))
member.name = str(temp.name)
tar.extract(member, str(temp.parent))
tar.close()
return temp
开发者ID:aashish24,项目名称:reprozip,代码行数:7,代码来源:default.py
示例2: chroot_unmount
def chroot_unmount(target):
"""Unmount magic directories, if they are mounted.
"""
unpacked_info = metadata_read(target, 'chroot')
mounted = unpacked_info.get('mounted', False)
if not mounted:
return False
target = target.resolve()
for m in ('/dev', '/proc'):
d = join_root(target / 'root', Path(m))
if d.exists():
logging.info("Unmounting %s...", d)
# Unmounts recursively
subprocess.check_call(
'grep %s /proc/mounts | '
'cut -f2 -d" " | '
'sort -r | '
'xargs umount' % d,
shell=True)
unpacked_info['mounted'] = False
metadata_write(target, unpacked_info, 'chroot')
return True
开发者ID:ReproNim,项目名称:reprozip,代码行数:26,代码来源:default.py
示例3: upload_file
def upload_file(self, local_path, input_path):
if self.use_chroot:
remote_path = join_root(PosixPath('/experimentroot'),
input_path)
else:
remote_path = input_path
# Upload to a temporary file first
logging.info("Uploading file via SCP...")
rtemp = PosixPath(make_unique_name(b'/tmp/reprozip_input_'))
self.client_scp.put(local_path.path, rtemp.path, recursive=False)
# Move it
logging.info("Moving file into place...")
chan = self.ssh.get_transport().open_session()
chown_cmd = '/bin/chown --reference=%s %s' % (
shell_escape(remote_path.path),
shell_escape(rtemp.path))
chmod_cmd = '/bin/chmod --reference=%s %s' % (
shell_escape(remote_path.path),
shell_escape(rtemp.path))
mv_cmd = '/bin/mv %s %s' % (
shell_escape(rtemp.path),
shell_escape(remote_path.path))
chan.exec_command('/usr/bin/sudo /bin/sh -c %s' % shell_escape(
';'.join((chown_cmd, chmod_cmd, mv_cmd))))
if chan.recv_exit_status() != 0:
logging.critical("Couldn't move file in virtual machine")
sys.exit(1)
chan.close()
开发者ID:hugobowne,项目名称:reprozip,代码行数:30,代码来源:__init__.py
示例4: download
def download(self, remote_path, local_path):
if self.use_chroot:
remote_path = join_root(PosixPath('/experimentroot'), remote_path)
temp = make_unique_name(b'reprozip_output_')
rtemp = PosixPath('/vagrant') / temp
ltemp = self.target / temp
# Copy file to shared folder
logging.info("Copying file to shared folder...")
chan = self.ssh.get_transport().open_session()
cp_cmd = '/bin/cp %s %s' % (
shell_escape(remote_path.path),
shell_escape(rtemp.path))
chown_cmd = '/bin/chown vagrant %s' % shell_escape(rtemp.path)
chmod_cmd = '/bin/chmod 644 %s' % shell_escape(rtemp.path)
chan.exec_command('/usr/bin/sudo /bin/sh -c %s' % shell_escape(
' && '.join((cp_cmd, chown_cmd, chmod_cmd))))
if chan.recv_exit_status() != 0:
logging.critical("Couldn't copy file in virtual machine")
try:
ltemp.remove()
except OSError:
pass
return False
# Move file to final destination
try:
ltemp.rename(local_path)
except OSError as e:
logging.critical("Couldn't download output file: %s\n%s",
remote_path, str(e))
ltemp.remove()
return False
return True
开发者ID:faical-yannick-congo,项目名称:reprozip,代码行数:35,代码来源:__init__.py
示例5: download
def download(self, remote_path, local_path):
remote_path = join_root(self.root, remote_path)
# Copy
if not remote_path.exists():
logging.critical("Can't get output file (doesn't exist): %s",
remote_path)
sys.exit(1)
remote_path.copyfile(local_path)
remote_path.copymode(local_path)
开发者ID:hugobowne,项目名称:reprozip,代码行数:10,代码来源:default.py
示例6: download_and_print
def download_and_print(self, remote_path):
remote_path = join_root(self.root, remote_path)
# Output to stdout
if not remote_path.exists():
logging.critical("Can't get output file (doesn't exist): %s",
remote_path)
sys.exit(1)
with remote_path.open('rb') as fp:
copyfile(fp, stdout_bytes)
开发者ID:hugobowne,项目名称:reprozip,代码行数:10,代码来源:default.py
示例7: upload_file
def upload_file(self, local_path, input_path):
remote_path = join_root(self.root, input_path)
# Copy
orig_stat = remote_path.stat()
with make_dir_writable(remote_path.parent):
local_path.copyfile(remote_path)
remote_path.chmod(orig_stat.st_mode & 0o7777)
if self.restore_owner:
remote_path.chown(orig_stat.st_uid, orig_stat.st_gid)
开发者ID:ReproNim,项目名称:reprozip,代码行数:10,代码来源:default.py
示例8: download
def download(self, remote_path, local_path):
if self.use_chroot:
remote_path = join_root(PosixPath('/experimentroot'), remote_path)
try:
self.client_scp.get(remote_path.path, local_path.path,
recursive=False)
except scp.SCPException as e:
logging.critical("Couldn't download output file: %s\n%s",
remote_path, str(e))
sys.exit(1)
开发者ID:hugobowne,项目名称:reprozip,代码行数:10,代码来源:__init__.py
示例9: extract_original_input
def extract_original_input(self, input_name, input_path, temp):
tar = tarfile.open(str(self.target / 'inputs.tar.gz'), 'r:*')
try:
member = tar.getmember(str(join_root(PosixPath(''), input_path)))
except KeyError:
return None
member = copy.copy(member)
member.name = str(temp.components[-1])
tar.extract(member, str(temp.parent))
tar.close()
return temp
开发者ID:ReproNim,项目名称:reprozip,代码行数:11,代码来源:default.py
示例10: download_and_print
def download_and_print(self, remote_path):
remote_path = join_root(self.root, remote_path)
# Output to stdout
if not remote_path.exists():
logging.critical("Can't get output file (doesn't exist): %s",
remote_path)
sys.exit(1)
with remote_path.open('rb') as fp:
chunk = fp.read(1024)
if chunk:
sys.stdout.buffer.write(chunk)
while len(chunk) == 1024:
chunk = fp.read(1024)
if chunk:
sys.stdout.buffer.write(chunk)
开发者ID:aashish24,项目名称:reprozip,代码行数:16,代码来源:default.py
示例11: chroot_mount
def chroot_mount(args):
"""Mounts /dev and /proc inside the chroot directory.
"""
target = Path(args.target[0])
read_dict(target / '.reprounzip', 'chroot')
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', 'bind', m, str(d)])
write_dict(target / '.reprounzip', {'mounted': True}, 'chroot')
logging.warning("The host's /dev and /proc have been mounted into the "
"chroot. Do NOT remove the unpacked directory with "
"rm -rf, it WILL WIPE the host's /dev directory.")
开发者ID:aashish24,项目名称:reprozip,代码行数:17,代码来源:default.py
示例12: upload_file
def upload_file(self, local_path, input_path):
if self.use_chroot:
remote_path = join_root(PosixPath('/experimentroot'),
input_path)
else:
remote_path = input_path
temp = make_unique_name(b'reprozip_input_')
ltemp = self.target / temp
rtemp = PosixPath('/vagrant') / temp
# Copy file to shared folder
logging.info("Copying file to shared folder...")
local_path.copyfile(ltemp)
# Move it
logging.info("Moving file into place...")
chan = self.ssh.get_transport().open_session()
chown_cmd = '/bin/chown --reference=%s %s' % (
shell_escape(remote_path.path),
shell_escape(rtemp.path))
chmod_cmd = '/bin/chmod --reference=%s %s' % (
shell_escape(remote_path.path),
shell_escape(rtemp.path))
mv_cmd = '/bin/mv %s %s' % (
shell_escape(rtemp.path),
shell_escape(remote_path.path))
chan.exec_command('/usr/bin/sudo /bin/sh -c %s' % shell_escape(
' && '.join((chown_cmd, chmod_cmd, mv_cmd))))
if chan.recv_exit_status() != 0:
logging.critical("Couldn't move file in virtual machine")
try:
ltemp.remove()
except OSError:
pass
sys.exit(1)
chan.close()
开发者ID:faical-yannick-congo,项目名称:reprozip,代码行数:37,代码来源:__init__.py
示例13: chroot_mount
def chroot_mount(args):
"""Mounts /dev and /proc inside the chroot directory.
"""
target = Path(args.target[0])
unpacked_info = metadata_read(target, 'chroot')
# Create proc mount
d = target / 'root/proc'
d.mkdir(parents=True)
subprocess.check_call(['mount', '-t', 'proc', 'none', str(d)])
# Bind /dev from host
for m in ('/dev', '/dev/pts'):
d = join_root(target / 'root', Path(m))
d.mkdir(parents=True)
logger.info("Mounting %s on %s...", m, d)
subprocess.check_call(['mount', '-o', 'bind', m, str(d)])
unpacked_info['mounted'] = True
metadata_write(target, unpacked_info, 'chroot')
logger.warning("The host's /dev and /proc have been mounted into the "
"chroot. Do NOT remove the unpacked directory with "
"rm -rf, it WILL WIPE the host's /dev directory.")
开发者ID:ViDA-NYU,项目名称:reprozip,代码行数:24,代码来源:default.py
示例14: functional_tests
def functional_tests(raise_warnings, interactive, run_vagrant, run_docker):
python = [sys.executable]
# Can't match on the SignalWarning category here because of a Python bug
# http://bugs.python.org/issue22543
python.extend(['-W', 'error:signal'])
if 'COVER' in os.environ:
python.extend(['-m'] + os.environ['COVER'].split(' '))
reprozip_main = tests.parent / 'reprozip/reprozip/main.py'
reprounzip_main = tests.parent / 'reprounzip/reprounzip/main.py'
verbose = ['-v'] * 3
rpz = python + [reprozip_main.absolute().path] + verbose
rpuz = python + [reprounzip_main.absolute().path] + verbose
# ########################################
# 'simple' program: trace, pack, info, unpack
#
# Build
build('simple', ['simple.c'])
# Trace
check_call(rpz + ['trace', '-d', 'rpz-simple',
'./simple',
(tests / 'simple_input.txt').path,
'simple_output.txt'])
orig_output_location = Path('simple_output.txt').absolute()
assert orig_output_location.is_file()
with orig_output_location.open(encoding='utf-8') as fp:
assert fp.read().strip() == '42'
orig_output_location.remove()
# Read config
with Path('rpz-simple/config.yml').open(encoding='utf-8') as fp:
conf = yaml.safe_load(fp)
other_files = set(Path(f).absolute() for f in conf['other_files'])
expected = [Path('simple'), (tests / 'simple_input.txt')]
assert other_files.issuperset([f.resolve() for f in expected])
# Check input and output files
input_files = conf['runs'][0]['input_files']
assert (dict((k, Path(f).name)
for k, f in iteritems(input_files)) ==
{'arg': b'simple_input.txt'})
output_files = conf['runs'][0]['output_files']
print(dict((k, Path(f).name) for k, f in iteritems(output_files)))
# Here we don't test for dict equality, since we might have C coverage
# files in the mix
assert Path(output_files['arg']).name == b'simple_output.txt'
# Pack
check_call(rpz + ['pack', '-d', 'rpz-simple', 'simple.rpz'])
Path('simple').remove()
# Info
check_call(rpuz + ['info', 'simple.rpz'])
# Show files
check_call(rpuz + ['showfiles', 'simple.rpz'])
# Lists packages
check_call(rpuz + ['installpkgs', '--summary', 'simple.rpz'])
# Unpack directory
check_call(rpuz + ['directory', 'setup', 'simple.rpz', 'simpledir'])
# Run directory
check_call(rpuz + ['directory', 'run', 'simpledir'])
output_in_dir = join_root(Path('simpledir/root'), orig_output_location)
with output_in_dir.open(encoding='utf-8') as fp:
assert fp.read().strip() == '42'
# Delete with wrong command (should fail)
assert call(rpuz + ['chroot', 'destroy', 'simpledir']) != 0
# Delete directory
check_call(rpuz + ['directory', 'destroy', 'simpledir'])
# 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'])
if not Path('/vagrant').exists():
check_call(['sudo', 'sh', '-c', 'mkdir /vagrant; chmod 777 /vagrant'])
#.........这里部分代码省略.........
开发者ID:Aloma,项目名称:reprozip,代码行数:101,代码来源:functional.py
示例15: directory_create
def directory_create(args):
"""Unpacks the experiment in a folder.
Only the files that are not part of a package are copied (unless they are
missing from the system and were packed).
In addition, input files are put in a tar.gz (so they can be put back after
an upload) and the configuration file is extracted.
"""
if not args.pack:
logging.critical("setup needs the pack filename")
sys.exit(1)
pack = Path(args.pack[0])
target = Path(args.target[0])
if target.exists():
logging.critical("Target directory exists")
sys.exit(1)
if not issubclass(DefaultAbstractPath, PosixPath):
logging.critical("Not unpacking on POSIX system")
sys.exit(1)
signals.pre_setup(target=target, pack=pack)
# 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_file(target / 'config.yml', True)
target.mkdir()
root = (target / 'root').absolute()
root.mkdir()
# Checks packages
missing_files = False
for pkg in packages:
if pkg.packfiles:
continue
for f in pkg.files:
f = Path(f.path)
if not f.exists():
logging.error(
"Missing file %s (from package %s that wasn't packed) "
"on host, experiment will probably miss it.",
f, pkg.name)
missing_files = True
if missing_files:
record_usage(directory_missing_pkgs=True)
logging.error(
"Some packages are missing, you should probably install "
"them.\nUse 'reprounzip installpkgs -h' for help")
# Unpacks files
if any('..' in m.name or m.name.startswith('/') for m in tar.getmembers()):
logging.critical("Tar archive contains invalid pathnames")
sys.exit(1)
members = [m for m in tar.getmembers() if m.name.startswith('DATA/')]
for m in members:
m.name = m.name[5:]
# Makes symlink targets relative
for m in members:
if not m.issym():
continue
linkname = PosixPath(m.linkname)
if linkname.is_absolute:
m.linkname = join_root(root, PosixPath(m.linkname)).path
logging.info("Extracting files...")
tar.extractall(str(root), members)
tar.close()
# Gets library paths
lib_dirs = []
p = subprocess.Popen(['/sbin/ldconfig', '-v', '-N'],
stdout=subprocess.PIPE)
try:
for l in p.stdout:
if len(l) < 3 or l[0] in (b' ', b'\t'):
continue
if l.endswith(b':\n'):
lib_dirs.append(Path(l[:-2]))
finally:
p.wait()
# Original input files, so upload can restore them
if any(run['input_files'] for run in runs):
logging.info("Packing up original input files...")
inputtar = tarfile.open(str(target / 'inputs.tar.gz'), 'w:gz')
for run in runs:
for ifile in itervalues(run['input_files']):
inputtar.add(str(join_root(root, PosixPath(ifile))),
str(PosixPath(ifile)))
inputtar.close()
# Meta-data for reprounzip
write_dict(target / '.reprounzip', {}, 'directory')
#.........这里部分代码省略.........
开发者ID:aashish24,项目名称:reprozip,代码行数:101,代码来源:default.py
示例16: vagrant_setup_create
#.........这里部分代码省略.........
target.mkdir(parents=True)
try:
# Writes setup script
logging.info("Writing setup script %s...", target / 'setup.sh')
with (target / 'setup.sh').open('w', encoding='utf-8',
newline='\n') as fp:
fp.write('#!/bin/sh\n\nset -e\n\n')
if packages:
# Updates package sources
fp.write(installer.update_script())
fp.write('\n')
# Installs necessary packages
fp.write(installer.install_script(packages))
fp.write('\n')
# TODO : Compare package versions (painful because of sh)
# Untar
if use_chroot:
fp.write('\n'
'mkdir /experimentroot; cd /experimentroot\n')
fp.write('tar zpxf /vagrant/data.tgz --numeric-owner '
'--strip=1 %s\n' % rpz_pack.data_prefix)
if mount_bind:
fp.write('\n'
'mkdir -p /experimentroot/dev\n'
'mkdir -p /experimentroot/proc\n')
for pkg in packages:
fp.write('\n# Copies files from package %s\n' % pkg.name)
for f in pkg.files:
f = f.path
dest = join_root(PosixPath('/experimentroot'), f)
fp.write('mkdir -p %s\n' %
shell_escape(unicode_(f.parent)))
fp.write('cp -L %s %s\n' % (
shell_escape(unicode_(f)),
shell_escape(unicode_(dest))))
else:
fp.write('\ncd /\n')
paths = set()
pathlist = []
# Adds intermediate directories, and checks for existence in
# the tar
for f in other_files:
path = PosixPath('/')
for c in rpz_pack.remove_data_prefix(f.path).components:
path = path / c
if path in paths:
continue
paths.add(path)
try:
rpz_pack.get_data(path)
except KeyError:
logging.info("Missing file %s", path)
else:
pathlist.append(path)
# FIXME : for some reason we need reversed() here, I'm not sure
# why. Need to read more of tar's docs.
# TAR bug: --no-overwrite-dir removes --keep-old-files
# TAR bug: there is no way to make --keep-old-files not report
# an error if an existing file is encountered. --skip-old-files
# was introduced too recently. Instead, we just ignore the exit
# status
with (target / 'rpz-files.list').open('wb') as lfp:
开发者ID:hugobowne,项目名称:reprozip,代码行数:67,代码来源:__init__.py
示例17: docker_setup_create
def docker_setup_create(args):
"""Sets up the experiment to be run in a Docker-built container.
"""
pack = Path(args.pack[0])
target = Path(args.target[0])
if target.exists():
logging.critical("Target directory exists")
sys.exit(1)
signals.pre_setup(target=target, pack=pack)
# 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(target / 'config.yml', True)
if args.base_image:
record_usage(docker_explicit_base=True)
base_image = args.base_image[0]
if args.distribution:
target_distribution = args.distribution[0]
else:
target_distribution = None
else:
target_distribution, base_image = select_image(runs)
logging.info("Using base image %s", base_image)
logging.debug("Distribution: %s", target_distribution or "unknown")
target.mkdir(parents=True)
pack.copyfile(target / 'experiment.rpz')
# Writes Dockerfile
logging.info("Writing %s...", target / 'Dockerfile')
with (target / 'Dockerfile').open('w',
encoding='utf-8', newline='\n') as fp:
fp.write('FROM %s\n\n' % base_image)
# Installs busybox
download_file(busybox_url(runs[0]['architecture']),
target / 'busybox')
fp.write('COPY busybox /bin/busybox\n')
fp.write('COPY experiment.rpz /reprozip_experiment.rpz\n\n')
fp.write('RUN \\\n'
' chmod +x /bin/busybox && \\\n')
if args.install_pkgs:
# Install every package through package manager
missing_packages = []
else:
# Only install packages that were not packed
missing_packages = [pkg for pkg in packages if pkg.packfiles]
packages = [pkg for pkg in packages if not pkg.packfiles]
# FIXME : Right now, we need 'sudo' to be available (and it's not
# necessarily in the base image)
if packages:
record_usage(docker_install_pkgs=True)
else:
record_usage(docker_install_pkgs="sudo")
packages += [Package('sudo', None, packfiles=False)]
if packages:
try:
installer = select_installer(pack, runs, target_distribution)
except CantFindInstaller as e:
logging.error("Need to install %d packages but couldn't "
"select a package installer: %s",
len(packages), e)
sys.exit(1)
# Updates package sources
fp.write(' %s && \\\n' % installer.update_script())
# Installs necessary packages
fp.write(' %s && \\\n' % installer.install_script(packages))
logging.info("Dockerfile will install the %d software packages that "
"were not packed", len(packages))
# Untar
paths = set()
pathlist = []
dataroot = PosixPath('DATA')
# Adds intermediate directories, and checks for existence in the tar
tar = tarfile.open(str(pack), 'r:*')
missing_files = chain.from_iterable(pkg.files
for pkg in missing_packages)
for f in chain(other_files, missing_files):
path = PosixPath('/')
for c in f.path.components[1:]:
path = path / c
if path in paths:
continue
paths.add(path)
datapath = join_root(dataroot, path)
try:
tar.getmember(str(datapath))
except KeyError:
logging.info("Missing file %s", datapath)
#.........这里部分代码省略.........
开发者ID:aashish24,项目名称:reprozip,代码行数:101,代码来源:docker.py
示例18: directory_create
def directory_create(args):
"""Unpacks the experiment in a folder.
Only the files that are not part of a package are copied (unless they are
missing from the system and were packed).
In addition, input files are put in a tar.gz (so they can be put back after
an upload) and the configuration file is extracted.
"""
if not args.pack:
logging.critical("setup needs the pack filename")
sys.exit(1)
pack = Path(args.pack[0])
target = Path(args.target[0])
if target.exists():
logging.critical("Target directory exists")
sys.exit(1)
if not issubclass(DefaultAbstractPath, PosixPath):
logging.critical("Not unpacking on POSIX system")
sys.exit(1)
signals.pre_setup(target=target, pack=pack)
# Unpacks configuration file
rpz_pack = RPZPack(pack)
rpz_pack.extract_config(target / 'config.yml')
# Loads config
config = load_config_file(target / 'config.yml', True)
packages = config.packages
target.mkdir()
root = (target / 'root').absolute()
# Checks packages
missing_files = False
for pkg in packages:
if pkg.packfiles:
continue
for f in pkg.files:
if not Path(f.path).exists():
logging.error(
"Missing file %s (from package %s that wasn't packed) "
"on host, experiment will probably miss it.",
f, pkg.name)
missing_files = True
if missing_files:
record_usage(directory_missing_pkgs=True)
logging.error("Some packages are missing, you should probably install "
"them.\nUse 'reprounzip installpkgs -h' for help")
root.mkdir()
try:
# Unpacks files
members = rpz_pack.list_data()
for m in members:
# Remove 'DATA/' prefix
m.name = str(rpz_pack.remove_data_prefix(m.name))
# Makes symlink targets relative
if m.issym():
linkname = PosixPath(m.linkname)
if linkname.is_absolute:
m.linkname = join_root(root, PosixPath(m.linkname)).path
logging.info("Extracting files...")
rpz_pack.extract_data(root, members)
rpz_pack.close()
# Original input files, so upload can restore them
input_files = [f.path for f in itervalues(config.inputs_outputs)
if f.read_runs]
if input_files:
logging.info("Packing up original input files...")
inputtar = tarfile.open(str(target / 'inputs.tar.gz'), 'w:gz')
for ifile in input_files:
filename = join_root(root, ifile)
if filename.exists():
inputtar.add(str(filename), str(ifile))
inputtar.close()
# Meta-data for reprounzip
metadata_write(target, metadata_initial_iofiles(config), 'directory')
signals.post_setup(target=target, pack=pack)
except Exception:
rmtree_fixed(root)
raise
开发者ID:ReproNim,项目名称:reprozip,代码行数:88,代码来源:default.py
示例19: chroot_create
def chroot_create(args):
"""Unpacks the experiment in a folder so it can be run with chroot.
All the files in the pack are unpacked; system files are copied only if
they were not packed, and busybox is installed if /bin/sh wasn't packed.
In addition, input files are put in a tar.gz (so they can be put back after
an upload) and the configuration file is extracted.
"""
if not args.pack:
logging.critical("setup/create needs the pack filename")
sys.exit(1)
pack = Path(args.pack[0])
target = Path(args.target[0])
if target.exists():
logging.critical("Target directory exists")
sys.exit(1)
if DefaultAbstractPath is not PosixPath:
logging.critical("Not unpacking on POSIX system")
sys.exit(1)
signals.pre_setup(target=target, pack=pack)
# 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_file(target / 'config.yml', True)
target.mkdir()
root = (target / 'root').absolute()
root.mkdir()
# Checks that everything was packed
packages_not_packed = [pkg for pkg in packages if not pkg.packfiles]
if packages_not_packed:
record_usage(chroot_missing_pkgs=True)
logging.warning("According to configuration, some files were left out "
"because they belong to the following packages:%s"
"\nWill copy files from HOST SYSTEM",
''.join('\n %s' % pkg
for pkg in packages_not_packed))
missing_files = False
for pkg in packages_not_packed:
for f in pkg.files:
f = Path(f.path)
if not f.exists():
logging.error(
"Missing file %s (from package %s) on host, "
"experiment will probably miss it",
f, pkg.name)
missing_files = True
continue
dest = join_root(root, f)
dest.parent.mkdir(parents=True)
if f.is_link():
dest.symlink(f.read_link())
else:
f.copy(dest)
if restore_owner:
stat = f.stat()
dest.chown(stat.st_uid, stat.st_gid)
if missing_files:
record_usage(chroot_mising_files=True)
# Unpacks files
if any('..' in m.name or m.name.startswith('/') for m in tar.getmembers()):
logging.critical("Tar archive contains invalid pathnames")
sys.exit(1)
members = [m for m in tar.getmembers() if m.name.startswith('DATA/')]
for m in members:
m.name = m.name[5:]
if not restore_owner:
uid = os.getuid()
gid = os.getgid()
for m in members:
m.uid = uid
m.gid = gid
logging.info("Extracting files...")
tar.extractall(str(root), members)
tar.close()
# Sets up /bin/sh and /usr/bin/env, downloading busybox if necessary
sh_path = join_root(root, Path('/bin/sh'))
env_path = join_root(root, Path('/usr/bin/env'))
if not sh_path.lexists() or not env_path.lexists():
logging.info("Setting up busybox...")
busybox_path = join_root(root, Path('/bin/busybox'))
busybox_path.parent.mkdir(parents=True)
with make_dir_writable(join_root(root, Path('/bin'))):
download_file(busybox_url(runs[0]['architecture']),
busybox_path)
#.........这里部分代码省略.........
开发者ID:aashish24,项目名称:reprozip,代码行数:101,代码来源:default.py
示例20: vagrant_setup_create
#.........这里部分代码省略.........
target.mkdir(parents=True)
# Writes setup script
logging.info("Writing setup script %s...", target / 'setup.sh')
with (target / 'setup.sh').open('w', encoding='utf-8', newline='\n') as fp:
fp.write('#!/bin/sh\n\nset -e\n\n')
if packages:
# Updates package sources
fp.write(installer.update_script())
fp.write('\n')
# Installs necessary packages
fp.write(installer.install_script(packages))
fp.write('\n')
# TODO : Compare package versions (painful because of sh)
# Untar
if use_chroot:
fp.write('\n'
'mkdir /experimentroot; cd /experimentroot\n')
fp.write('tar zpxf /vagrant/experiment.rpz '
'--numeric-owner --strip=1 DATA\n')
if mount_bind:
fp.write('\n'
'mkdir -p /experimentroot/dev\n'
'mount -o rbind /dev /experimentroot/dev\n'
'mkdir -p /experimentroot/proc\n'
'mount -o rbind /proc /experimentroot/proc\n')
for pkg in packages:
fp.write('\n# Copies files from package %s\n' % pkg.name)
for f in pkg.files:
f = f.path
dest = join_root(PosixPath('/experimentroot'), f)
fp.write('mkdir -p %s\n' %
shell_escape(unicode_(f.parent)))
fp.write('cp -L %s %s\n' % (
shell_escape(unicode_(f)),
shell_escape(unicode_(dest))))
else:
fp.write('\ncd /\n')
paths = set()
pathlist = []
dataroot = PosixPath('DATA')
# Adds intermediate directories, and checks for existence in the
# tar
tar = tarfile.open(str(pack), 'r:*')
for f in other_files:
path = PosixPath('/')
for c in f.path.components[1:]:
path = path / c
if path in paths:
continue
paths.add(path)
datapath = join_root(dataroot, path)
try:
tar.getmember(str(datapath))
except KeyError:
logging.info("Missing file %s", datapath)
else:
pathlist.append(unicode_(datapath))
tar.close()
# FIXME : for some reason we need reversed() here, I'm not sure
# why. Need to read more of tar's docs.
# TAR bug: --no-overwrite-dir removes --keep-old-files
# TAR bug: there is no way to make --keep-old-files not report an
开发者ID:aashish24,项目名称:reprozip,代码行数:67,代码来源:__init__.py
注:本文中的reprounzip.unpackers.common.join_root函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论