Created
July 27, 2016 09:17
-
-
Save joshmoore/76ae362e22a625289e2c70e8abddbfaf to your computer and use it in GitHub Desktop.
Script to refresh the B-F cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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