Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def trace(binary, argv, directory, append, verbosity=1):
"""Main function for the trace subcommand.
"""
cwd = Path.cwd()
if (any(cwd.lies_under(c) for c in magic_dirs + system_dirs) and
not cwd.lies_under('/usr/local')):
logging.warning(
"You are running this experiment from a system directory! "
"Autodetection of non-system files will probably not work as "
"intended")
# Trace directory
if directory.exists():
if append is None:
r = tty_prompt(
"Trace directory %s exists\n"
"(a)ppend run to the trace, (d)elete it or (s)top? [a/d/s] " %
directory,
'aAdDsS')
if r is None:
logging.critical(
cur.close()
# Further filters input files
inputs = [[fi.path
for fi in lst
# Input files are regular files,
if fi.path.is_file() and
# ONLY_READ,
fi.runs[r] == TracedFile.ONLY_READ and
# not executable,
# FIXME : currently disabled; only remove executed files
# not fi.path.stat().st_mode & 0b111 and
fi.path not in executed and
# not in a system directory
not any(fi.path.lies_under(m)
for m in magic_dirs + system_dirs)]
for r, lst in enumerate(access_files)]
# Identify output files
outputs = [[fi.path
for fi in lst
# Output files are regular files,
if fi.path.is_file() and
# WRITTEN
fi.runs[r] == TracedFile.WRITTEN and
# not in a system directory
not any(fi.path.lies_under(m)
for m in magic_dirs + system_dirs)]
for r, lst in enumerate(access_files)]
# Run the list of files through the filter plugins
run_filter_plugins(files, inputs)
if fi.what == TracedFile.READ_THEN_WRITTEN and
not any(fi.path.lies_under(m) for m in magic_dirs)]
if read_then_written_files:
logger.warning(
"Some files were read and then written. We will only pack the "
"final version of the file; reproducible experiments shouldn't "
"change their input files")
logger.info("Paths:\n%s",
", ".join(unicode_(fi.path)
for fi in read_then_written_files))
files = set(
fi
for fi in itervalues(files)
if fi.what != TracedFile.WRITTEN and not any(fi.path.lies_under(m)
for m in magic_dirs))
return files, inputs, outputs
cur.close()
# Further filters input files
inputs = [[fi.path
for fi in lst
# Input files are regular files,
if fi.path.is_file() and
# ONLY_READ,
fi.runs[r] == TracedFile.ONLY_READ and
# not executable,
# FIXME : currently disabled; only remove executed files
# not fi.path.stat().st_mode & 0b111 and
fi.path not in executed and
# not in a system directory
not any(fi.path.lies_under(m)
for m in magic_dirs + system_dirs)]
for r, lst in enumerate(access_files)]
# Identify output files
outputs = [[fi.path
for fi in lst
# Output files are regular files,
if fi.path.is_file() and
# WRITTEN
fi.runs[r] == TracedFile.WRITTEN and
# not in a system directory
not any(fi.path.lies_under(m)
for m in magic_dirs + system_dirs)]
for r, lst in enumerate(access_files)]
# Run the list of files through the filter plugins
run_filter_plugins(files, inputs)