Created
January 24, 2017 09:50
-
-
Save mguijarr/e357ab7ac395da38f8bfbb5b9cef590f to your computer and use it in GitHub Desktop.
MXCuBE XML-RPC client example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jsonpickle | |
import xmlrpclib | |
import time | |
import sys | |
import imp | |
server = xmlrpclib.ServerProxy('http://lid287:7171') | |
server.queue_set_serialisation("json") | |
## | |
BASE_DATA_DIRECTORY = '/data/id28/...' | |
## | |
# Retrieve code of queue model from server and compile and import it | |
# Recipe from http://code.activestate.com/recipes/82234-importing-a-dynamically-generated-module/ | |
# this allows to run this code even if MXCuBE is not installed on the host | |
for (module_name, module_code) in server.queue_get_model_code(): | |
queue_model_objects = imp.new_module(module_name) | |
exec module_code in queue_model_objects.__dict__ | |
sys.modules[module_name] = queue_model_objects | |
# Create a 'data collection' group and add a data collection | |
dcg = queue_model_objects.TaskGroup() | |
dcg.set_name('no_name') | |
json_dcg = jsonpickle.encode(dcg) | |
server.log_message('Adding task group from example client.', 'info') | |
dcg_id = server.queue_add_child(1, json_dcg) | |
# let's add a data collection | |
dc = queue_model_objects.DataCollection() | |
# this is how to set parameters for the data collection | |
# beware: gamma and chi are still called kappa and kappa_phi ! | |
dc.acquisitions[0].acquisition_parameters.exp_time = 5 | |
dc.acquisitions[0].acquisition_parameters.num_images = 10 | |
dc.acquisitions[0].acquisition_parameters.osc_start = 0 | |
dc.acquisitions[0].acquisition_parameters.osc_range = 45 | |
dc.acquisitions[0].acquisition_parameters.overlap = 0 | |
# ... | |
dc.acquisitions[0].path_template.directory = BASE_DATA_DIRECTORY | |
dc.acquisitions[0].path_template.base_prefix = 'test' | |
dc.set_name(dc.acquisitions[0].path_template.get_prefix()) | |
dc.acquisitions[0].path_template.num_files = 10 | |
# Serialize the task | |
dc = jsonpickle.encode(dc) | |
dc_id = server.queue_add_child(dcg_id, dc) | |
server.log_message('Collection added for %s added' % energy[1], 'info') | |
# and execute the queue | |
server.log_message('Executing queue.', 'info') | |
server.start_queue() # or just one task: server.queue_execute_entry_with_id(dcg_id) | |
# loop to wait end of queue execution | |
is_executing = server.is_queue_executing() | |
while(is_executing): | |
time.sleep(1) | |
is_executing = server.is_queue_executing() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment