use of com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput in project beakerx by twosigma.
the class TimeItLineModeMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
Message message = param.getCode().getMessage();
int executionCount = param.getExecutionCount();
String codeToExecute = param.getCommand().replace(TIMEIT_LINE, "");
codeToExecute = codeToExecute.replaceAll("(-.)(\\d*\\s)", "");
try {
return timeIt(buildTimeItOption(param.getCode()), codeToExecute, message, executionCount, param.isShowResult());
} catch (IllegalArgumentException e) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, e.getMessage());
}
}
use of com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput in project beakerx by twosigma.
the class AddImportMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] parts = MagicCommandUtils.splitPath(command);
if (parts.length != 2) {
return new MagicCommandOutput(ERROR, WRONG_FORMAT_MSG + IMPORT);
}
ImportPath anImport = new ImportPath(parts[1]);
AddImportStatus status = this.kernel.addImport(anImport);
if (AddImportStatus.ERROR.equals(status)) {
return new MagicCommandOutput(ERROR, "Could not import " + parts[1]);
}
return new MagicCommandOutput(OK);
}
use of com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput in project beakerx by twosigma.
the class DataSourcesMagicCommand method dataSource.
protected MagicCommandOutcomeItem dataSource(String source, String command) {
String[] parts = command.split(" ");
if (parts.length != 2) {
return new MagicCommandOutput(MagicCommandOutcomeItem.Status.ERROR, WRONG_FORMAT_MSG);
} else if (!parts[1].contains("jdbc:")) {
return new MagicCommandOutput(MagicCommandOutcomeItem.Status.ERROR, "Incorrect jdbc url.");
}
HashMap<String, Object> params = new HashMap<>();
params.put(source, parts[1]);
this.kernel.setShellOptions(new EvaluatorParameters(params));
return new MagicCommandOutput(MagicCommandOutcomeItem.Status.OK);
}
use of com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput in project beakerx by twosigma.
the class AddStaticImportMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] parts = MagicCommandUtils.splitPath(command);
if (parts.length != 3) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, WRONG_FORMAT_MSG);
}
AddImportStatus status = this.kernel.addImport(new ImportPath(parts[1] + " " + parts[2]));
if (AddImportStatus.ERROR.equals(status)) {
return new MagicCommandOutput(ERROR, "Could not import static " + parts[2]);
}
return new MagicCommandOutput(MagicCommandOutput.Status.OK);
}
use of com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput in project beakerx by twosigma.
the class ClassPathAddMvnCellMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String commandCodeBlock = param.getCommandCodeBlock();
if (commandCodeBlock != null) {
command += "\n" + commandCodeBlock;
}
String[] commandLines = command.split(SPLIT_LINE_REGEX);
unifyMvnLineFormat(commandLines);
if (!validateCommandLines(commandLines)) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, MVN_CELL_FORMAT_ERROR_MESSAGE);
}
ClasspathAddMvnMagicCommand mvnMagicCommand = MagicCommandTypesFactory.getClasspathAddMvnMagicCommand(kernel);
commandParams.setRepos(mvnMagicCommand.getRepos().get());
List<MavenJarResolver.Dependency> dependencies = getDepsFromCommand(Arrays.copyOfRange(commandLines, 1, commandLines.length));
MavenJarResolver mavenJarResolver = new MavenJarResolver(commandParams, pomFactory);
MvnLoggerWidget mvnLoggerWidget = new MvnLoggerWidget(param.getCode().getMessage());
MavenJarResolver.AddMvnCommandResult result = mavenJarResolver.retrieve(dependencies, mvnLoggerWidget);
if (result.isJarRetrieved()) {
return handleAddedJars(mavenJarResolver.getPathToMavenRepo() + "/*");
}
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, result.getErrorMessage());
}
Aggregations