本文整理汇总了Python中omero.gateway.BlitzGateway.getUser方法的典型用法代码示例。如果您正苦于以下问题:Python BlitzGateway.getUser方法的具体用法?Python BlitzGateway.getUser怎么用?Python BlitzGateway.getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类omero.gateway.BlitzGateway
的用法示例。
在下文中一共展示了BlitzGateway.getUser方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_containers
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import getUser [as 别名]
def create_containers(self, cli, project, dataset):
"""
Creates containers with names provided if they don't exist already.
Returns Dataset ID.
"""
sessionId = cli._event_context.sessionUuid
conn = BlitzGateway(host='localhost')
conn.connect(sUuid = sessionId)
params = omero.sys.Parameters()
params.theFilter = omero.sys.Filter()
params.theFilter.ownerId = wrap(conn.getUser().getId())
d = None
dsId = None
if project is not None:
# We need to find or create a project
# This is not nice but we really shouldn't be dealing with large numbers of objects here
plist = list(conn.getObjects("Project", attributes={'name': project}, params=params))
if len(plist) == 0:
# Create project and dataset then link
p = self.create_project(conn, project)
d = self.create_dataset(conn, dataset)
dsId = d.id.val
self.link_dataset(conn, p.id.val, dsId)
else:
# Pick the first, it's as good as any
p = plist[0]
print "Using existing Project:", project
# Since Project already exists check children for dataset
for c in p.listChildren():
if c.getName() == dataset:
d = c
dsId = d.getId()
# No existing child dataset so create one and link
if d is None:
d = self.create_dataset(conn, dataset)
dsId = d.id.val
self.link_dataset(conn, p.getId(), dsId)
else:
print "Using existing Dataset:", dataset
else:
# There may be more than one dataset with the same name
# This is not nice but we really shouldn't be dealing with large numbers of objects here
dlist = list(conn.getObjects("Dataset", attributes={'name': dataset}, params=params))
if len(dlist) != 0:
# We want one without a parent, the first will do
for c in dlist:
if len(c.listParents()) == 0:
d = c
dsId = d.getId()
if d is None:
dsId = self.create_dataset(conn, dataset).id.val
else:
print "Using existing Dataset:", dataset
return dsId
示例2: connect_to_omero
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import getUser [as 别名]
def connect_to_omero(user, password, host, port=4064):
conn = BlitzGateway(user, password, host=host, port=port)
print conn.connect()
user = conn.getUser()
print "Current user:"
print " ID:", user.getId()
print " Username:", user.getName()
print " Full Name:", user.getFullName()
print "Member of:"
for g in conn.getGroupsMemberOf():
print " ID:", g.getName(), " Name:", g.getId()
group = conn.getGroupFromContext()
print "Current group: ", group.getName()
return conn
示例3: create_containers
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import getUser [as 别名]
def create_containers(cli, dataset, project=None):
"""
Creates containers with names provided if they don't exist already.
Returns Dataset ID.
"""
sessionId = cli._event_context.sessionUuid
conn = BlitzGateway()
conn.connect(sUuid = sessionId)
params = omero.sys.Parameters()
params.theFilter = omero.sys.Filter()
params.theFilter.ownerId = wrap(conn.getUser().getId())
d = None
prId = None
if project is not None:
p = conn.getObject("Project", attributes={'name': project}, params=params)
if p is None:
print "Creating Project:", project
p = omero.model.ProjectI()
p.name = wrap(project)
prId = conn.getUpdateService().saveAndReturnObject(p).id.val
else:
print "Using Project:", project, p
prId = p.getId()
# Since Project already exists, check children for Dataset
for c in p.listChildren():
if c.getName() == dataset:
d = c
if d is None:
d = conn.getObject("Dataset", attributes={'name': dataset}, params=params)
if d is None:
print "Creating Dataset:", dataset
d = omero.model.DatasetI()
d.name = wrap(dataset)
dsId = conn.getUpdateService().saveAndReturnObject(d).id.val
if prId is not None:
print "Linking Project-Dataset..."
link = omero.model.ProjectDatasetLinkI()
link.child = omero.model.DatasetI(dsId, False)
link.parent = omero.model.ProjectI(prId, False)
conn.getUpdateService().saveObject(link)
else:
print "Using Dataset:", dataset, d
dsId = d.getId()
return dsId
示例4: run_as_script
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import getUser [as 别名]
def run_as_script():
"""
Main entry point of the script, as called via the scripting service.
"""
client = scripts.client(
'Export_Tree_Hierarchy.py',
'Trigger an update of the symlink tree hierarchy on the sciCORE '
'cluster filesystem.',
authors = ["Niko Ehrenfeuchter"],
institutions = ["IMCF, University of Basel"],
contact = "[email protected]",
)
try:
# wrap client to use the Blitz Gateway
conn = BlitzGateway(client_obj=client)
username = conn.getUser().getName()
markdir = os.path.join(os.environ['HOME'], '.omero_tree_export_usernames')
if not os.path.exists(markdir):
# do not create the marker directory, send back an error message
# instead - the directory has to exist, otherwise the wrapper
# daemon is not running!
message = "ERROR: Marker directory '%s' missing!" % markdir
client.setOutput("Message", rstring(message))
raise IOError("directory '%s' missing!" % markdir)
filename = os.path.join(markdir, username)
if os.path.exists(filename):
message = ("WARNING: a request for username '%s' is already "
"existing! Please contact an administrator if this "
"request does not get processed soon!" % username)
else:
message = "Requested update for username '%s'." % username
with open(filename, 'a') as out:
out.write('%s' % username)
client.setOutput("Message", rstring(message))
finally:
# Cleanup
client.closeSession()
示例5: create_screen
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import getUser [as 别名]
def create_screen(self, cli, screen):
"""
Creates screen with name provided if it doesn't exist already.
Returns Screen ID.
"""
sessionId = cli._event_context.sessionUuid
conn = BlitzGateway(host='localhost')
conn.connect(sUuid = sessionId)
params = omero.sys.Parameters()
params.theFilter = omero.sys.Filter()
params.theFilter.ownerId = wrap(conn.getUser().getId())
slist = list(conn.getObjects("Screen", attributes={'name': screen}, params=params))
if len(slist) == 0:
print "Creating Screen:", screen
s = ScreenI()
s.name = wrap(screen.encode('ascii','ignore'))
scrId = conn.getUpdateService().saveAndReturnObject(s).id.val
else:
scrId = slist[0].getId()
print "Using Screen:", screen
return scrId
示例6: encrypted
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import getUser [as 别名]
# Using secure connection.
# =============================================================
# By default, once we have logged in, data transfer is not encrypted (faster)
# To use a secure connection, call setSecure(True):
# conn.setSecure(True) # <--------- Uncomment this
# Current session details
# =============================================================
# By default, you will have logged into your 'current' group in OMERO. This
# can be changed by switching group in the OMERO.insight or OMERO.web clients.
user = conn.getUser()
print "Current user:"
print " ID:", user.getId()
print " Username:", user.getName()
print " Full Name:", user.getFullName()
print "Member of:"
for g in conn.getGroupsMemberOf():
print " ID:", g.getName(), " Name:", g.getId()
group = conn.getGroupFromContext()
print "Current group: ", group.getName()
print "Other Members of current group:"
for exp in conn.listColleagues():
print " ID:", exp.getId(), exp.getOmeName(), " Name:", exp.getFullName()
示例7: Omg
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import getUser [as 别名]
class Omg(object):
"""
OMERO gateway that wraps Blitz gateway and CLI, intended for
scripting and interactive work.
Attributes
----------
conn : Blitz gateway connection
"""
def __init__(self, conn=None, user=None, passwd=None,
server=SERVER, port=PORT, skey=None):
"""
Requires active Blitz connection OR username plus password or sesskey
"""
if conn is None and (user is None or (passwd is None and skey is None)):
raise ValueError("Bad parameters," + self.__init__.__doc__)
if conn is not None:
if conn.isConnected():
self.conn = conn
else:
raise ValueError("Cannot initialize with closed connection!")
else:
if passwd is not None:
self.conn = BlitzGateway(user, passwd, host=server, port=port)
self.conn.connect()
else:
self.conn = BlitzGateway(user, host=server, port=port)
self.conn.connect(skey)
if self.conn.isConnected():
self._server = self.conn.host
self._port = self.conn.port
self._user = self.conn.getUser().getName()
self._key = self.conn.getSession().getUuid().getValue()
print("Connected to {0} (port {1}) as {2}, session key={3}".format(
self._server, self._port, self._user, self._key))
else:
print("Failed to open connection :-(")
def ls(self):
"""
Print groups, then projects/datasets/images for current group.
"""
print("Groups for {0}:-".format(self.conn.getUser().getName()))
for gid, gname in self._ls_groups():
print(" {0} ({1})".format(gname, str(gid)))
curr_grp = self.conn.getGroupFromContext()
gid, gname = curr_grp.getId(), curr_grp.getName()
print("\nData for current group, {0} ({1}):-".format(gname, gid))
for pid, pname in self._ls_projects():
print(" Project: {0} ({1})".format(pname, str(pid)))
for did, dname in self._ls_datasets(pid):
print(" Dataset: {0} ({1})".format(dname, str(did)))
for iid, iname in self._ls_images(did):
print(" Image: {0} ({1})".format(iname, str(iid)))
# TODO, list orphaned Datasets and Images
def _ls_groups(self):
"""list groups (id, name) this session is a member of"""
groups = self.conn.getGroupsMemberOf()
return [(group.getId(), group.getName()) for group in groups]
def _ls_projects(self):
"""list projects (id, name) in the current session group"""
projs = self.conn.listProjects(self.conn.getUserId())
return [(proj.getId(), proj.getName()) for proj in projs]
def _ls_datasets(self, proj_id):
"""list datasets (id, name) within the project id given"""
dsets = self.conn.getObject("Project", proj_id).listChildren()
return [(dset.getId(), dset.getName()) for dset in dsets]
def _ls_images(self, dset_id):
"""list images (id, name) within the dataset id given"""
imgs = self.conn.getObject("Dataset", dset_id).listChildren()
return [(img.getId(), img.getName()) for img in imgs]
def chgrp(self, group_id):
"""
Change group for this session to the group_id given.
"""
self.conn.setGroupForSession(group_id)
def get(self, im_id, get_att=True):
"""
Download the specified image as an OME-TIFF to current directory,
with attachments also downloaded to folder: img_path + '_attachments'
Return : path to downloaded image
"""
img = self.conn.getObject("Image", oid=im_id)
img_name = self._unique_name(img.getName(), im_id)
img_path = os.path.join(os.getcwd(), img_name)
img_file = open(str(img_path + ".ome.tiff"), "wb")
fsize, blockgen = img.exportOmeTiff(bufsize=65536)
for block in blockgen:
img_file.write(block)
img_file.close()
fa_type = omero.model.FileAnnotationI
attachments = [ann for ann in img.listAnnotations()
#.........这里部分代码省略.........
示例8:
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import getUser [as 别名]
print """%s%s:%s Name:"%s" (owner=%s)""" % (
" " * indent,
obj.OMERO_CLASS,
obj.getId(),
obj.getName(),
obj.getOwnerOmeName())
# List all Projects available to the user currently logged in
# ===========================================================
# The only_owned=True parameter limits the Projects which are returned.
# If the parameter is omitted or the value is False, then all Projects
# visible in the current group are returned.
print "\nList Projects:"
print "=" * 50
my_expId = conn.getUser().getId()
for project in conn.listProjects(my_expId):
print_obj(project)
for dataset in project.listChildren():
print_obj(dataset, 2)
for image in dataset.listChildren():
print_obj(image, 4)
# Retrieve the datasets owned by the user currently logged in
# ===========================================================
# Here we create an omero.sys.ParametersI instance which we
# can use to filter the results that are returned. If we did
# not pass the params argument to getObjects, then all Datasets
# in the current group would be returned.
print "\nList Datasets:"
示例9: run
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import getUser [as 别名]
def run():
"""
Launch (remote) Priism ER deconvolution job on a list of images.
Results imported back into dataset of origin for each image.
"""
# Build GUI dialog for user to choose images & update parameters
client = script.client(
"ER_Deconvolution.py", "ER deconvolution",
script.String(
"Data_Type", optional=False,
grouping="1", values=[rstring('Image')], default="Image"),
script.List(
"IDs", optional=False,
description="image IDs (must have original .dv file!)",
grouping='2').ofType(rlong(0)),
script.Int(
"alpha", optional=False,
description='regularization parameter "alpha" - try 1000-10000',
grouping='3', default=job['par.alpha'], min=0),
script.Float(
"lambda f", optional=False,
description='smoothing parameter "lambda f" - try 0.1-1.0',
grouping='4', default=job['par.lamf'], min=0.0, max=1.0),
script.Int(
"iterations", optional=False,
description="number of iterations - try 10-100",
grouping='5', default=job['par.niter'], min=0),
version="0.99",
authors=["Graeme Ball"],
institutions=["Dundee Imaging Facility"],
contact="[email protected]"
)
try:
tempdir = None
input_image_ids = [int(n) for n in client.getInput("IDs", unwrap=True)]
job['par.alpha'] = client.getInput("alpha", unwrap=True)
job['par.lamf'] = client.getInput("lambda f", unwrap=True)
job['par.niter'] = client.getInput("iterations", unwrap=True)
conn = BlitzGateway(client_obj=client)
user = str(conn.getUser().getName())
group = str(conn.getGroupFromContext().getName())
sid = client.getSessionId()
# export images (must be .dv!) to shared / temp storage
tempdir = mktempdir(user, TEMP)
inputs = []
for iid in input_image_ids:
try:
path = export_original_dvfile(conn, iid, tempdir)
image = conn.getObject("Image", iid)
fail(image is None, "No such image, ID=%d" % iid)
did = image.getParent().getId()
#did = image.getDataset().getId()
inputs.append({'imageID': iid, 'path': path, 'datasetID': did})
except RuntimeError as e:
print "Fail: " + str(e)
jobs = []
for inp in inputs:
command = dict(job) # copy
command['inputs'] = [inp] # only 1 input image for this job
jobs.append(json.dumps([command])) # only 1 command for this job
# N.B. '.jobs' file format more flexible than needed here
# write jobs definition file (1 line json string per job)
jobs_filepath = os.path.join(tempdir, jobs_filename)
with open(jobs_filepath, 'w') as f:
f.writelines(["%s\n" % j for j in jobs])
# poll filesystem, checking for results
client.enableKeepAlive(KEEPALIVE_PULSE)
results_filepath = os.path.join(tempdir, results_filename)
result_count = 0 # results .json file grows as results appear
import_count = 0 # ensure we only attempt to import each result once
tstart = time.time()
while result_count < len(inputs) and (time.time() - tstart) < TIMEOUT:
fail(not conn.isConnected(), "Connection lost!")
alive_filepath = os.path.join(tempdir, alive_check_filename)
with open(alive_filepath, 'w') as f:
f.write("%f\n%d" % (time.time(), RESULTS_POLL_PULSE))
time.sleep(RESULTS_POLL_PULSE)
if os.path.exists(results_filepath):
with open(results_filepath, 'r') as fr:
results = fr.readlines() # 1 line json string per result
new_results = results[import_count:]
import_count += import_results(new_results, user, group,
sid, conn)
result_count = len(results)
if result_count < len(inputs):
print "Job timed out after %d seconds, %d results imported" % \
(TIMEOUT, import_count)
#.........这里部分代码省略.........