Skip to content

Instantly share code, notes, and snippets.

@mpkocher
Last active October 2, 2019 14:54
Show Gist options
  • Save mpkocher/52cfcf48f5efee63f50e36a2c8223f76 to your computer and use it in GitHub Desktop.
Save mpkocher/52cfcf48f5efee63f50e36a2c8223f76 to your computer and use it in GitHub Desktop.
Example of getting Runs list from SL
#!/usr/bin/env python
"""Get a List of Runs from SMRT Link"""
# From:http://bitbucket.nanofluidics.com:7990/projects/SL/repos/pbcommand/browse/pbcommand/cli/examples/template_simple.py
import os
import sys
import logging
from pbcommand.validators import validate_file
from pbcommand.utils import setup_log
from pbcommand.cli import get_default_argparser_with_base_opts, pacbio_args_runner
from pbcommand.services._service_access_layer import SmrtLinkAuthClient
import requests
log = logging.getLogger(__name__)
__version__ = "0.1.0"
__author__ = "mkocher"
def get_parser():
"""Define Parser. Use the helper methods in validators to validate input"""
p = get_default_argparser_with_base_opts(__version__, __doc__)
p.add_argument('host', type=str, default="smrtlink-alpha", help="SL Host")
p.add_argument('-u', '--user', type=str, default="admin", help="User")
p.add_argument('-p', '--password', type=str, default=None,
help="User Password", required=True)
return p
def raw_get(c, u):
return requests.get(u, headers=c._get_headers(), verify=False).json()
def run_main(host, user, password):
"""
Get a list of Runs.
"""
c = SmrtLinkAuthClient(host, user, password)
# this was added post SL-6.0.0 release to
# c.get_runs()
# using a raw call to enable working on 6.0.0 systems
runs_d = raw_get(c, c._to_url("/smrt-link/runs"))
for run in runs_d:
print (run['uniqueId'], run['status'], run['name'])
return 0
def args_runner(args):
#log.debug("Raw args {a}".format(a=args))
return run_main(args.host, args.user, args.password)
def main(argv):
return pacbio_args_runner(argv[1:],
get_parser(),
args_runner,
log,
setup_log_func=setup_log)
if __name__ == '__main__':
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment