Skip to content

Commit 4a1c05c

Browse files
committed
changes to work with recent versions of firefly_client
* add pause before uploading table * add FIREFLY_URL environment variable as the default * print a message while files are being pattern-matched * reformat single-quotes to double-quotes
1 parent 9af4e61 commit 4a1c05c

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

examples/filetable.py

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@ def filetable_to_firefly(ffclient, topdir, pattern, recursive=True):
1515
ffclient: firefly_client.FireflyClient
1616
Instance of FireflyClient connected to a Firefly server
1717
18-
topdir: 'str'
18+
topdir: "str"
1919
pathname for directory to search
2020
21-
pattern: 'str'
22-
filename pattern to search for, e.g. '*.fits'
21+
pattern: "str"
22+
filename pattern to search for, e.g. "*.fits"
2323
2424
recursive: `bool`
2525
Search all subdirectories recursively (default=True)
2626
2727
Returns:
2828
--------
29-
tbl_val: 'str'
29+
tbl_val: "str"
3030
Descriptor of table that was uploaded to the Firefly server
3131
3232
metadict: `dict`
3333
Dictionary of metadata items
3434
3535
"""
36-
filelist = glob(topdir+'/**/' + pattern, recursive=recursive)
37-
metadict = {'datasource': 'path'}
38-
with tempfile.NamedTemporaryFile(mode='w+t',
36+
filelist = glob(topdir+"/**/" + pattern, recursive=recursive)
37+
metadict = {"datasource": "path"}
38+
with tempfile.NamedTemporaryFile(mode="w+t",
3939
delete=False,
40-
suffix='.csv') as fd:
40+
suffix=".csv") as fd:
4141
csv_writer = csv.writer(fd)
42-
csv_writer.writerow(['number','name','path'])
42+
csv_writer.writerow(["number","name","path"])
4343
for i, path in enumerate(filelist):
4444
csv_writer.writerow([i, os.path.basename(path),
45-
'file://'+path])
45+
"file://"+path])
4646

4747
tbl_val = ffclient.upload_file(fd.name)
4848
os.remove(fd.name)
@@ -55,40 +55,45 @@ def main():
5555
parser = argparse.ArgumentParser(description="""
5656
Display a table of files in a Firefly window
5757
""")
58-
parser.add_argument('topdir', help='top-level directory to search')
59-
parser.add_argument('pattern', help='filename pattern for search')
60-
parser.add_argument('--norecursion', help='do not recursively search topdir',
61-
action='store_true')
62-
parser.add_argument('--host', help='host address for Firefly',
63-
default='localhost')
64-
parser.add_argument('--port', help='port for Firefly', default='8080')
65-
parser.add_argument('--base', help='base.for Firefly', default='firefly')
66-
parser.add_argument('--channel', help='channel name for websocket',
58+
parser.add_argument("topdir", help="top-level directory to search")
59+
parser.add_argument("pattern", help="filename pattern for search")
60+
parser.add_argument("--norecursion", help="do not recursively search topdir",
61+
action="store_true")
62+
parser.add_argument("--firefly_url", help="URL for Firefly server",
63+
default=os.getenv("FIREFLY_URL"))
64+
parser.add_argument("--channel", help="channel name for websocket",
6765
default=None)
68-
parser.add_argument('--printurl', help='print browser url instead of' +
69-
' attempting to launch browser', action='store_true')
66+
parser.add_argument("--printurl", help="print browser url instead of" +
67+
" attempting to launch browser", action="store_true")
7068

7169
args = parser.parse_args()
7270
topdir = args.topdir
7371
pattern = args.pattern
74-
host = args.host
75-
port = args.port
76-
basedir = args.base
72+
firefly_url = args.firefly_url
7773
channel = args.channel
7874
printurl = args.printurl
75+
launch_browser=True
76+
if printurl:
77+
launch_browser=False
7978
recursion = not args.norecursion
8079

81-
fc = FireflyClient.make_client(url='{}:{}'.format(host, port), channel_override=channel, html_file='slate.html')
80+
fc = firefly_client.FireflyClient.make_client(url=firefly_url, channel_override=channel, html_file="slate.html", launch_browser=launch_browser)
8281
if printurl:
83-
print('Firefly url is {}'.format(fc.get_firefly_url()))
82+
print("Firefly URL is {}".format(fc.get_firefly_url()))
8483

84+
print("Searching for files...", end="")
8585
tbl_val, metainfo = filetable_to_firefly(fc, topdir, pattern,
8686
recursive=recursion)
87-
r = fc.add_cell(0, 0, 1, 2, 'tables', 'main')
87+
print("done.")
88+
89+
if printurl:
90+
input("Press Enter after your browser is open to the Firefly URL...")
91+
92+
r = fc.add_cell(0, 0, 1, 2, "tables", "main")
8893
fc.show_table(tbl_val, meta=metainfo)
89-
r = fc.add_cell(0, 1, 1, 2, 'tableImageMeta', 'image-meta')
90-
fc.show_image_metadata(viewer_id=r['cell_id'])
94+
r = fc.add_cell(0, 1, 1, 2, "tableImageMeta", "image-meta")
95+
fc.show_image_metadata(viewer_id=r["cell_id"])
9196

92-
if __name__ == '__main__':
97+
if __name__ == "__main__":
9398
main()
9499

0 commit comments

Comments
 (0)