本文整理汇总了Python中reprounzip.utils.iteritems函数的典型用法代码示例。如果您正苦于以下问题:Python iteritems函数的具体用法?Python iteritems怎么用?Python iteritems使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iteritems函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: showfiles
def showfiles(args):
"""Writes out the input and output files.
Works both for a pack file and for an extracted directory.
"""
pack = Path(args.pack[0])
if not pack.exists():
logging.critical("Pack or directory %s does not exist", pack)
sys.exit(1)
if pack.is_dir():
# Reads info from an unpacked directory
runs, packages, other_files = load_config_file(pack / 'config.yml',
canonical=True)
# The '.reprounzip' file is a pickled dictionary, it contains the name
# of the files that replaced each input file (if upload was used)
with pack.open('rb', '.reprounzip') as fp:
unpacked_info = pickle.load(fp)
input_files = unpacked_info.get('input_files', {})
print("Input files:")
for i, run in enumerate(runs):
if len(runs) > 1:
print(" Run %d:" % i)
for input_name, path in iteritems(run['input_files']):
print(" %s (%s)" % (input_name, path))
if input_files.get(input_name) is not None:
assigned = PosixPath(input_files[input_name])
else:
assigned = "(original)"
print(" %s" % assigned)
print("Output files:")
for i, run in enumerate(runs):
if len(runs) > 1:
print(" Run %d:" % i)
for output_name, path in iteritems(run['output_files']):
print(" %s (%s)" % (output_name, path))
else: # pack.is_file()
# Reads info from a pack file
runs, packages, other_files = load_config(pack)
print("Input files:")
for i, run in enumerate(runs):
if len(runs) > 1:
print(" Run %d:" % i)
for input_name, path in iteritems(run['input_files']):
print(" %s (%s)" % (input_name, path))
print("Output files:")
for i, run in enumerate(runs):
if len(runs) > 1:
print(" Run %d:" % i)
for output_name, path in iteritems(run['output_files']):
print(" %s (%s)" % (output_name, path))
开发者ID:aashish24,项目名称:reprozip,代码行数:57,代码来源:pack_info.py
示例2: showfiles
def showfiles(args):
"""Writes out the input and output files.
Works both for a pack file and for an extracted directory.
"""
pack = Path(args.pack[0])
if not pack.exists():
logging.critical("Pack or directory %s does not exist", pack)
sys.exit(1)
if pack.is_dir():
# Reads info from an unpacked directory
config = load_config_file(pack / 'config.yml',
canonical=True)
# The '.reprounzip' file is a pickled dictionary, it contains the name
# of the files that replaced each input file (if upload was used)
with pack.open('rb', '.reprounzip') as fp:
unpacked_info = pickle.load(fp)
assigned_input_files = unpacked_info.get('input_files', {})
print("Input files:")
for input_name, f in iteritems(config.inputs_outputs):
if not f.read_runs:
continue
print(" %s (%s)" % (input_name, f.path))
if assigned_input_files.get(input_name) is not None:
assigned = assigned_input_files[input_name]
else:
assigned = "(original)"
print(" %s" % assigned)
print("Output files:")
for output_name, f in iteritems(config.inputs_outputs):
if f.write_runs:
print(" %s (%s)" % (output_name, f.path))
else: # pack.is_file()
# Reads info from a pack file
config = load_config(pack)
print("Input files:")
for input_name, f in iteritems(config.inputs_outputs):
if f.read_runs:
print(" %s (%s)" % (input_name, f.path))
print("Output files:")
for output_name, f in iteritems(config.inputs_outputs):
if f.write_runs:
print(" %s (%s)" % (output_name, f.path))
开发者ID:JosuaKrause,项目名称:reprozip,代码行数:50,代码来源:pack_info.py
示例3: metadata_initial_iofiles
def metadata_initial_iofiles(config, dct=None):
"""Add the initial state of the input files to the unpacker metadata.
:param config: The configuration as returned by `load_config()`, which will
be used to list the input files and to determine which ones have been
packed (and therefore exist initially).
The `input_files` key contains a dict mapping the name to either:
* None (or inexistent): original file and exists
* False: doesn't exist (wasn't packed)
* True: has been generated by one of the run since the experiment was
unpacked
* basestring: the user uploaded a file with this path, and no run has
overwritten it yet
"""
if dct is None:
dct = {}
path2iofile = {f.path: n
for n, f in iteritems(config.inputs_outputs)
if f.read_runs}
def packed_files():
yield config.other_files
for pkg in config.packages:
if pkg.packfiles:
yield pkg.files
for f in itertools.chain.from_iterable(packed_files()):
f = f.path
path2iofile.pop(f, None)
dct['input_files'] = dict((n, False) for n in itervalues(path2iofile))
return dct
开发者ID:koconne8,项目名称:reprozip,代码行数:35,代码来源:misc.py
示例4: __call__
def __call__(self, **kwargs):
info = {}
for arg, argtype in iteritems(self._args):
if argtype == Signal.REQUIRED:
try:
info[arg] = kwargs.pop(arg)
except KeyError:
warnings.warn(
"signal: Missing required argument %s; " "signal ignored" % arg,
category=SignalWarning,
stacklevel=2,
)
return
else:
if arg in kwargs:
info[arg] = kwargs.pop(arg)
if argtype == Signal.DEPRECATED:
warnings.warn("signal: Argument %s is deprecated" % arg, category=SignalWarning, stacklevel=2)
if kwargs:
arg = next(iter(kwargs))
warnings.warn("signal: Unexpected argument %s; signal ignored" % arg, category=SignalWarning, stacklevel=2)
return
for listener in self._listeners:
try:
listener(**info)
except Exception:
traceback.print_exc()
warnings.warn("signal: Got an exception calling a signal", category=SignalWarning)
开发者ID:JosuaKrause,项目名称:reprozip,代码行数:29,代码来源:signals.py
示例5: chroot_run
def chroot_run(args):
"""Runs the command in the chroot.
"""
target = Path(args.target[0])
read_dict(target / '.reprounzip', 'chroot')
cmdline = args.cmdline
# Loads config
runs, packages, other_files = load_config_file(target / 'config.yml', True)
selected_runs = get_runs(runs, args.run, cmdline)
root = target / 'root'
# X11 handler
x11 = X11Handler(args.x11, ('local', socket.gethostname()),
args.x11_display)
cmds = []
for run_number in selected_runs:
run = runs[run_number]
cmd = 'cd %s && ' % shell_escape(run['workingdir'])
cmd += '/usr/bin/env -i '
environ = x11.fix_env(run['environ'])
cmd += ' '.join('%s=%s' % (k, shell_escape(v))
for k, v in iteritems(environ))
cmd += ' '
# FIXME : Use exec -a or something if binary != argv[0]
if cmdline is None:
argv = [run['binary']] + run['argv'][1:]
else:
argv = cmdline
cmd += ' '.join(shell_escape(a) for a in argv)
userspec = '%s:%s' % (run.get('uid', 1000),
run.get('gid', 1000))
cmd = 'chroot --userspec=%s %s /bin/sh -c %s' % (
userspec,
shell_escape(unicode_(root)),
shell_escape(cmd))
cmds.append(cmd)
cmds = ['chroot %s /bin/sh -c %s' % (shell_escape(unicode_(root)),
shell_escape(c))
for c in x11.init_cmds] + cmds
cmds = ' && '.join(cmds)
# Starts forwarding
forwarders = []
for portnum, connector in x11.port_forward:
fwd = LocalForwarder(connector, portnum)
forwarders.append(fwd)
signals.pre_run(target=target)
retcode = interruptible_call(cmds, shell=True)
sys.stderr.write("\n*** Command finished, status: %d\n" % retcode)
signals.post_run(target=target, retcode=retcode)
开发者ID:aashish24,项目名称:reprozip,代码行数:55,代码来源:default.py
示例6: docker_setup_build
def docker_setup_build(args):
"""Builds the container from the Dockerfile
"""
target = Path(args.target[0])
unpacked_info = read_dict(target)
if 'initial_image' in unpacked_info:
logger.critical("Image already built")
sys.exit(1)
if args.image_name:
image = args.image_name[0]
if not isinstance(image, bytes):
image = image.encode('ascii')
else:
image = make_unique_name(b'reprounzip_image_')
logger.info("Calling 'docker build'...")
try:
retcode = subprocess.call(args.docker_cmd.split() + ['build', '-t'] +
args.docker_option + [image, '.'],
cwd=target.path)
except OSError:
logger.critical("docker executable not found")
sys.exit(1)
else:
if retcode != 0:
logger.critical("docker build failed with code %d", retcode)
sys.exit(1)
logger.info("Initial image created: %s", image.decode('ascii'))
unpacked_info['initial_image'] = image
unpacked_info['current_image'] = image
if 'DOCKER_MACHINE_NAME' in os.environ:
unpacked_info['docker_host'] = {
'type': 'docker-machine',
'name': os.environ['DOCKER_MACHINE_NAME']}
elif 'DOCKER_HOST' in os.environ:
unpacked_info['docker_host'] = {
'type': 'custom',
'env': dict((k, v)
for k, v in iteritems(os.environ)
if k.startswith('DOCKER_'))}
write_dict(target, unpacked_info)
开发者ID:ViDA-NYU,项目名称:reprozip,代码行数:44,代码来源:reprounzip_docker.py
示例7: metadata_update_run
def metadata_update_run(config, dct, runs):
"""Update the unpacker metadata after some runs have executed.
:param runs: An iterable of run numbers that were probably executed.
This maintains a crude idea of the status of input files by updating the
files that are outputs of the runs that were just executed. This means that
files that were uploaded by the user will no longer be shown as uploaded
(they have been overwritten by the experiment) and files that weren't
packed exist from now on.
This is not very reliable because a run might have created a file that is
not designated as its output anyway, or might have failed and thus not
created the output (or a bad output).
"""
runs = set(runs)
input_files = dct.setdefault('input_files', {})
for name, fi in iteritems(config.inputs_outputs):
if fi.read_runs and any(r in runs for r in fi.write_runs):
input_files[name] = True
开发者ID:hugobowne,项目名称:reprozip,代码行数:21,代码来源:misc.py
示例8: run
def run(self, files):
reprounzip.common.record_usage(download_files=len(files))
output_files = dict(
(n, f.path)
for n, f in iteritems(self.get_config().inputs_outputs)
if f.write_runs)
# No argument: list all the output files and exit
if not files:
print("Output files:")
for output_name in output_files:
print(" %s" % output_name)
return
self.prepare_download(files)
try:
# Download files
for filespec in files:
filespec_split = filespec.split(':', 1)
if len(filespec_split) != 2:
logging.critical("Invalid file specification: %r",
filespec)
sys.exit(1)
output_name, local_path = filespec_split
try:
remote_path = output_files[output_name]
except KeyError:
logging.critical("Invalid output file: %r", output_name)
sys.exit(1)
logging.debug("Downloading file %s", remote_path)
if not local_path:
self.download_and_print(remote_path)
else:
self.download(remote_path, Path(local_path))
finally:
self.finalize()
开发者ID:JosuaKrause,项目名称:reprozip,代码行数:39,代码来源:misc.py
示例9: docker_run
def docker_run(args):
"""Runs the experiment in the container.
"""
target = Path(args.target[0])
unpacked_info = read_dict(target)
cmdline = args.cmdline
# Sanity check
if args.detach and args.x11:
logger.critical("Error: Can't use X11 forwarding if you're detaching")
raise UsageError
# Loads config
config = load_config(target / 'config.yml', True)
runs = config.runs
selected_runs = get_runs(runs, args.run, cmdline)
# Get current image name
if 'current_image' in unpacked_info:
image = unpacked_info['current_image']
logger.debug("Running from image %s", image.decode('ascii'))
else:
logger.critical("Image doesn't exist yet, have you run setup/build?")
sys.exit(1)
# Name of new container
if args.detach:
container = make_unique_name(b'reprounzip_detached_')
else:
container = make_unique_name(b'reprounzip_run_')
hostname = runs[selected_runs[0]].get('hostname', 'reprounzip')
# Port forwarding
port_options = []
for port_host, port_container, proto in parse_ports(args.expose_port):
port_options.extend(['-p',
'%s:%s/%s' % (port_host, port_container, proto)])
# X11 handler
if args.x11:
local_ip = get_local_addr()
docker_host = local_ip
if os.environ.get('DOCKER_HOST'):
m = _dockerhost_re.match(os.environ['DOCKER_HOST'])
if m is not None:
docker_host = m.group(1)
if args.tunneled_x11:
x11 = X11Handler(True, ('internet', docker_host), args.x11_display)
else:
x11 = X11Handler(True, ('internet', local_ip), args.x11_display)
if (docker_host != local_ip and docker_host != 'localhost' and
not docker_host.startswith('127.') and
not docker_host.startswith('192.168.99.')):
ssh_cmdline = ' '.join(
'-R*:%(p)d:127.0.0.1:%(p)d' % {'p': port}
for port, connector in x11.port_forward)
logger.warning(
"You requested X11 forwarding but the Docker container "
"appears to be running remotely. It is probable that it "
"won't be able to connect to the local display. Creating "
"a remote SSH tunnel and running with --tunneled-x11 "
"might help (%s).",
ssh_cmdline)
else:
x11 = X11Handler(False, ('local', hostname), args.x11_display)
cmd = []
for run_number in selected_runs:
run = runs[run_number]
env_set, env_unset = x11.env_fixes(run['environ'])
a_env_set, a_env_unset = parse_environment_args(args)
env_set.update(a_env_set)
env_unset.extend(a_env_unset)
if env_set or env_unset:
cmd.append('env')
env = []
for k in env_unset:
env.append('-u')
env.append(shell_escape(k))
for k, v in iteritems(env_set):
env.append('%s=%s' % (shell_escape(k), shell_escape(v)))
cmd.append(' '.join(env))
# FIXME : Use exec -a or something if binary != argv[0]
if cmdline is not None:
cmd.append('cmd')
cmd.append(' '.join(shell_escape(a) for a in cmdline))
cmd.append('run')
cmd.append('%d' % run_number)
cmd = list(chain.from_iterable([['do', shell_escape(c)]
for c in x11.init_cmds] +
[cmd]))
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Passing arguments to Docker image:")
for c in cmd:
logger.debug(c)
#.........这里部分代码省略.........
开发者ID:ViDA-NYU,项目名称:reprozip,代码行数:101,代码来源:reprounzip_docker.py
示例10: docker_setup_create
#.........这里部分代码省略.........
'#!/bin/sh\n'
'\n'
'COMMAND=\n'
'ENVVARS=\n'
'\n'
'if [ $# = 0 ]; then\n'
' exec /busybox sh /rpz_entrypoint.sh')
for nb in irange(len(runs)):
fp.write(' run %d' % nb)
fp.write(
'\n'
'fi\n'
'\n'
'while [ $# != 0 ]; do\n'
' case "$1" in\n'
' help)\n'
' echo "Image built from reprounzip-docker" >&2\n'
' echo "Usage: docker run <image> [cmd "word [word '
'...]"] [run <R>]" >&2\n'
' echo " \\`cmd ...\\` changes the command for '
'the next \\`run\\` option" >&2\n'
' echo " \\`run <name|number>\\` runs the '
'specified run" >&2\n'
' echo "By default, all the runs are executed." '
'>&2\n'
' echo "The runs in this image are:" >&2\n')
for run in runs:
fp.write(
' echo " {name}: {cmdline}" >&2\n'.format(
name=run['id'],
cmdline=' '.join(shell_escape(a)
for a in run['argv'])))
fp.write(
' exit 0\n'
' ;;\n'
' do)\n'
' shift\n'
' $1\n'
' ;;\n'
' env)\n'
' shift\n'
' ENVVARS="$1"\n'
' ;;\n'
' cmd)\n'
' shift\n'
' COMMAND="$1"\n'
' ;;\n'
' run)\n'
' shift\n'
' case "$1" in\n')
for i, run in enumerate(runs):
cmdline = ' '.join([run['binary']] + run['argv'][1:])
fp.write(
' {name})\n'
' RUNCOMMAND={cmd}\n'
' RUNWD={wd}\n'
' RUNENV={env}\n'
' RUNUID={uid}\n'
' RUNGID={gid}\n'
' ;;\n'.format(
name='%s|%d' % (run['id'], i),
cmd=shell_escape(cmdline),
wd=shell_escape(run['workingdir']),
env=shell_escape(' '.join(
'%s=%s' % (shell_escape(k), shell_escape(v))
for k, v in iteritems(run['environ']))),
uid=run.get('uid', 1000),
gid=run.get('gid', 1000)))
fp.write(
' *)\n'
' echo "RPZ: Unknown run $1" >&2\n'
' exit 1\n'
' ;;\n'
' esac\n'
' if [ -n "$COMMAND" ]; then\n'
' RUNCOMMAND="$COMMAND"\n'
' COMMAND=\n'
' fi\n'
' export RUNWD; export RUNENV; export ENVVARS; '
'export RUNCOMMAND\n'
' /rpzsudo "#$RUNUID" "#$RUNGID" /busybox sh -c '
'"cd \\"\\$RUNWD\\" && /busybox env -i $RUNENV $ENVVARS '
'$RUNCOMMAND; echo \\"*** Command finished, status: \\$?\\""\n'
' ENVVARS=\n'
' ;;\n'
' *)\n'
' echo "RPZ: Unknown option $1" >&2\n'
' exit 1\n'
' ;;\n'
' esac\n'
' shift\n'
'done\n')
# Meta-data for reprounzip
write_dict(target, metadata_initial_iofiles(config))
signals.post_setup(target=target, pack=pack)
except Exception:
target.rmtree(ignore_errors=True)
raise
开发者ID:ViDA-NYU,项目名称:reprozip,代码行数:101,代码来源:reprounzip_docker.py
示例11: graph_json
def graph_json(target, runs, packages, other_files, package_map, edges,
inputs_outputs, inputs_outputs_map,
level_pkgs, level_processes, level_other_files):
"""Writes a JSON file suitable for further processing.
"""
# Packages
if level_pkgs in (LVL_PKG_IGNORE, LVL_PKG_DROP):
json_packages = []
else:
json_packages = [pkg.json(level_pkgs) for pkg in packages]
# Other files
json_other_files = [unicode_(fi) for fi in sorted(other_files)]
# Programs
prog_map = {}
json_runs = [run.json(prog_map, level_processes) for run in runs]
# Connect edges
done_edges = set()
for prog, fi, mode, argv in edges:
endp_prog = prog_map[prog]
if fi in package_map:
if level_pkgs == LVL_PKG_DROP:
continue
endp_file = package_map[fi].json_endpoint(fi, level_pkgs)
e = endp_prog['name'], endp_file, mode
if e in done_edges:
continue
else:
done_edges.add(e)
else:
endp_file = unicode_(fi)
if mode is None:
endp_prog['reads'].append(endp_file)
elif mode & FILE_WRITE:
endp_prog['writes'].append(endp_file)
elif mode & FILE_READ:
endp_prog['reads'].append(endp_file)
json_other_files.sort()
if PY3:
fp = target.open('w', encoding='utf-8', newline='\n')
else:
fp = target.open('wb')
try:
json.dump({'packages': sorted(json_packages,
key=lambda p: p['name']),
'other_files': json_other_files,
'runs': json_runs,
'inputs_outputs': [
{'name': k, 'path': unicode_(v.path),
'read_by_runs': v.read_runs,
'written_by_runs': v.write_runs}
for k, v in sorted(iteritems(inputs_outputs))]},
fp,
ensure_ascii=False,
indent=2,
sort_keys=True)
finally:
fp.close()
开发者ID:ViDA-NYU,项目名称:reprozip,代码行数:62,代码来源:graph.py
示例12: _print_package_info
def _print_package_info(pack, info, verbosity=1):
print("Pack file: %s" % pack)
print("\n----- Pack information -----")
print("Compressed size: %s" % hsize(pack.size()))
info_pack = info.get('pack')
if info_pack:
if 'total_size' in info_pack:
print("Unpacked size: %s" % hsize(info_pack['total_size']))
if 'total_paths' in info_pack:
print("Total packed paths: %d" % info_pack['total_paths'])
if verbosity >= 3:
print(" Files: %d" % info_pack['files'])
print(" Directories: %d" % info_pack['dirs'])
if info_pack.get('symlinks'):
print(" Symbolic links: %d" % info_pack['symlinks'])
if info_pack.get('hardlinks'):
print(" Hard links: %d" % info_pack['hardlinks'])
if info_pack.get('others'):
print(" Unknown (what!?): %d" % info_pack['others'])
print("\n----- Metadata -----")
info_meta = info['meta']
if verbosity >= 3:
print("Total paths: %d" % info_meta['total_paths'])
print("Listed packed paths: %d" % info_meta['packed_paths'])
if info_meta.get('packages'):
print("Total software packages: %d" % info_meta['packages'])
print("Packed software packages: %d" % info_meta['packed_packages'])
if verbosity >= 3:
print("Files from packed software packages: %d" %
info_meta['packed_packages_files'])
print("Files from unpacked software packages: %d" %
info_meta['unpacked_packages_files'])
if 'architecture' in info_meta:
print("Architecture: %s (current: %s)" % (info_meta['architecture'],
platform.machine().lower()))
if 'distribution' in info_meta:
distribution = ' '.join(t for t in info_meta['distribution'] if t)
current_distribution = [distro.id(), distro.version()]
current_distribution = ' '.join(t for t in current_distribution if t)
print("Distribution: %s (current: %s)" % (
distribution, current_distribution or "(not Linux)"))
if 'runs' in info:
runs = info['runs']
print("Runs (%d):" % len(runs))
for run in runs:
cmdline = ' '.join(shell_escape(a) for a in run['argv'])
if len(runs) == 1 and run['id'] == "run0":
print(" %s" % cmdline)
else:
print(" %s: %s" % (run['id'], cmdline))
if verbosity >= 2:
print(" wd: %s" % run['workingdir'])
if 'signal' in run:
print(" signal: %d" % run['signal'])
else:
print(" exitcode: %d" % run['exitcode'])
if run.get('walltime') is not None:
print(" walltime: %s" % run['walltime'])
inputs_outputs = info.get('inputs_outputs')
if inputs_outputs:
if verbosity < 2:
print("Inputs/outputs files (%d): %s" % (
len(inputs_outputs), ", ".join(sorted(inputs_outputs))))
else:
print("Inputs/outputs files (%d):" % len(inputs_outputs))
for name, f in sorted(iteritems(inputs_outputs)):
t = []
if f['read_runs']:
t.append("in")
if f['write_runs']:
t.append("out")
print(" %s (%s): %s" % (name, ' '.join(t), f['path']))
unpacker_status = info.get('unpacker_status')
if unpacker_status:
print("\n----- Unpackers -----")
for s, n in [(COMPAT_OK, "Compatible"), (COMPAT_MAYBE, "Unknown"),
(COMPAT_NO, "Incompatible")]:
if s != COMPAT_OK and verbosity < 2:
continue
if s not in unpacker_status:
continue
upks = unpacker_status[s]
print("%s (%d):" % (n, len(upks)))
for upk_name, msg in upks:
if msg is not None:
print(" %s (%s)" % (upk_name, msg))
else:
print(" %s" % upk_name)
开发者ID:ViDA-NYU,项目名称:reprozip,代码行数:91,代码来源:pack_info.py
示例13: print_info
#.........这里部分代码省略.........
if runs:
meta_architecture = runs[0]['architecture']
if any(r['architecture'] != meta_architecture
for r in runs):
logging.warning("Runs have different architectures")
meta_distribution = runs[0]['distribution']
if any(r['distribution'] != meta_distribution
for r in runs):
logging.warning("Runs have different distributions")
meta_distribution = ' '.join(t for t in meta_distribution if t)
current_architecture = platform.machine().lower()
current_distribution = platform.linux_distribution()[0:2]
current_distribution = ' '.join(t for t in current_distribution if t)
print("Pack file: %s" % pack)
print("\n----- Pack information -----")
print("Compressed size: %s" % hsize(pack.size()))
print("Unpacked size: %s" % hsize(pack_total_size))
print("Total packed paths: %d" % pack_total_paths)
if args.verbosity >= 3:
print(" Files: %d" % pack_files)
print(" Directories: %d" % pack_dirs)
print(" Symbolic links: %d" % pack_symlinks)
if pack_others:
print(" Unknown (what!?): %d" % pack_others)
print("\n----- Metadata -----")
if args.verbosity >= 3:
print("Total paths: %d" % meta_total_paths)
print("Listed packed paths: %d" % meta_packed_paths)
if packages:
print("Total software packages: %d" % meta_packages)
print("Packed software packages: %d" % meta_packed_packages)
if args.verbosity >= 3:
print("Files from packed software packages: %d" %
meta_packed_packages_files)
print("Files from unpacked software packages: %d" %
meta_unpacked_packages_files)
if runs:
print("Architecture: %s (current: %s)" % (meta_architecture,
current_architecture))
print("Distribution: %s (current: %s)" % (
meta_distribution, current_distribution or "(not Linux)"))
print("Executions (%d):" % len(runs))
for i, run in enumerate(runs):
cmdline = ' '.join(shell_escape(a) for a in run['argv'])
if len(runs) > 1:
print(" %d: %s" % (i, cmdline))
else:
print(" %s" % cmdline)
if args.verbosity >= 2:
print(" wd: %s" % run['workingdir'])
if 'signal' in run:
print(" signal: %d" % run['signal'])
else:
print(" exitcode: %d" % run['exitcode'])
if inputs_outputs:
if args.verbosity < 2:
print("Inputs/outputs files (%d) :%s" % (
len(inputs_outputs), ", ".join(inputs_outputs)))
else:
print("Inputs/outputs files (%d):" % len(inputs_outputs))
for name, f in iteritems(inputs_outputs):
t = []
if f.read_runs:
t.append("in")
if f.write_runs:
t.append("out")
print(" %s (%s): %s" % (name, ' '.join(t), f.path))
# Unpacker compatibility
print("\n----- Unpackers -----")
unpacker_status = {}
for name, upk in iteritems(unpackers):
if 'test_compatibility' in upk:
compat = upk['test_compatibility']
if callable(compat):
compat = compat(pack, config=config)
if isinstance(compat, (tuple, list)):
compat, msg = compat
else:
msg = None
unpacker_status.setdefault(compat, []).append((name, msg))
else:
unpacker_status.setdefault(None, []).append((name, None))
for s, n in [(COMPAT_OK, "Compatible"), (COMPAT_MAYBE, "Unknown"),
(COMPAT_NO, "Incompatible")]:
if s != COMPAT_OK and args.verbosity < 2:
continue
if s not in unpacker_status:
continue
upks = unpacker_status[s]
print("%s (%d):" % (n, len(upks)))
for upk_name, msg in upks:
if msg is not None:
print(" %s (%s)" % (upk_name, msg))
else:
print(" %s" % upk_name)
开发者ID:JosuaKrause,项目名称:reprozip,代码行数:101,代码来源:pack_info.py
示例14: chroot_create
#.........这里部分代码省略.........
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
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()
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:
path = Path(f.path)
if not path.exists():
logging.error(
"Missing file %s (from package %s) on host, "
"experiment will probably miss it",
path, pkg.name)
missing_files = True
continue
dest = join_root(root, path)
dest.parent.mkdir(parents=True)
if path.is_link():
dest.symlink(path.read_link())
else:
path.copy(dest)
if restore_owner:
stat = path.stat()
dest.chown(stat.st_uid, stat.st_gid)
if missing_files:
record_usage(chroot_mising_files=True)
# Unpacks files
members = rpz_pack.list_data()
for m in members:
# Remove 'DATA/' prefix
m.name = str(rpz_pack.remove_data_prefix(m.name))
if not restore_owner:
uid = os.getuid()
gid = os.getgid()
for m in members:
m.uid = uid
m.gid = gid
logging.info("Extracting files...")
rpz_pack.extract_data(root, members)
rpz_pack.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(config.runs[0]['architecture']),
busybox_path,
'busybox-%s' % config.runs[0]['architecture'])
busybox_path.chmod(0o755)
if not sh_path.lexists():
sh_path.parent.mkdir(parents=True)
sh_path.symlink('/bin/busybox')
if not env_path.lexists():
env_path.parent.mkdir(parents=True)
env_path.symlink('/bin/busybox')
# Original input files, so upload can restore them
input_files = [f.path for n, f in iteritems(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:
inputtar.add(str(join_root(root, ifile)),
str(ifile))
inputtar.close()
# Meta-data for reprounzip
write_dict(target / '.reprounzip', {}, 'chroot')
signals.post_setup(target=target, pack=pack)
开发者ID:JosuaKrause,项目名称:reprozip,代码行数:101,代码来源:default.py
示例15: generate
def generate(target, configfile, database, all_forks=False, graph_format='dot',
level_pkgs='file', level_processes='thread',
level_other_files='all',
regex_filters=None, regex_replaces=None, aggregates=None):
"""Main function for the graph subcommand.
"""
try:
graph_format = {'dot': FORMAT_DOT, 'DOT': FORMAT_DOT,
'json': FORMAT_JSON, 'JSON': FORMAT_JSON}[graph_format]
except KeyError:
logging.critical("Unknown output format %r", graph_format)
sys.exit(1)
level_pkgs, level_processes, level_other_files, file_depth = \
parse_levels(level_pkgs, level_processes, level_other_files)
# Reads package ownership from the configuration
if not configfile.is_file():
logging.critical("Configuration file does not exist!\n"
"Did you forget to run 'reprozip trace'?\n"
"If not, you might want to use --dir to specify an "
"alternate location.")
sys.exit(1)
config = load_config(configfile, canonical=False)
inputs_outputs = dict((f.path, n)
for n, f in iteritems(config.inputs_outputs))
has_thread_flag = config.format_version >= LooseVersion('0.7')
runs, files, edges = read_events(database, all_forks,
has_thread_flag)
# Label the runs
if len(runs) != len(config.runs):
logging.warning("Configuration file doesn't list the same number of "
"runs we found in the database!")
else:
for config_run, run in izip(config.runs, runs):
run.name = config_run['id']
# Apply regexes
ignore = [lambda path, r=re.compile(p): r.search(path) is not None
for p in regex_filters or []]
replace = [lambda path, r=re.compile(p): r.sub(repl, path)
for p, repl in regex_replaces or []]
def filefilter(path):
pathuni = unicode_(path)
if any(f(pathuni) for f in ignore):
logging.debug("IGN %s", pathuni)
return None
if not (replace or aggregates):
return path
for fi in replace:
pathuni_ = fi(pathuni)
if pathuni_ != pathuni:
logging.debug("SUB %s -> %s", pathuni, pathuni_)
pathuni = pathuni_
for prefix in aggregates or []:
if pathuni.startswith(prefix):
logging.debug("AGG %s -> %s", pathuni, prefix)
pathuni = prefix
break
return PosixPath(pathuni)
files_new = set()
for fi in files:
fi = filefilter(fi)
if fi is not None:
files_new.add(fi)
files = files_new
edges_new = OrderedSet()
for prog, fi, mode, argv in edges:
fi = filefilter(fi)
if fi is not None:
edges_new.add((prog, fi, mode, argv))
edges = edges_new
# Puts files in packages
package_map = {}
if level_pkgs == LVL_PKG_IGNORE:
packages = []
other_files = files
else:
logging.info("Organizes packages...")
file2package = dict((f.path, pkg)
for pkg in config.packages for f in pkg.files)
packages = {}
other_files = []
for fi in files:
pkg = file2package.get(fi)
if pkg is not None:
package = packages.get(pkg.name)
if package is None:
package = Package(pkg.name, pkg.version)
packages[pkg.name] = package
package.files.add(fi)
package_map[fi] = package
else:
other_files.append(fi)
#.........这里部分代码省略.........
开发者ID:hugobowne,项目名称:reprozip,代码行数:101,代码来源:graph.py
示例16: run_from_vistrails
def run_from_vistrails():
setup_logging('REPROUNZIP-VISTRAILS', logging.INFO)
cli_version = 1
if len(sys.argv) > 1:
try:
cli_version = int(sys.argv[1])
except ValueError:
logging.info("Compatibility mode: reprounzip-vistrails didn't get "
"a version number")
if cli_version != 1:
logging.critical("Unknown interface version %d; you are probably "
"using a version of reprounzip-vistrails too old for "
"your VisTrails package. Consider upgrading.",
cli_version)
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument('unpacker')
parser.add_argument('directory')
parser.add_argument('run')
par
|
请发表评论