本文整理汇总了Python中omero.gateway.BlitzGateway.connect方法的典型用法代码示例。如果您正苦于以下问题:Python BlitzGateway.connect方法的具体用法?Python BlitzGateway.connect怎么用?Python BlitzGateway.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类omero.gateway.BlitzGateway
的用法示例。
在下文中一共展示了BlitzGateway.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_as_program
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def run_as_program():
"""
Testing function to allow the script to be called outside of the OMERO
scripting environment. The connection details and image ID must be valid.
"""
import getpass
HOST = 'localhost'
PORT = 4064
USERNAME = raw_input("OMERO username: ")
PASSWORD = getpass.getpass("OMERO password: ")
h = raw_input("OMERO host (%s): " % HOST)
if h:
HOST = h
p = raw_input("OMERO port (%d): " % PORT)
if p:
PORT = p
conn = BlitzGateway(USERNAME, PASSWORD, host=HOST, port=PORT)
conn.connect()
conn.keepAlive()
params = create_script_defaults()
params[PARAM_DATATYPE] = 'Image'
params[PARAM_IDS] = [51]
# params[PARAM_DATATYPE] = 'Dataset'
# params[PARAM_IDS] = [2]
params[PARAM_UPLOAD_RESULTS] = True
params[PARAM_EMAIL_RESULTS] = True
params[PARAM_EMAIL] = ADMIN_EMAIL
count = run(conn, params)
if count >= 0:
print ("Processed %d image%s" %
(count, count != 1 and 's' or ''))
示例2: testChgrpAsync
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def testChgrpAsync(self):
"""
Try to reproduce "race condition" bugs seen in web #8037 (fails to reproduce)
"""
image = self.image
ctx = self.gateway.getAdminService().getEventContext()
uuid = ctx.sessionUuid
self.loginAsAdmin()
gid = self.gateway.createGroup("chgrp-test-%s" % uuid, member_Ids=[ctx.userId], perms=COLLAB)
self.loginAsAuthor()
original_group = ctx.groupId
self.assertNotEqual(None, self.gateway.getObject("Image", image.id))
# Do the Chgrp
rsp = self.doChange("Image", image.getId(), gid, return_complete=False)
while rsp.getResponse() is None:
# while waiting, try various things to reproduce race condition seen in web.
img = self.gateway.getObject("Image", image.id)
c = BlitzGateway()
c.connect(sUuid=uuid)
#self.gateway.setGroupForSession(gid)
# Image should no-longer be available in current group
self.assertEqual(None, self.gateway.getObject("Image", image.id), "Image should not be available in original group")
# Switch to new group - confirm that image is there.
self.gateway.setGroupForSession(gid)
img = self.gateway.getObject("Image", image.id)
self.assertNotEqual(None, img, "Image should be available in new group")
self.assertEqual(img.getDetails().getGroup().id, gid, "Image group.id should match new group")
示例3: test_unicode_password
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def test_unicode_password(self):
with pytest.raises(Ice.ConnectionRefusedException):
gateway = BlitzGateway(
username='user', passwd=u'ążźćółę',
host='localhost', port=65535
)
gateway.connect()
示例4: run_as_program
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def run_as_program():
"""
Testing function to allow the script to be called outside of the OMERO
scripting environment. The connection details and image ID must be valid.
"""
import getpass
HOST = 'localhost'
PORT = 4064
USERNAME = raw_input("OMERO username: ")
PASSWORD = getpass.getpass("OMERO password: ")
h = raw_input("OMERO host (%s): " % HOST)
if h:
HOST = h
p = raw_input("OMERO port (%d): " % PORT)
if p:
PORT = p
conn = BlitzGateway(USERNAME, PASSWORD, host=HOST, port=PORT)
conn.connect()
params = {}
params[PARAM_IDS] = [1]
params[PARAM_DATATYPE] = "Image"
params[PARAM_ALL_IMAGES] = True
params[PARAM_READABLE] = True
(count, ok) = run(conn, params)
print (summary(count, ok))
示例5: main
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def main(argv):
parser = make_parser()
args = parser.parse_args(argv[1:])
if not args.out_file:
args.out_file = "map_screen_%d.tsv" % args.screen_id
passwd = getpass.getpass()
conn = BlitzGateway(
args.user, passwd, host=args.host, port=args.port, group=args.group
)
conn.connect()
screen = conn.getObject("Screen", args.screen_id)
print "writing to %s" % args.out_file
print "SCREEN: %s" % screen.name
with open(args.out_file, "w") as fo:
fo.write("PLATE\tSERIES\tWELL\tFIELD\tImageID\tWellID\n")
for p in screen.listChildren():
rows = []
print " plate: %s" % p.name
for w in p.listChildren():
n_fields = sum(1 for _ in w.listChildren())
for i in xrange(n_fields):
img = w.getImage(i)
well_tag = "%s%02d" % (LETTERS[w.row], w.column + 1)
rows.append((
p.name, img.getSeries(), well_tag, i + 1, img.id, w.id
))
rows.sort(key=itemgetter(1))
rows.sort()
for r in rows:
fo.write("%s\t%d\t%s\t%d\t%d\t%d\n" % r)
示例6: create_containers
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [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
示例7: connect_to_omero
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [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
示例8: connect_to_omero
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def connect_to_omero(uname, passwd):
conn = BlitzGateway(uname, passwd, host=HOST, port=PORT)
connected = conn.connect()
if not connected:
sys.stderr.write("Error : Connection not available, please check your user name and password.\n")
return None
return conn
示例9: connect
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def connect( server, port, username, password ):
'''
Helper method that connects to an OMERO.searcher server.
@param server
@param port
@param username
@param password
@returns connection
'''
try:
conn = BlitzGateway( username, password, host=server, port=int(port))
conn.connect()
return conn
except:
return None
示例10: create_containers
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [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
示例11: connect_to_omero
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def connect_to_omero():
conn = BlitzGateway(USERNAME, PASSWORD, host=HOST, port=PORT)
connected = conn.connect()
if not connected:
import sys
sys.stderr.write("Error : Connection not available, please check your user name and password.\n")
return None
return conn
示例12: omero_login
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def omero_login(user, passwd, host, port):
"""Establish the connection to an OMERO server.
Parameters
==========
user : str - OMERO user name (e.g. "demo_user_01")
passwd : str - OMERO user password
host : str - OMERO server hostname to connect to
port : int - OMERO server port number (e.g. 4064)
Returns
=======
conn : omero.gateway._BlitzGateway - OMERO connection object
"""
conn = BlitzGateway(user, passwd, host=host, port=port, secure=True,
useragent="HRM-OMERO.connector")
conn.connect()
return conn
示例13: temporary_connection
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def temporary_connection():
temp_client = omero.client()
omeroProperties = temp_client.getProperties().getPropertiesForPrefix('omero')
# Configuration
HOST = omeroProperties.get('omero.host', 'localhost')
PORT = omeroProperties.get('omero.port', 4064)
USERNAME = omeroProperties.get('omero.user')
PASSWORD = omeroProperties.get('omero.pass')
temp_conn = BlitzGateway(USERNAME, PASSWORD, host=HOST, port=PORT)
connected = temp_conn.connect()
return temp_client,temp_conn
示例14: connect_base
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [as 别名]
def connect_base():
"""Establish the base connection to OMERO.
Returns the connection in the context defined in localconfig.
"""
# establish the base connection with an admin account
su_conn = BlitzGateway(SU_USER, SU_PASS, host=HOST, port=PORT)
if su_conn.connect() is False:
raise RuntimeError('Connection to OMERO failed, check settings!')
log.debug("Successfully connected to OMERO.")
return su_conn
示例15: create_screen
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import connect [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