def main(): import argparse parser = argparse.ArgumentParser(description=""" Display a table of files in a Firefly window """) parser.add_argument('topdir', help='top-level directory to search') parser.add_argument('pattern', help='filename pattern for search') parser.add_argument('--norecursion', help='do not recursively search topdir', action='store_true') parser.add_argument('--host', help='host address for Firefly', default='localhost') parser.add_argument('--port', help='port for Firefly', default='8080') parser.add_argument('--base', help='base.for Firefly', default='firefly') parser.add_argument('--channel', help='channel name for websocket', default=None) parser.add_argument('--printurl', help='print browser url instead of' + ' attempting to launch browser', action='store_true') args = parser.parse_args() topdir = args.topdir pattern = args.pattern host = args.host port = args.port basedir = args.base channel = args.channel printurl = args.printurl recursion = not args.norecursion fc = firefly_client.FireflyClient('{}:{}'.format(host, port), basedir=basedir, channel=channel, html_file='slate.html') if printurl: print('Firefly url is {}'.format(fc.get_firefly_url())) else: fc.launch_browser() tbl_val, metainfo = filetable_to_firefly(fc, topdir, pattern, recursive=recursion) r = fc.add_cell(0, 0, 1, 2, 'tables', 'main') fc.show_table(tbl_val, meta=metainfo) r = fc.add_cell(0, 1, 1, 2, 'tableImageMeta', 'image-meta') fc.show_image_metadata(viewer_id=r['cell_id'])
def __init__(self, display, verbose=False, host="localhost", port=8080, name="afw", basedir="firefly", *args, **kwargs): virtualDevice.DisplayImpl.__init__(self, display, verbose) if self.verbose: print("Opening firefly device %s" % (self.display.frame if self.display else "[None]")) global _fireflyClient if not _fireflyClient: try: _fireflyClient = firefly_client.FireflyClient("%s:%d" % (host, port), channel=name, basedir=basedir, **kwargs) except Exception as e: raise RuntimeError("Unable to connect websocket %s:%d: %s" % (host, port, e)) if (host == "localhost"): _fireflyClient.launch_browser() try: _fireflyClient.add_listener(self.__handleCallbacks) except Exception as e: raise RuntimeError( "Cannot add listener. Browser must be connected" + "to %s:%d/%s/;wsch=%s: %s" % (host, port, basedir, name, e)) self._isBuffered = False self._regions = [] self._regionLayerId = None self._fireflyFitsID = None self._fireflyMaskOnServer = None self._maskIds = [] self._maskDict = {}
def test_connect(self): """A connection test on an unused socket""" port = get_unused_port() with self.assertRaises(ValueError): firefly_client.FireflyClient('localhost:{}'.format(port))
def test_token_http(self): """A token cannot be used with a non-SSL url""" with self.assertRaises(ValueError): firefly_client.FireflyClient('http://127.0.0.1:8080/firefly', token='abcdefghij')