def run(self, args): if not os.path.exists(args.file): self.ctx.die(670, "No such file: %s" % args.file) else: client = self.ctx.conn(args) store = SessionsStore() srv, usr, uuid, port = store.get_current() props = store.get(srv, usr, uuid) from omero.scripts import parse_file from omero.util.temp_files import create_path path = create_path() text = """ omero.host=%(omero.host)s omero.user=%(omero.sess)s omero.pass=%(omero.sess)s """ path.write_text(text % props) params = parse_file(args.file) m = self._parse_inputs(args, params) for k, v in list(m.items()): if v is not None: client.setInput(k, v) p = self.ctx.popen([sys.executable, args.file], stdout=sys.stdout, stderr=sys.stderr, ICE_CONFIG=str(path)) p.wait() if p.poll() != 0: self.ctx.die(p.poll(), "Execution failed.")
def __init__(self, parent=None): super().__init__(parent) self.store = SessionsStore() self.destroyed.connect(self.close) atexit.register(self.close) self.worker: Optional[WorkerBase] = None self._next_worker: Optional[WorkerBase] = None
def get_params_from_session(): store = SessionsStore() session_props = store.get_current() host, username, suuid, port = session_props # If there is no suuid, there is no session if suuid is None: return None return {'host': host, 'username': username, 'suuid': suuid, 'port': port}
def __init__(self, config_file=None): # Set the connection as not established self.conn = None self.SUUID = None self.HOST = None self.PORT = None self.USERNAME = None self.PASSWORD = None # If config_file not specified, first see if there's an active OMERO # CLI session. if config_file is None: store = SessionsStore() session_props = store.get_current() self.HOST, self.USERNAME, self.SUUID, self.PORT = session_props # config_file specified, or no active session. Continue with reading # connection params from the config file. if config_file is not None or self.SUUID is None: # Normalize file path. if config_file is None: config_file = '~/.omero/config' config_file = os.path.expanduser(config_file) # Check config file exists. if not (os.path.exists(config_file) and os.path.isfile(config_file)): sys.stderr.write('No active OMERO CLI session and ' 'configuration file {} does not ' 'exist\n'.format(config_file)) sys.exit(1) # Check permisisons on config file. if os.stat(config_file).st_mode & 0077: sys.stderr.write('Configuration file contains private ' 'credentials and must not be accessible by ' 'other users. Please run:\n\n' ' chmod 600 {}\n\n'.format(config_file)) sys.exit(1) # Read the credentials file. config = ConfigParser.RawConfigParser() config.read(config_file) self.HOST = config.get('OMEROCredentials', 'host') self.PORT = config.getint('OMEROCredentials', 'port') self.USERNAME = config.get('OMEROCredentials', 'username') self.PASSWORD = config.get('OMEROCredentials', 'password')
def timer(func): """Print the runtime of the decorated function""" @functools.wraps(func) def wrapper_timer(*args, **kwargs): start_time = time.perf_counter() # 1 value = func(*args, **kwargs) end_time = time.perf_counter() # 2 run_time = end_time - start_time # 3 logger.debug(f"Finished {func.__name__!r} in {run_time:.4f} secs") return value return wrapper_timer STORE = SessionsStore() def parse_omero_url(url): m = re.search( r"https?://(?P<host>[^/]+).*/webclient/\?show=(?P<type>[a-z]+)-(?P<id>[0-9]+)", url, ) if m: return m.groupdict() @timer def get_gateway(path, host=None): gateway = QGateWay() if host: