def run(self, *args): pause = random.random() event.wait(pause) self.cli = CLI() self.cli.loadplugins() self.con = self.cli.controls["admin"] self.cmp = self.con.ctx
def setup_method(self, method): self.cli = CLI() self.cli.register("db", DatabaseControl, "TEST") self.args = ["db"] dir = path(__file__) / ".." / ".." / ".." / ".." / ".." / ".." /\ ".." / "dist" # FIXME: should not be hard-coded dir = dir.abspath() cfg = dir / "etc" / "omero.properties" cfg = cfg.abspath() self.cli.dir = dir self.data = {} for line in cfg.text().split("\n"): line = line.strip() for x in ("version", "patch"): key = "omero.db." + x if line.startswith(key): self.data[x] = line[len(key) + 1:] self.file = create_path() self.script_file = "%(version)s__%(patch)s.sql" % self.data if os.path.isfile(self.script_file): os.rename(self.script_file, self.script_file + '.bak') assert not os.path.isfile(self.script_file) self.mox = Mox() self.mox.StubOutWithMock(getpass, 'getpass') self.mox.StubOutWithMock(__builtin__, "raw_input")
class TestLoadRenderingSettings: def setup_method(self): self.cli = CLI() self.cli.register("render", RenderControl, "TEST") self.render = self.cli.controls['render'] def test_none(self): with pytest.raises(NonZeroReturnCode): self.render._load_rendering_settings(None) def test_non_existing_file(self): with pytest.raises(NonZeroReturnCode) as e: self.render._load_rendering_settings(str(uuid.uuid4()) + '.yml') assert e.value.rv == 103 def test_no_channels(self, tmpdir): d = {'version': 1} f = write_yaml(d, tmpdir) with pytest.raises(NonZeroReturnCode) as e: self.render._load_rendering_settings(f) assert e.value.rv == 104 def test_bad_version(self, tmpdir): d = {'channels': {1: {'label': 'foo'}}} f = write_yaml(d, tmpdir) with pytest.raises(NonZeroReturnCode) as e: self.render._load_rendering_settings(f) assert e.value.rv == 124
class TestJvmCfg(object): """Test template files regeneration""" @pytest.fixture(autouse=True) def setup_method(self, tmpadmindir): self.cli = CLI() self.cli.register("admin", AdminControl, "TEST") self.cli.register("config", PrefsControl, "TEST") self.args = ["admin", "jvmcfg"] self.cli.dir = path(tmpadmindir) def testNoTemplatesGeneration(self): """Test no template files are generated by the jvmcfg subcommand""" # Test non-existence of configuration files for f in GRID_FILES: assert not os.path.exists(path(self.cli.dir) / "etc" / "grid" / f) for f in ETC_FILES: assert not os.path.exists(path(self.cli.dir) / "etc" / f) # Call the jvmcf command and test file genearation self.cli.invoke(self.args, strict=True) for f in GRID_FILES: assert not os.path.exists(path(self.cli.dir) / "etc" / "grid" / f) for f in ETC_FILES: assert not os.path.exists(path(self.cli.dir) / "etc" / f) @pytest.mark.parametrize("suffix", ["", ".blitz", ".indexer", ".pixeldata", ".repository"]) def testInvalidJvmCfgStrategy(self, suffix, tmpdir): """Test invalid JVM strategy configuration leads to CLI error""" key = "omero.jvmcfg.strategy%s" % suffix self.cli.invoke(["config", "set", key, "bad"], strict=True) with pytest.raises(NonZeroReturnCode): self.cli.invoke(self.args, strict=True)
def __init__(self, *args, **kwargs): self.__output = [] self.__error = [] self.__popen = [] self.__call = [] self.mox = mox.Mox() CLI.__init__(self, *args, **kwargs)
def setup_method(self, method): self.cli = CLI() self.cli.register("db", DatabaseControl, "TEST") self.args = ["db"] self.data = {} # FIXME: Use a different approach to get omero.db.version etc # No-longer stored in "omero.properties" if OMERODIR: dir = path(OMERODIR).abspath() cfg = dir / "etc" / "omero.properties" cfg = cfg.abspath() self.cli.dir = dir for line in cfg.text().split("\n"): line = line.strip() for x in ("version", "patch"): key = "omero.db." + x if line.startswith(key): self.data[x] = line[len(key) + 1:] self.file = create_path() self.script_file = "" if "version" in self.data and "patch" in self.data: self.script_file = "%(version)s__%(patch)s.sql" % self.data if os.path.isfile(self.script_file): os.rename(self.script_file, self.script_file + '.bak') assert not os.path.isfile(self.script_file) self.mox = Mox() self.mox.StubOutWithMock(getpass, 'getpass') self.mox.StubOutWithMock(__builtin__, "raw_input")
class TestJvmCfg(object): """Test template files regeneration""" @pytest.fixture(autouse=True) def setup_method(self, tmpadmindir): self.cli = CLI() self.cli.dir = path(tmpadmindir) self.cli.register("admin", AdminControl, "TEST") self.cli.register("config", PrefsControl, "TEST") self.args = ["admin", "jvmcfg"] def testNoTemplatesGeneration(self): """Test no template files are generated by the jvmcfg subcommand""" # Test non-existence of configuration files for f in GRID_FILES: assert not os.path.exists(path(self.cli.dir) / "etc" / "grid" / f) for f in ETC_FILES: assert not os.path.exists(path(self.cli.dir) / "etc" / f) # Call the jvmcf command and test file genearation self.cli.invoke(self.args, strict=True) for f in GRID_FILES: assert not os.path.exists(path(self.cli.dir) / "etc" / "grid" / f) for f in ETC_FILES: assert not os.path.exists(path(self.cli.dir) / "etc" / f) @pytest.mark.parametrize( 'suffix', ['', '.blitz', '.indexer', '.pixeldata', '.repository']) def testInvalidJvmCfgStrategy(self, suffix, tmpdir): """Test invalid JVM strategy configuration leads to CLI error""" key = "omero.jvmcfg.strategy%s" % suffix self.cli.invoke(["config", "set", key, "bad"], strict=True) with pytest.raises(NonZeroReturnCode): self.cli.invoke(self.args, strict=True)
def __init__(self, *args, **kwargs): self.__expect = [] self.__output = [] self.__error = [] self.__popen = [] self.__call = [] self.mox = mox.Mox() CLI.__init__(self, *args, **kwargs)
class T(Thread): def run(self, *args): pause = random.random() event.wait(pause) self.cli = CLI() self.cli.loadplugins() self.con = self.cli.controls["admin"] self.cmp = self.con.ctx
def testParametersParsedCorrectly(self): class TestControl(BaseControl): def __call__(self2, args): self.assertEquals("b",args["a"]) cli = CLI() cli.register("test", TestControl, "HELP") cli.invoke(["test","a=b"]) self.assertEquals(0, cli.rv)
def __init__(self, *args, **kwargs): CLI.__init__(self, *args, **kwargs) self.DIR = create_path(folder=True) self.REQRESP = {} self.STORE = MyStore(self.DIR) self.STORE.clear(testhost, testuser) self.register("s", SessionsControl, "TEST") self.controls["s"].FACTORY = lambda ignore: self.STORE assert self.STORE.count(testhost, testuser) == 0
def setup_method(self, method): self.cli = CLI() self.cli.register("import", ImportControl, "TEST") self.args = ["import"] dist_dir = path(__file__) / ".." / ".." / ".." / ".." / ".." / ".." /\ ".." / "dist" # FIXME: should not be hard-coded dist_dir = dist_dir.abspath() client_dir = dist_dir / "lib" / "client" self.args += ["--clientdir", client_dir]
class TestChgrp(object): def setup_method(self, method): self.cli = CLI() self.cli.register("chgrp", ChgrpControl, "TEST") self.args = ["chgrp"] def testHelp(self): self.args += ["-h"] self.cli.invoke(self.args, strict=True)
def testNoArgumentsDies(self): cli = CLI() cli.register("import", ImportControl, "HELP") try: cli.invoke([]) self.assert_(cli.rv != 0) except NonZeroReturnCode, nzrc: pass
def testLineParsedCorrectly(self): class TestControl(BaseControl): def __call__(self, args): if len(*args) != 2: raise Exc("Args was over parsed! %s" % args) cli = CLI() cli.register("test", TestControl, "HELP") cli.invoke(["test","a","a b c d e"]) self.assertEquals(0, cli.rv)
def check(obj): from omero.cli import CLI from omero.gateway import BlitzGateway cli = CLI() cli.loadplugins() cli.onecmd('login') try: gateway = BlitzGateway(client_obj=cli.get_client()) remote_obj = gateway.getObject( obj.type, attributes={"name": obj.name}) errors = [] if remote_obj.description != obj.description: errors.append("current:%s\nexpected:%s" % ( remote_obj.description, obj.description)) for al in remote_obj._getAnnotationLinks( ns="openmicroscopy.org/omero/client/mapAnnotation"): mapValue = al.child.mapValue kv_pairs = [(m.name, m.value) for m in mapValue] for i in range(len(kv_pairs)): if kv_pairs[i] != obj.map[i]: errors.append( "current:%s\nexpected:%s" % (kv_pairs[i], obj.map[i])) if not errors: log.info("No annotations mismatch detected") else: for e in errors: log.info("Found some annotations mismatch") print e finally: if cli: cli.close() gateway.close()
def check(self): from omero.cli import CLI from omero.gateway import BlitzGateway cli = CLI() cli.loadplugins() cli.onecmd('login -q') try: gateway = BlitzGateway(client_obj=cli.get_client()) for experiment in self.m["experiments"]: self.check_object(gateway, experiment, "Project") for experiment in self.m["screens"]: self.check_object(gateway, experiment, "Screen") if "map" in self.m: if self.m["experiments"]: study_type = "Project" else: study_type = "Screen" self.check_object(gateway, self.m, study_type) finally: if cli: cli.close() gateway.close()
def __init__(self, dir): """ :param dir: The server directory, can be None if you are not interacting with OMERO """ self.cli = None self.dir = None if dir: self.dir = os.path.abspath(dir) self.cli = CLI() self.cli.loadplugins()
def testLoad(self, tmpdir): tmpfile = tmpdir.join('test') tmpfile.write("foo") self.cli = CLI() self.cli.register("load", LoadControl, "help") with pytest.raises(NonZeroReturnCode): self.cli.invoke("load %s" % tmpfile, strict=True) self.cli.invoke("load -k %s" % tmpfile, strict=True) self.cli.invoke("load --keep-going %s" % tmpfile, strict=True)
def testLoad(self): tmp = create_path() tmp.write_text("foo") self.cli = CLI() self.cli.register("load", LoadControl, "help") with pytest.raises(NonZeroReturnCode): self.cli.invoke("load %s" % tmp, strict=True) self.cli.invoke("load -k %s" % tmp, strict=True) self.cli.invoke("load --keep-going %s" % tmp, strict=True)
class AbstractCLITest(ITest): def setup_method(self, method): super(AbstractCLITest, self).setup_method(method) self.cli = CLI() self.cli.register("sessions", SessionsControl, "TEST") def setup_mock(self): self.mox = Mox() def teardown_mock(self): self.mox.UnsetStubs() self.mox.VerifyAll()
def testLoad(self, tmpdir): tmpfile = tmpdir.join('test') tmpfile.write("foo") self.cli = CLI() self.cli.register("load", LoadControl, "help") # replace slashes, otherwise C:\\x becomes C:x tmpfile = tmpfile.strpath.replace("\\", "/") with pytest.raises(NonZeroReturnCode): self.cli.invoke("load %s" % tmpfile, strict=True) self.cli.invoke("load -k %s" % tmpfile, strict=True) self.cli.invoke("load --keep-going %s" % tmpfile, strict=True)
def as_stdout(path, readers="", extra_args=None): """Returns the import candidates for the given path. you can pass more arguments to the `import` command through the extra_args argument in the form of a list. ..code :: >>> as_stdout("/my/dir/with_tifs", extra_args=["--depth", "6"]) """ if extra_args is None: extra_args = [] path = _to_list(path) readers = str(readers) cli = CLI() cli.loadplugins() if readers: cli.invoke(["import", "-l"] + [ readers, ] + extra_args + ["-f"] + path) else: cli.invoke(["import"] + extra_args + ["-f"] + path) if cli.rv != 0: raise omero.InternalException( None, None, "'import -f' exited with a rc=%s. " "See console for more information" % cli.rv)
def setup_method(self, method): self.cli = CLI() self.cli.register("db", DatabaseControl, "TEST") self.args = ["db"] self.file = create_path() self.mox = mox.Mox() self.mox.StubOutWithMock(getpass, 'getpass') try: self.mox.StubOutWithMock(__builtins__, "raw_input") except AttributeError: # Python 3 self.mox.StubOutWithMock(builtins, "input")
def import_ln_s(self, host, port): """Import file using the ``--transfer=ln_s`` option. Parameters ---------- host : str Hostname of OMERO server in which images will be imported. port : int Port used to connect to OMERO.server. Returns ------- import_status : boolean True if OMERO import returns a 0 exit status, else False. """ cli = CLI() cli.register('import', ImportControl, '_') cli.register('sessions', SessionsControl, '_') cli.invoke([ 'import', '-k', self.conn.getSession().getUuid().val, '-s', host, '-p', str(port), '--transfer', 'ln_s', str(self.file_path) ]) if cli.rv == 0: self.imported = True print(f'Imported {self.file_path}') return True else: logging.error(f'Import of {self.file_path} has failed!') return False
def setup_method(self, method): self.cli = CLI() self.cli.register("db", DatabaseControl, "TEST") dir = path(__file__) / ".." / ".." / ".." / ".." / ".." / ".." /\ ".." / "dist" # FIXME: should not be hard-coded dir = dir.abspath() cfg = dir / "etc" / "omero.properties" cfg = cfg.abspath() self.cli.dir = dir self.data = {} for line in cfg.text().split("\n"): line = line.strip() for x in ("version", "patch"): key = "omero.db." + x if line.startswith(key): self.data[x] = line[len(key)+1:] self.file = create_path() self.script_file = "%(version)s__%(patch)s.sql" % self.data if os.path.isfile(self.script_file): os.rename(self.script_file, self.script_file + '.bak') assert not os.path.isfile(self.script_file) self.mox = Mox() self.mox.StubOutWithMock(getpass, 'getpass') self.mox.StubOutWithMock(__builtin__, "raw_input")
def setup_method(self, method): # # Non-temp directories ctxdir = path() / ".." / ".." / ".." / "dist" etc_dir = ctxdir / "etc" # List configuration files to backup self.cfg_files = {} for f in ['internal.cfg', 'master.cfg', 'ice.config']: self.cfg_files[f] = etc_dir / f for f in ['windefault.xml', 'default.xml', 'config.xml']: self.cfg_files[f] = etc_dir / 'grid' / f # Create temp files for backup tmp_dir = create_path(folder=True) self.tmp_cfg_files = {} for key in self.cfg_files.keys(): if self.cfg_files[key].exists(): self.tmp_cfg_files[key] = tmp_dir / key self.cfg_files[key].copy(self.tmp_cfg_files[key]) else: self.tmp_cfg_files[key] = None # Other setup self.cli = CLI() self.cli.dir = ctxdir self.cli.register("admin", AdminControl, "TEST") self.args = ["admin", "ports"]
class TestHql(object): def setup_method(self, method): self.cli = CLI() self.cli.register("hql", HqlControl, "TEST") self.args = ["hql"] def testHelp(self): self.args += ["-h"] self.cli.invoke(self.args, strict=True) @pytest.mark.parametrize("key", BLACKLISTED_KEYS) def testFilterBlacklist(self, key): output = self.cli.controls["hql"].filter({key: 1}) assert output == {} @pytest.mark.parametrize("key", ["rois", "groupExperimenterMap"]) def testFilterLoaded(self, key): output = self.cli.controls["hql"].filter({"_" + key + "Loaded": 1}) assert output == {} @pytest.mark.parametrize( ("value", "outcome"), [("owner=None;group=None", {}), ("owner=1", {"details": "owner=1"})]) def testFilterDetails(self, value, outcome): output = self.cli.controls["hql"].filter({"_details": value}) assert output == outcome @pytest.mark.parametrize("multi_value", [[0, 1]]) def testFilterMultiValue(self, multi_value): output = self.cli.controls["hql"].filter({'key': multi_value}) assert output == {} @pytest.mark.parametrize("empty_value", [None, [], {}]) def testFilterEmptyValue(self, empty_value): output = self.cli.controls["hql"].filter({'key': empty_value}) assert output == {} @pytest.mark.parametrize("value", WHITELISTED_VALUES) def testFilterWhitelist(self, value): output = self.cli.controls["hql"].filter({'key': value}) assert output == {'key': value} def testFilterStrip(self): output = self.cli.controls["hql"].filter({'_key': 1}) assert output == {'key': 1}
class TestHql(object): def setup_method(self, method): self.cli = CLI() self.cli.register("hql", HqlControl, "TEST") self.args = ["hql"] def testHelp(self): self.args += ["-h"] self.cli.invoke(self.args, strict=True) @pytest.mark.parametrize("key", BLACKLISTED_KEYS) def testFilterBlacklist(self, key): output = self.cli.controls["hql"].filter({key: 1}) assert output == {} @pytest.mark.parametrize("key", ["rois", "groupExperimenterMap"]) def testFilterLoaded(self, key): output = self.cli.controls["hql"].filter({"_" + key + "Loaded": 1}) assert output == {} @pytest.mark.parametrize(("value", "outcome"), [("owner=None;group=None", {}), ("owner=1", { "details": "owner=1" })]) def testFilterDetails(self, value, outcome): output = self.cli.controls["hql"].filter({"_details": value}) assert output == outcome @pytest.mark.parametrize("multi_value", [[0, 1]]) def testFilterMultiValue(self, multi_value): output = self.cli.controls["hql"].filter({'key': multi_value}) assert output == {} @pytest.mark.parametrize("empty_value", [None, [], {}]) def testFilterEmptyValue(self, empty_value): output = self.cli.controls["hql"].filter({'key': empty_value}) assert output == {} @pytest.mark.parametrize("value", WHITELISTED_VALUES) def testFilterWhitelist(self, value): output = self.cli.controls["hql"].filter({'key': value}) assert output == {'key': value} def testFilterStrip(self): output = self.cli.controls["hql"].filter({'_key': 1}) assert output == {'key': 1}
def testDropBoxArgs(self): class MockImportControl(ImportControl): def importer(this, args): self.assertEquals(args.server, "localhost") self.assertEquals(args.port, "4064") self.assertEquals(args.key, "b0742975-03a1-4f6d-b0ac-639943f1a147") self.assertEquals(args.errs, "/Users/cblackburn/omero/tmp/omero_cblackburn/6915/dropboxuUGl5rerr") self.assertEquals(args.file, "/Users/cblackburn/omero/tmp/omero_cblackburn/6915/dropboxaDCjQlout") cmd = ['-s', 'localhost', '-p', '4064', '-k', 'b0742975-03a1-4f6d-b0ac-639943f1a147'] cmd += ['import', '---errs=/Users/cblackburn/omero/tmp/omero_cblackburn/6915/dropboxuUGl5rerr'] cmd += ['---file=/Users/cblackburn/omero/tmp/omero_cblackburn/6915/dropboxaDCjQlout'] cmd += ['--', '/OMERO/DropBox/root/tinyTest.d3d.dv'] cli = CLI() cli.register("import", MockImportControl, "HELP") cli.invoke(cmd)
def main(): parser = Parser() parser.add_login_arguments() parser.add_argument("--orphans", action="store_true") parser.add_argument("--unknown", action="store_true") parser.add_argument("--search", action="store_true") parser.add_argument("--images", action="store_true") parser.add_argument("--copy-from", type=long, default=None) parser.add_argument("--copy-type", default="Image") parser.add_argument("--copy-to", type=long, default=None) parser.add_argument("screen", nargs="?") ns = parser.parse_args() cli = CLI() cli.loadplugins() client = cli.conn(ns) try: query = client.sf.getQueryService() if ns.orphans: orphans(query) elif ns.unknown: unknown(query) elif ns.search: search = client.sf.createSearchService() check_search(query, search) elif not ns.screen: stat_screens(query) else: if ns.copy_to: copy(client, ns.copy_from, ns.copy_type, ns.copy_to) else: for x in stat_plates(query, ns.screen, ns.images): print x finally: cli.close()
class External(object): """ Manages the execution of shell and OMERO CLI commands """ def __init__(self, dir): """ :param dir: The server directory, can be None if you are not interacting with OMERO """ self.cli = None self.dir = None if dir: self.dir = os.path.abspath(dir) self.cli = CLI() self.cli.loadplugins() def get_config(self, raise_missing=True): """ Returns a dictionary of all OMERO config properties """ configxml = os.path.join(self.dir, 'etc', 'grid', 'config.xml') try: configobj = ConfigXml(configxml, read_only=True) except Exception as e: log.warning('config.xml not found: %s', e) if raise_missing: raise return {} cfgdict = configobj.as_map() configobj.close() return cfgdict def update_config(self, newcfg): cfg = ConfigXml(os.path.join(self.dir, 'etc', 'grid', 'config.xml')) for k, v in newcfg.items(): cfg[k] = v cfg.close() def omero_cli(self, command): """ Runs an OMERO CLI command """ assert isinstance(command, list) log.info('Running omero: %s', ' '.join(command)) return self.cli.invoke(command)
class TestReadChannels: def setup_method(self): self.cli = CLI() self.cli.register("render", RenderControl, "TEST") self.render = self.cli.controls['render'] def test_non_integer_channel(self): d = {'channels': {'GFP': {'label': 'foo'}}} with pytest.raises(NonZeroReturnCode) as e: self.render._read_channels(d) assert e.value.rv == 105 @pytest.mark.parametrize('key', ['min', 'max', 'start', 'end']) def test_float_keys(self, key): d = {'channels': {1: {key: 'foo'}}} with pytest.raises(NonZeroReturnCode) as e: self.render._read_channels(d) assert e.value.rv == 105
def check(self, update=False): from omero.cli import CLI from omero.gateway import BlitzGateway cli = CLI() cli.loadplugins() cli.onecmd('login -q') try: gateway = BlitzGateway(client_obj=cli.get_client()) self.check_study(gateway, update=update) finally: if cli: cli.close() gateway.close()
def main(): parser = Parser() parser.add_login_arguments() parser.add_argument("--orphans", action="store_true") parser.add_argument("--unknown", action="store_true") parser.add_argument("--search", action="store_true") parser.add_argument("--images", action="store_true") parser.add_argument("--release", default="TODO", help="The name of the release, e.g. 'prod88'") parser.add_argument( "--disable-fsusage", action="store_true", help=("Disable fs usage file size and counts. " "Use this flag if the script is taking too long.")) parser.add_argument( "--format", default="tsv", help=( "Output format, includes 'string', 'csv', 'tsv' (default), and " "'json'. " "'tsv' can be appended to the IDR studies.csv file with no further " "processing. " "All other formats include headers and totals. " "'string' is the most human readable (fixed width columns). ")) parser.add_argument("studies", nargs='*', help="Studies to be processed, default all (idr*)") parser.add_argument('-v', '--verbose', action='count', default=0) ns = parser.parse_args() levels = [logging.WARNING, logging.INFO, logging.DEBUG] level = levels[min(len(levels) - 1, ns.verbose)] logging.basicConfig(level=level, format="%(asctime)s %(levelname)s %(message)s") cli = CLI() cli.loadplugins() client = cli.conn(ns) try: query = client.sf.getQueryService() if ns.orphans: orphans(query) elif ns.unknown: unknown(query, ns.studies) elif ns.search: search = client.sf.createSearchService() check_search(query, search) else: df = stat_top_level(client, ns.studies, release=ns.release, fsusage=(not ns.disable_fsusage), append_totals=(ns.format != 'tsv')) print_stats(df, ns.format) finally: cli.close()
def as_stdout(path, readers=""): path = _to_list(path) readers = str(readers) cli = CLI() cli.loadplugins() if readers: cli.invoke(["import", "-l", readers, "-f"] + path) else: cli.invoke(["import", "-f"] + path) if cli.rv != 0: raise omero.InternalException( None, None, "'import -f' exited with a rc=%s. " "See console for more information" % cli.rv)
def testDropBoxArgs(self): class MockImportControl(ImportControl): def importer(this, args): self.assertEquals(args.server, "localhost") self.assertEquals(args.port, "4064") self.assertEquals(args.key, "b0742975-03a1-4f6d-b0ac-639943f1a147") self.assertEquals( args.errs, "/Users/cblackburn/omero/tmp/omero_cblackburn/6915/dropboxuUGl5rerr" ) self.assertEquals( args.file, "/Users/cblackburn/omero/tmp/omero_cblackburn/6915/dropboxaDCjQlout" ) cmd = [ '-s', 'localhost', '-p', '4064', '-k', 'b0742975-03a1-4f6d-b0ac-639943f1a147' ] cmd += [ 'import', '---errs=/Users/cblackburn/omero/tmp/omero_cblackburn/6915/dropboxuUGl5rerr' ] cmd += [ '---file=/Users/cblackburn/omero/tmp/omero_cblackburn/6915/dropboxaDCjQlout' ] cmd += ['--', '/OMERO/DropBox/root/tinyTest.d3d.dv'] cli = CLI() cli.register("import", MockImportControl, "HELP") cli.invoke(cmd)
def as_stdout(path, readers=""): path = _to_list(path) readers = str(readers) cli = CLI() cli.loadplugins() if readers: cli.invoke(["import", "-l", readers, "-f"]+path) else: cli.invoke(["import", "-f"]+path) if cli.rv != 0: raise omero.InternalException(None, None, "'import -f' exited with a rc=%s. See console for more information" % cli.rv)
class TestCli(object): def testMultipleLoad(self): """ In DropBox, the loading of multiple CLIs seems to lead to the wrong context being assigned to some controls. See #4749 """ import random from threading import Thread, Event event = Event() class T(Thread): def run(self, *args): pause = random.random() event.wait(pause) self.cli = CLI() self.cli.loadplugins() self.con = self.cli.controls["admin"] self.cmp = self.con.ctx threads = [T() for x in range(20)] for t in threads: t.start() event.set() for t in threads: t.join() assert len(threads) == len(set([t.cli for t in threads])) assert len(threads) == len(set([t.con for t in threads])) assert len(threads) == len(set([t.cmp for t in threads])) def testLoad(self, tmpdir): tmpfile = tmpdir.join('test') tmpfile.write("foo") self.cli = CLI() self.cli.register("load", LoadControl, "help") # replace slashes, otherwise C:\\x becomes C:x tmpfile = tmpfile.strpath.replace("\\", "/") with pytest.raises(NonZeroReturnCode): self.cli.invoke("load %s" % tmpfile, strict=True) self.cli.invoke("load -k %s" % tmpfile, strict=True) self.cli.invoke("load --keep-going %s" % tmpfile, strict=True)
class TestCli(object): def testMultipleLoad(self): """ In DropBox, the loading of multiple CLIs seems to lead to the wrong context being assigned to some controls. See #4749 """ import random from threading import Thread, Event event = Event() class T(Thread): def run(self, *args): pause = random.random() event.wait(pause) self.cli = CLI() self.cli.loadplugins() self.con = self.cli.controls["admin"] self.cmp = self.con.ctx threads = [T() for x in range(20)] for t in threads: t.start() event.set() for t in threads: t.join() assert len(threads) == len(set([t.cli for t in threads])) assert len(threads) == len(set([t.con for t in threads])) assert len(threads) == len(set([t.cmp for t in threads])) def testLoad(self): tmp = create_path() tmp.write_text("foo") self.cli = CLI() self.cli.register("load", LoadControl, "help") with pytest.raises(NonZeroReturnCode): self.cli.invoke("load %s" % tmp, strict=True) self.cli.invoke("load -k %s" % tmp, strict=True) self.cli.invoke("load --keep-going %s" % tmp, strict=True)
def main(): parser = Parser() parser.add_login_arguments() parser.add_argument("file") parser.add_argument("object") ns = parser.parse_args() cli = CLI() cli.loadplugins() client = cli.conn(ns) try: screen_metadata(client, ns.file, ns.object) finally: cli.close()
class TestTag(object): def setup_method(self, method): self.cli = CLI() self.cli.register("fs", FsControl, "TEST") self.args = ["fs"] def testHelp(self): self.args += ["-h"] self.cli.invoke(self.args, strict=True) @pytest.mark.parametrize('subcommand', FsControl().get_subcommands()) def testSubcommandHelp(self, subcommand): self.args += [subcommand, "-h"] self.cli.invoke(self.args, strict=True)
class TestUser(object): def setup_method(self, method): self.cli = CLI() self.cli.register("user", UserControl, "TEST") self.args = ["user"] # Help subcommands # ======================================================================== def testHelp(self): self.args += ["-h"] self.cli.invoke(self.args, strict=True) @pytest.mark.parametrize("subcommand", UserControl().get_subcommands()) def testSubcommandHelp(self, subcommand): self.args += [subcommand, "-h"] self.cli.invoke(self.args, strict=True)
class TestDownload(object): def setup_method(self, method): self.cli = CLI() self.cli.register("download", DownloadControl, "TEST") self.args = ["download"] def testHelp(self): self.args += ["-h"] self.cli.invoke(self.args, strict=True) @pytest.mark.parametrize( 'bad_input', ['-1', 'OriginalFile:-1', 'FileAnnotation:-1', 'Image:-1']) def testInvalidInput(self, bad_input): self.args += [bad_input, '-'] with pytest.raises(NonZeroReturnCode): self.cli.invoke(self.args, strict=True)
idx = server.rindex("@") return server[idx+1:], server[0:idx] # server, user which may also contain an @ except ValueError: return server, None def _get_server(self, store): defserver = store.last_host() rv = self.ctx.input("Server: [%s]" % defserver) if not rv: return defserver, None else: return self._parse_conn(rv) def _get_username(self, defuser): if defuser is None: defuser = get_user("root") rv = self.ctx.input("Username: [%s]" % defuser) if not rv: return defuser else: return rv try: register("sessions", SessionsControl, HELP) except NameError: if __name__ == "__main__": cli = CLI() cli.register("sessions", SessionsControl, HELP) cli.invoke(sys.argv[1:])
config["omero.config.upgraded"] = "4.2.0" def handle_line(self, line, config, keys): line = line.strip() if not line or line.startswith("#"): return None if line.endswith("\\"): return line[:-1] parts = line.split("=", 1) if len(parts[0]) == 0: return if len(parts) == 1: parts.append("") if keys and parts[0] in keys: self.ctx.die(502, "Duplicate property: %s (%s => %s)"\ % (parts[0], config[parts[0]], parts[1])) keys.append(parts[0]) config[parts[0]] = parts[1] def old(self, args): self.ctx.out(getprefs(args.target, str(self.ctx.dir / "lib"))) try: register("config", PrefsControl, HELP) except NameError: if __name__ == "__main__": cli = CLI() cli.register("config", PrefsControl, HELP) cli.invoke(sys.argv[1:])
rv = list() mapped.append(rv) if not s.isLoaded(): rv.append("") rv.append("id=%s" % s.id.val) rv.append("") rv.append("") rv.append("") rv.append("insufficient privileges") else: rv.append(s.node.id) rv.append(s.uuid) rv.append(s.started) rv.append(s.owner.omeName) if s.userAgent is None: rv.append("") else: rv.append(s.userAgent) if client.getSessionId() == s.uuid.val: rv.append("current session") else: rv.append("") self.ctx.controls["hql"].display(mapped, ("node", "session", "started", "owner", "agent", "notes")) try: register("admin", AdminControl, HELP) except NameError: if __name__ == "__main__": cli = CLI() cli.register("admin", AdminControl, HELP) cli.invoke(sys.argv[1:])
def invoke(self, *args): CLI.invoke(self, *args, strict = True)
for attr_name, arg_name in java_args.items(): arg_value = getattr(args, attr_name) if arg_value: if isinstance(arg_name, tuple): arg_name = arg_name[0] login_args.append("%s=%s" % (arg_name, arg_value)) else: login_args.append(arg_name) if isinstance(arg_value, (str, unicode)): login_args.append(arg_value) a = self.COMMAND + login_args + args.path p = omero.java.popen(a, debug=False, xargs=xargs, stdout=out, stderr=err) self.ctx.rv = p.wait() class TestEngine(ImportControl): COMMAND = [TEST_CLASS] try: register("import", ImportControl, HELP, epilog=EXAMPLES) register("testengine", TestEngine, TESTHELP) except NameError: if __name__ == "__main__": cli = CLI() cli.register("import", ImportControl, HELP, epilog=EXAMPLES) cli.register("testengine", TestEngine, TESTHELP) cli.invoke(sys.argv[1:])
def setup_method(self, method): self.cli = CLI() self.cli.register("fs", FsControl, "TEST") self.args = ["fs"]