Search in sources :

Example 6 with MagicCommandOutput

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());
    }
}
Also used : MagicCommandOutput(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput) Message(com.twosigma.beakerx.message.Message)

Example 7 with MagicCommandOutput

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);
}
Also used : AddImportStatus(com.twosigma.beakerx.kernel.AddImportStatus) MagicCommandOutput(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput) ImportPath(com.twosigma.beakerx.kernel.ImportPath)

Example 8 with MagicCommandOutput

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);
}
Also used : EvaluatorParameters(com.twosigma.beakerx.kernel.EvaluatorParameters) MagicCommandOutput(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput) HashMap(java.util.HashMap)

Example 9 with MagicCommandOutput

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);
}
Also used : AddImportStatus(com.twosigma.beakerx.kernel.AddImportStatus) MagicCommandOutput(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput) ImportPath(com.twosigma.beakerx.kernel.ImportPath)

Example 10 with MagicCommandOutput

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());
}
Also used : MagicCommandOutput(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput) MavenJarResolver(com.twosigma.beakerx.kernel.magic.command.MavenJarResolver)

Aggregations

MagicCommandOutput (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput)14 TryResult (com.twosigma.beakerx.TryResult)3 SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)3 ImportPath (com.twosigma.beakerx.kernel.ImportPath)3 PlainCode.createSimpleEvaluationObject (com.twosigma.beakerx.kernel.PlainCode.createSimpleEvaluationObject)3 Message (com.twosigma.beakerx.message.Message)3 AddImportStatus (com.twosigma.beakerx.kernel.AddImportStatus)2 Code (com.twosigma.beakerx.kernel.Code)2 MagicCommandFunctionality (com.twosigma.beakerx.kernel.magic.command.MagicCommandFunctionality)2 MavenJarResolver (com.twosigma.beakerx.kernel.magic.command.MavenJarResolver)2 ThreadMXBean (java.lang.management.ThreadMXBean)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 EvaluatorParameters (com.twosigma.beakerx.kernel.EvaluatorParameters)1 KernelFunctionality (com.twosigma.beakerx.kernel.KernelFunctionality)1 MagicCommandType (com.twosigma.beakerx.kernel.magic.command.MagicCommandType)1 AddMvnCommandResult (com.twosigma.beakerx.kernel.magic.command.MavenJarResolver.AddMvnCommandResult)1 MagicCommandResult (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandResult)1 MIMEContainer (com.twosigma.beakerx.mimetype.MIMEContainer)1 File (java.io.File)1