Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processor: pass locale to subprocesses #150

Merged
merged 1 commit into from
Dec 18, 2019
Merged

Conversation

joshmoore
Copy link
Member

Neither setting the values globally on the server (or
in the docker container) nor setting them on OMERO start
up suffices to set the values in scripts.

cc: @will-moore

Neither setting the values globally on the server (or
in the docker container) nor setting them on OMERO start
up suffices to set the values in scripts.
Copy link
Member

@manics manics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work on py3-ci:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from omero.gateway import BlitzGateway
import omero.clients  # noqa
from omero.rtypes import rlong, rstring
from omero.model import ImageAnnotationLinkI, ImageI
import omero.scripts as scripts
import omero.util.script_utils as script_utils
import logging

logger = logging.getLogger('test_unicode')


def process_images(conn, script_params):

    fanns = []
    message = ""
    images, log_message = script_utils.get_objects(conn, script_params)
    message += log_message
    for image in images:
        text = ''.join(c if c.isalnum() else '_' for c in image.getName())
        message += 'ID:{} {}\n'.format(image.getId(), text)
        output = '{}.txt'.format(text)
        with open(output, 'w') as f:
            f.write(text)
        fann = conn.createFileAnnfromLocalFile(output, mimetype="text/plain")
        if image.canAnnotate():
            message += '  Attached file\n'
            link = ImageAnnotationLinkI()
            link.parent = ImageI(image.getId(), False)
            link.child = fann._obj
            link = conn.getUpdateService().saveAndReturnObject(link)
        else:
            message += '  Unable to attach file\n'
        fanns.append(fann)

    return fanns, message


def run_script():
    """
    The main entry point of the script, as called by the client via the
    scripting service, passing the required parameters.
    """

    client = scripts.client(
        'Test_Unicode.py',
        'Create a file with the name of the image (which may be unicode) and attach it',

        scripts.String(
            "Data_Type", optional=False, grouping="1",
            description="The data you want to work with.", values=[rstring('Image')],
            default="Image"),
        scripts.List(
            "IDs", optional=False, grouping="2",
            description="List of Image IDs to process.").ofType(rlong(0)),

        version="0.0.1",
        authors=["OME Team"],
        institutions=["University of Dundee"],
        contact="ome-users@lists.openmicroscopy.org.uk",
    )

    try:
        script_params = client.getInputs(unwrap=True)
        conn = BlitzGateway(client_obj=client)
        file_anns, message = process_images(conn, script_params)
        client.setOutput("Message", rstring(message))

    finally:
        client.closeSession()


if __name__ == "__main__":
    run_script()

@joshmoore joshmoore merged commit 9e8de44 into ome:master Dec 18, 2019
@joshmoore joshmoore deleted the proc-locale branch December 18, 2019 11:06
@joshmoore joshmoore added this to the 5.6.0 milestone Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants