Skip to content

Commit

Permalink
add very basic plugin system (for tools)
Browse files Browse the repository at this point in the history
  • Loading branch information
anatskiy committed Oct 9, 2016
1 parent a34a120 commit 6e66fbe
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/tool/tool-form.js
Expand Up @@ -173,4 +173,4 @@ define([ 'utils/utils', 'mvc/ui/ui-misc', 'mvc/ui/ui-modal', 'mvc/tool/tool-form
return {
View: View
};
});
});
40 changes: 40 additions & 0 deletions client/galaxy/scripts/mvc/tool/tool-webhooks.js
@@ -0,0 +1,40 @@
/**
Webhooks
**/
define([], function() {
var galaxyRoot = typeof Galaxy != 'undefined' ? Galaxy.root : '/';

var WebhookModel = Backbone.Model.extend({
urlRoot: galaxyRoot + 'api/webhooks/toolview',
defaults: {
name: '',
path: ''
}
});

var WebhookView = Backbone.View.extend({
el: '#webhook-toolview',
webhookTemplate: _.template('<p>name: <%= name %><br>path: <%= path %></p>'),

initialize: function() {
var me = this;
this.model = new WebhookModel;
this.model.fetch({
success: function() {
me.render();
}
});
},

render: function() {
var webhookContent = this.model.toJSON();
if (webhookContent.css_styles) $('<style/>').text(webhookContent.css_styles).appendTo('head');
this.$el.html(this.webhookTemplate(webhookContent));
return this;
}
});

return {
WebhookView: WebhookView
};
});
2 changes: 1 addition & 1 deletion config/plugins/webhooks/plugin2/config/plugin2.yml
@@ -1,2 +1,2 @@
name: Plugin 2
type: mainview
type: toolview
2 changes: 2 additions & 0 deletions config/plugins/webhooks/plugin2/static/style.css
@@ -0,0 +1,2 @@
#webhook-toolview {border:1px solid #ccc;border-radius:3px;padding:10px;}
#webhook-toolview p {margin-bottom:0;}
24 changes: 22 additions & 2 deletions lib/galaxy/webapps/galaxy/api/webhooks.py
Expand Up @@ -2,13 +2,33 @@
API Controller providing Galaxy Webhooks
"""

import logging

from galaxy.web import _future_expose_api_anonymous_and_sessionless as \
expose_api_anonymous_and_sessionless
from galaxy.web.base.controller import BaseAPIController

import logging
import random

log = logging.getLogger(__name__)


class WebhooksController(BaseAPIController):
def __init__(self, app):
super(WebhooksController, self).__init__(app)

@expose_api_anonymous_and_sessionless
def get_all(self, trans, **kwd):
"""
*GET /api/webhooks/
Returns all webhooks
"""
return self.app.webhooks_registry.webhooks

@expose_api_anonymous_and_sessionless
def get_random(self, trans, webhook_type, **kwd):
"""
*GET /api/webhooks/{webhook_type}
Returns a random webhook for a given type
"""
webhooks = self.app.webhooks_registry.webhooks[webhook_type]
return random.choice(webhooks)
16 changes: 16 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Expand Up @@ -456,6 +456,22 @@ def populate_api_routes( webapp, app ):
action='update_tour',
conditions=dict( method=[ "POST" ] ) )

# ========================
# ===== WEBHOOKS API =====
# ========================

webapp.mapper.connect( 'get_all',
'/api/webhooks',
controller='webhooks',
action='get_all',
conditions=dict( method=[ "GET" ] ) )

webapp.mapper.connect( 'get_random',
'/api/webhooks/{webhook_type}',
controller='webhooks',
action='get_random',
conditions=dict( method=[ "GET" ] ) )

# =======================
# ===== LIBRARY API =====
# =======================
Expand Down
26 changes: 18 additions & 8 deletions lib/galaxy/webhooks/__init__.py
Expand Up @@ -12,9 +12,8 @@


class WebhooksRegistry(object):
webhooks = {}

def __init__(self, webhooks_directories):
self.webhooks = {}
path = os.path.join(galaxy_root_path, webhooks_directories)
self.webhooks_directories = \
[os.path.join(path, name)
Expand All @@ -34,17 +33,28 @@ def load_webhooks(self):
conf.endswith('.yaml')][0]

if config_file:
self.load_webhook_from_config(
os.path.join(config_dir, config_file))
self.load_webhook_from_config(config_dir, config_file)

def load_webhook_from_config(self, config_file):
def load_webhook_from_config(self, config_dir, config_file):
try:
with open(config_file) as f:
with open(os.path.join(config_dir, config_file)) as f:
config = yaml.load(f)

if config['type'] not in self.webhooks.keys():
self.webhooks[config['type']] = []
self.webhooks[config['type']].append({
'name': config['name']

path = os.path.normpath(os.path.join(config_dir, '..'))

try:
with open(os.path.join(path, 'static/style.css'), 'r') as f:
css_styles = f.read().replace('\n', '')
except IOError:
css_styles = ''

config.update({
'path': path,
'css_styles': css_styles
})
self.webhooks[config['type']].append(config)
except Exception as e:
log.exception(e)
1 change: 1 addition & 0 deletions static/maps/mvc/tool/tool-webhooks.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions static/scripts/mvc/tool/tool-webhooks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e66fbe

Please sign in to comment.