Search in sources :

Example 6 with ScriptRequest

use of org.eclipse.scanning.api.script.ScriptRequest in project gda-core by openGDA.

the class FrameCaptureRequestHandler method internalHandling.

private boolean internalHandling(FrameCaptureRequest frameCaptureRequest, ScanRequest scanRequest) {
    List<FrameRequestDocument> detectorDocuments = frameCaptureRequest.getValue();
    String monitorName = serverProperties.getProcessingRequests().getFrameCaptureDecorator();
    if (monitorName == null) {
        logger.error("Frame capture decorator not defined");
        return false;
    }
    try {
        FrameCollectingScannable scn = (FrameCollectingScannable) ScannableDeviceConnectorService.getInstance().getScannable(monitorName);
        scn.setFrameRequestDocument(detectorDocuments.iterator().next());
    } catch (ScanningException e) {
        logger.error("Error retrieving {} '{}'", FrameCollectingScannable.class.getName(), monitorName, e);
        return false;
    }
    List<String> monitors = new ArrayList<>(scanRequest.getMonitorNamesPerScan());
    monitors.add(monitorName);
    scanRequest.setMonitorNamesPerScan(monitors);
    var script = LocalProperties.get(CAMERA_STREAM_SCRIPT_PROPERTY);
    if (script != null) {
        var scriptRequest = new ScriptRequest(script);
        scanRequest.setAfterScript(scriptRequest);
    }
    return true;
}
Also used : ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) ScanningException(org.eclipse.scanning.api.scan.ScanningException) ArrayList(java.util.ArrayList) FrameRequestDocument(uk.ac.gda.api.acquisition.parameters.FrameRequestDocument) FrameCollectingScannable(uk.ac.diamond.daq.scanning.FrameCollectingScannable)

Example 7 with ScriptRequest

use of org.eclipse.scanning.api.script.ScriptRequest in project gda-core by openGDA.

the class GDAJythonScriptServiceTest method testExecute.

@Test
public void testExecute() throws Exception {
    File testFile = File.createTempFile("test", ".py", null);
    testFile.deleteOnExit();
    String testFilePath = testFile.getAbsolutePath();
    ScriptRequest scriptRequest = new ScriptRequest(testFilePath, SPEC_PASTICHE);
    scriptService.execute(scriptRequest);
    verify(mockCommandRunner).evaluateCommand("run '" + testFilePath + "'");
}
Also used : ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) File(java.io.File) Test(org.junit.Test)

Example 8 with ScriptRequest

use of org.eclipse.scanning.api.script.ScriptRequest in project gda-core by openGDA.

the class GDAJythonScriptServiceTest method testExecuteNoSuchFile.

@Test(expected = ScriptExecutionException.class)
public void testExecuteNoSuchFile() throws Exception {
    ICommandRunner mockCommandRunner = Mockito.mock(ICommandRunner.class);
    InterfaceProvider.setCommandRunnerForTesting(mockCommandRunner);
    ScriptRequest scriptRequest = new ScriptRequest("/tmp/noSuchFile.py", SPEC_PASTICHE);
    scriptService.execute(scriptRequest);
}
Also used : ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) Test(org.junit.Test)

Aggregations

ScriptRequest (org.eclipse.scanning.api.script.ScriptRequest)8 Test (org.junit.Test)5 File (java.io.File)2 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)1 ScanningException (org.eclipse.scanning.api.scan.ScanningException)1 IScriptFiles (uk.ac.diamond.daq.mapping.api.IScriptFiles)1 ScriptFiles (uk.ac.diamond.daq.mapping.impl.ScriptFiles)1 FrameCollectingScannable (uk.ac.diamond.daq.scanning.FrameCollectingScannable)1 FrameRequestDocument (uk.ac.gda.api.acquisition.parameters.FrameRequestDocument)1