Package omeroweb :: Package webadmin :: Module webadmin_utils
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.webadmin.webadmin_utils

 1  import logging 
 2  import traceback 
 3  import re 
 4  from omero_version import omero_version 
 5   
 6  from webclient.webclient_gateway import OmeroWebGateway 
 7  from omeroweb.webgateway.views import _createConnection 
 8   
 9  logger = logging.getLogger('admin-utils') 
10   
11 -def getGuestConnection(host, port):
12 conn = None 13 guest = "guest" 14 try: 15 # do not store connection on connectors 16 conn = _createConnection('', host=host, port=port, username=guest, passwd=guest, secure=True, useragent="OMERO.web") 17 if conn is not None: 18 logger.info("Have connection as Guest") 19 else: 20 logger.info("Open connection is not available") 21 except Exception, x: 22 logger.error(traceback.format_exc()) 23 return conn
24
25 -def _checkVersion(host, port):
26 rv = False 27 conn = getGuestConnection(host, port) 28 if conn is not None: 29 try: 30 agent = conn.getServerVersion() 31 regex = re.compile("^.*?[-]?(\\d+[.]\\d+([.]\\d+)?)[-]?.*?$") 32 33 agent_cleaned = regex.match(agent).group(1) 34 agent_split = agent_cleaned.split(".") 35 36 local_cleaned = regex.match(omero_version).group(1) 37 local_split = local_cleaned.split(".") 38 39 rv = (agent_split == local_split) 40 logger.info("Client version: '%s'; Server version: '%s'"% (omero_version, agent)) 41 except Exception, x: 42 logger.error(traceback.format_exc()) 43 return rv
44
45 -def _isServerOn(host, port):
46 conn = getGuestConnection(host, port) 47 if conn is not None: 48 try: 49 conn.getServerVersion() 50 return True 51 except Exception, x: 52 logger.error(traceback.format_exc()) 53 return False
54
55 -def upgradeCheck():
56 # upgrade check: 57 # ------------- 58 # On each startup OMERO.web checks for possible server upgrades 59 # and logs the upgrade url at the WARNING level. If you would 60 # like to disable the checks, change the following to 61 # 62 # if False: 63 # 64 # For more information, see 65 # http://trac.openmicroscopy.org.uk/omero/wiki/UpgradeCheck 66 # 67 try: 68 from omero.util.upgrade_check import UpgradeCheck 69 check = UpgradeCheck("web") 70 check.run() 71 if check.isUpgradeNeeded(): 72 logger.error("Upgrade is available. Please visit http://trac.openmicroscopy.org.uk/omero/wiki/MilestoneDownloads.\n") 73 else: 74 logger.error("Up to date.\n") 75 except Exception, x: 76 logger.error("Upgrade check error: %s" % x)
77
78 -def toBoolean(val):
79 """ 80 Get the boolean value of the provided input. 81 82 If the value is a boolean return the value. 83 Otherwise check to see if the value is in 84 ["false", "f", "no", "n", "none", "0", "[]", "{}", "" ] 85 and returns True if value is not in the list 86 """ 87 88 if val is True or val is False: 89 return val 90 91 falseItems = ["false", "f", "no", "n", "none", "0", "[]", "{}", "" ] 92 93 return not str( val ).strip().lower() in falseItems
94