def retrieve_resource(resource, exact): """ Retrieve the provided resource from XDMoD's database. :type resource str :param resource: the name of the resource to retrieve :return: a json encoded version of the record in `modw`.`resourcefact` identified by """ if resource is None or len(resource) < 1: raise AssertionError('provided resource must not be empty.') connection, cursor = akrr.getXDDB(True) with connection: query = """ SELECT name, id FROM `modw`.`resourcefact` AS RF WHERE RF.NAME LIKE %s """ if not exact else """ SELECT name, id FROM `modw`.`resourcefact` AS RF WHERE RF.NAME = %s """ parameter = (resource + "%", ) if not exact else (resource, ) cursor.execute(query, parameter) rows = cursor.fetchall() return rows
def retrieve_resources(): """ Retrieve all resources currently present in the XDMoD database. :return: a dict representation of the resourcefact table ( name, id ) """ connection, cursor = akrr.getXDDB(True) with connection: cursor.execute(""" SELECT name, id from `modw`.`resourcefact`; """) rows = cursor.fetchall() return rows
def retrieve_resources(): """ Retrieve the applicable contents of the `modw`.`resourcefact` table. :return: a tuple of strings containing the name of the resources. """ try: connection, cursor = akrr.getXDDB() # PROVIDES: automatic resource cleanup with connection: cursor = connection.cursor() cursor.execute("SELECT `name`,`id` FROM `modw`.`resourcefact`") rows = cursor.fetchall() except MySQLdb.Error, e: logging.error("MySQL Error: {0}: {1}", e.args[0]. e.args[1]) sys.exit(1)