#!/usr/bin/env python

"""
Access a Galaxy instance and get data for Libraries.

Pretty standard get and show at this point.
"""
import os
import sys
import pprint

import setup
import common

# the REST URL for the library resource
RESOURCE_URL = '/api/libraries'

# ----------------------------------------------------------------------------- functions
def get_libraries():
    """
    Return a list of dictionaries that describe the current user's libraries.
    """
    apikey = setup.get_apikey()
    full_url = setup.get_base_url() + RESOURCE_URL
    return common.get( apikey, full_url )

def get_library( library_id ):
    """
    Return a dictionary that the gives details of a specific library.
    """
    apikey = setup.get_apikey()
    resource_url = setup.get_base_url() + RESOURCE_URL

    full_url = resource_url + '/' + library_id
    return common.get( apikey, full_url )


# ----------------------------------------------------------------------------- main
if __name__ == '__main__':
    # double duty
    if   len( sys.argv ) <= 1:
        # no args: get all libraries
        returned = get_libraries()
        pprint.pprint( returned, indent=2 )

    elif len( sys.argv ) <= 2:
        # 1 arg: get a specific library
        library_id = sys.argv[1]
        returned = get_library( library_id )
        pprint.pprint( returned, indent=2 )
