Skip to content

Instantly share code, notes, and snippets.

@joshmoore
Created July 27, 2016 09:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmoore/76ae362e22a625289e2c70e8abddbfaf to your computer and use it in GitHub Desktop.
Save joshmoore/76ae362e22a625289e2c70e8abddbfaf to your computer and use it in GitHub Desktop.
Script to refresh the B-F cache
#!/usr/bin/env python
from argparse import ArgumentParser
from fileinput import input
from sys import argv
from sys import exit
from sys import stdout
from sys import stderr
from time import time
def login():
import omero
import omero.cli
cli = omero.cli.CLI()
cli.loadplugins()
cli.onecmd("-q login")
client = cli.get_client()
client.enableKeepAlive(300)
return cli, client
def run(cli, client, pixid, force=False):
start = time()
error = ""
rps = client.sf.createRawPixelsStore()
msg = None
try:
rps.setPixelsId(long(pixid), False, {"omero.pixeldata.fail_if_missing": "true"})
msg = "ok:"
except Exception, e:
error = e
msg = "miss:"
if msg == "ok:" or not force:
rps.close()
else:
try:
rps.setPixelsId(long(pixid), False, {"omero.pixeldata.fail_if_missing": "false"})
msg = "fill:"
except KeyboardInterrupt:
msg = "cancel:"
pass
except Exception, e:
msg = "fail:"
error = e
finally:
rps.close()
stop = time()
if error:
error = str(error).split("\n")[0]
print >>stdout, msg, pixid, stop-start, error
return msg
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("--force", action="store_true")
parser.add_argument("pixid", type=long)
ns = parser.parse_args()
cli, client = login()
error = "fail:"
try:
error = run(cli, client, ns.pixid, ns.force)
finally:
cli.close()
if error == "fail:":
exit(123)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment