# HG changeset patch -- Bitbucket.org # Project galaxy-dist # URL http://bitbucket.org/galaxy/galaxy-dist/overview # User Nate Coraor nate@bx.psu.edu # Date 1277318677 14400 # Node ID 5cde0b6269e320c2bd769222cbd40f2e8956b7c5 # Parent e177f00679e9f8106c346251c1f8bdc0ece127d5 API: Add library creation functionality. Note that no roles can be associated with libraries via the API at this time.
--- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -830,7 +830,7 @@ class HistoryDatasetAssociationDisplayAt class Library( object ): permitted_actions = get_permitted_actions( filter='LIBRARY' ) api_collection_visible_keys = ( 'id', 'name' ) - api_element_visible_keys = ( 'name', 'description', 'synopsys' ) + api_element_visible_keys = ( 'name', 'description', 'synopsis' ) def __init__( self, name=None, description=None, synopsis=None, root_folder=None ): self.name = name or "Unnamed library" self.description = description
--- a/scripts/api/README +++ b/scripts/api/README @@ -13,9 +13,20 @@ subdirectories.
In Galaxy, create an account that matches the address you put in 'admin_users', then browse to that user's preferences and generate a new API Key. Copy the -key to your clipboard. Create a new library (doing this via the API is not yet -implemented). Then take your API Key and use the scripts in scripts/api/ to do -things: +key to your clipboard and then use these scripts: + +% ./display.py my_key http://localhost:4096/api/libraries +Collection Members +------------------ + +0 elements in collection + +% ./library_create_library.py my_key http://localhost:4096/api/libraries api_test 'API Test Library' +Response +-------- +/api/libraries/f3f73e481f432006 + name: api_test + id: f3f73e481f432006
% ./display.py my_key http://localhost:4096/api/libraries Collection Members @@ -27,7 +38,7 @@ Collection Members % ./display.py my_key http://localhost:4096/api/libraries/f3f73e481f432006 Member Information ------------------ -synopsys: None +synopsis: None contents_url: /api/libraries/f3f73e481f432006/contents description: API Test Library name: api_test
--- /dev/null +++ b/scripts/api/library_create_library.py @@ -0,0 +1,19 @@ +#!/usr/bin/python + +import os, sys +sys.path.insert( 0, os.path.dirname( __file__ ) ) +from common import submit + +try: + data = {} + data[ 'name' ] = sys.argv[3] +except IndexError: + print 'usage: %s key url name [description] [synopsys]' % os.path.basename( sys.argv[0] ) + sys.exit( 1 ) +try: + data[ 'description' ] = sys.argv[4] + data[ 'synopsis' ] = sys.argv[5] +except IndexError: + pass + +submit( sys.argv[1], sys.argv[2], data )
--- a/lib/galaxy/web/api/libraries.py +++ b/lib/galaxy/web/api/libraries.py @@ -60,3 +60,33 @@ class LibrariesController( BaseControlle item = library.get_api_value( view='element' ) item['contents_url'] = url_for( 'contents', library_id=library_id ) return item + + @web.expose_api + def create( self, trans, payload, **kwd ): + """ + POST /api/libraries + Creates a new library. + """ + if not trans.user_is_admin(): + trans.response.status = 403 + return "You are not authorized to create a new library." + params = util.Params( payload ) + name = util.restore_text( params.get( 'name', None ) ) + if not name: + trans.response.status = 400 + return "Missing required parameter 'name'." + description = util.restore_text( params.get( 'description', '' ) ) + synopsis = util.restore_text( params.get( 'synopsis', '' ) ) + if synopsis in [ 'None', None ]: + synopsis = '' + library = trans.app.model.Library( name=name, description=description, synopsis=synopsis ) + root_folder = trans.app.model.LibraryFolder( name=name, description='' ) + library.root_folder = root_folder + trans.sa_session.add_all( ( library, root_folder ) ) + trans.sa_session.flush() + encoded_id = trans.security.encode_id( library.id ) + rval = {} + rval['url'] = url_for( 'libraries', id=encoded_id ) + rval['name'] = name + rval['id'] = encoded_id + return [ rval ]
galaxy-commits@lists.galaxyproject.org