Skip to content
Commits on Source (15)
......@@ -27,16 +27,13 @@ from .utils.command import Command
class Ffprobe(Command):
MASK_STDERR = True
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.flag = False
def start(self):
super().start()
self.stderr = ''
@property
def stdout(self):
return self._process.stderr.splitlines(True)
......
......@@ -32,10 +32,26 @@ import binascii
HEADER = binascii.a2b_hex("580a000000020003")
# has to be one line
DUMP_RDB = """lazyLoad(commandArgs(TRUE)); for (obj in ls()) { print(obj); for (line in deparse(get(obj))) cat(line,"\\n"); }"""
# unfortunately this above snippet can't detect the build-path differences so
# diffoscope still falls back to a hexdump
DUMP_RDB = r"""
hideOutput = lazyLoad(commandArgs(TRUE));
for (x in ls(all.names = TRUE, sorted = TRUE)) {
obj = get(x)
cat(sprintf("%s (%s) = ", x, typeof(obj)), sep = "");
if (typeof(obj) == "environment") {
cat("\n{\n", sep = "");
for (y in ls(obj, all.names = TRUE, sorted = TRUE))
cat(sprintf(" \"%s\" = \"%s\"\n", y, get(y, envir = obj)), sep = "");
cat("}\n");
} else {
for (line in deparse(obj))
cat(line, "\n", sep = "");
}
cat("\n");
}
"""
logger = logging.getLogger(__name__)
......@@ -87,6 +103,7 @@ class RdsReader(Command):
def cmdline(self):
return [
'Rscript',
'--no-environ',
'-e',
'args <- commandArgs(TRUE); readRDS(args[1])',
self.path,
......@@ -111,9 +128,11 @@ class RdsFile(File):
class RdbReader(Command):
MASK_STDERR = True
@tool_required('Rscript')
def cmdline(self):
return ['Rscript', '-e', DUMP_RDB, self.path]
return ['Rscript', '--no-environ', '-e', DUMP_RDB, self.path]
class RdbFile(File):
......
......@@ -26,15 +26,14 @@ logger = logging.getLogger(__name__)
class Command(metaclass=abc.ABCMeta):
MASK_STDERR = False
MAX_STDERR_LINES = 50
def __init__(self, path):
self._path = path
def start(self):
logger.debug(
"Executing %s", ' '.join([shlex.quote(x) for x in self.cmdline()])
)
logger.debug("Executing %s", self.shell_cmdline())
self._stdin = self.stdin()
# "stdin" used to be a feeder but we didn't need the functionality so
......@@ -67,12 +66,15 @@ class Command(metaclass=abc.ABCMeta):
raise NotImplementedError()
def shell_cmdline(self):
return ' '.join(
map(
lambda x: '{}' if x == self.path else shlex.quote(x),
self.cmdline(),
)
)
def fn(x):
if x == self.path:
return '{}'
x = repr(x)
if ' ' not in x:
x = x[1:-1]
return x
return ' '.join(fn(x) for x in self.cmdline())
def env(self):
return None # inherit parent environment by default
......@@ -88,6 +90,9 @@ class Command(metaclass=abc.ABCMeta):
pass
def _read_stderr(self):
if self.MASK_STDERR:
return ""
buf = ""
lines = self._process.stderr.splitlines(True)
......
......@@ -296,12 +296,12 @@ class Difference:
if command1 and command1.stderr:
difference.add_comment(
"stderr from `{}`:".format(' '.join(command1.cmdline()))
"stderr from `{}`:".format(command1.shell_cmdline())
)
difference.add_comment(command1.stderr)
if command2 and command2.stderr:
difference.add_comment(
"stderr from `{}`:".format(' '.join(command2.cmdline()))
"stderr from `{}`:".format(command2.shell_cmdline())
)
difference.add_comment(command2.stderr)
......