-
Notifications
You must be signed in to change notification settings - Fork 80
Adds missing bits #1960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds missing bits #1960
Changes from all commits
768eefa
15ac925
49b7e6f
11b4f34
a1df204
c86d37d
afc8707
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,13 @@ | |
# ----------------------------------------------------------------------------- | ||
|
||
from json import loads | ||
from glob import glob | ||
from os.path import join | ||
|
||
from tornado.web import HTTPError | ||
|
||
from .oauth2 import OauthBaseHandler, authenticate_oauth | ||
from qiita_core.qiita_settings import qiita_config | ||
import qiita_db as qdb | ||
|
||
|
||
|
@@ -97,17 +100,20 @@ def post(self, name, version): | |
cmd_desc = self.get_argument('description') | ||
req_params = loads(self.get_argument('required_parameters')) | ||
opt_params = loads(self.get_argument('optional_parameters')) | ||
outputs = self.get_argument('outputs', None) | ||
if outputs: | ||
outputs = loads(outputs) | ||
dflt_param_set = loads(self.get_argument('default_parameter_sets')) | ||
|
||
parameters = req_params | ||
parameters.update(opt_params) | ||
|
||
cmd = qdb.software.Command.create( | ||
plugin, cmd_name, cmd_desc, parameters) | ||
plugin, cmd_name, cmd_desc, parameters, outputs) | ||
|
||
# params = opt_params | ||
for name, vals in dflt_param_set.items(): | ||
qdb.software.DefaultParameters.create(name, cmd, **vals) | ||
if dflt_param_set is not None: | ||
for name, vals in dflt_param_set.items(): | ||
qdb.software.DefaultParameters.create(name, cmd, **vals) | ||
|
||
self.finish() | ||
|
||
|
@@ -184,3 +190,35 @@ def get(self, plugin_name, plugin_version, cmd_name): | |
'default_parameter_sets': { | ||
p.name: p.values for p in cmd.default_parameter_sets}} | ||
self.write(response) | ||
|
||
|
||
class CommandActivateHandler(OauthBaseHandler): | ||
@authenticate_oauth | ||
def post(self, plugin_name, plugin_version, cmd_name): | ||
"""Activates the command | ||
|
||
Parameters | ||
---------- | ||
plugin_name : str | ||
The plugin name | ||
plugin_version : str | ||
The plugin version | ||
cmd_name : str | ||
The command name | ||
""" | ||
with qdb.sql_connection.TRN: | ||
cmd = _get_command(plugin_name, plugin_version, cmd_name) | ||
cmd.activate() | ||
|
||
self.finish() | ||
|
||
|
||
class ReloadPluginAPItestHandler(OauthBaseHandler): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing a test, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this method idempotent? if not, should it be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question regarding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is idempotent as long as the files in |
||
@authenticate_oauth | ||
def post(self): | ||
"""Reloads the plugins""" | ||
conf_files = glob(join(qiita_config.plugin_dir, "*.conf")) | ||
for fp in conf_files: | ||
s = qdb.software.Software.from_file(fp, update=True) | ||
s.activate() | ||
self.finish() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,7 +147,7 @@ def exists(cls, software, name): | |
return qdb.sql_connection.TRN.execute_fetchlast() | ||
|
||
@classmethod | ||
def create(cls, software, name, description, parameters): | ||
def create(cls, software, name, description, parameters, outputs=None): | ||
r"""Creates a new command in the system | ||
|
||
The supported types for the parameters are: | ||
|
@@ -175,6 +175,9 @@ def create(cls, software, name, description, parameters): | |
format is: {parameter_name: (parameter_type, default)}, | ||
where parameter_name, parameter_type and default are strings. If | ||
default is None. | ||
outputs : dict, optional | ||
The description of the outputs that this command generated. The | ||
format is: {output_name: artifact_type} | ||
|
||
Returns | ||
------- | ||
|
@@ -216,7 +219,7 @@ def create(cls, software, name, description, parameters): | |
ptype, dflt = vals | ||
# Check that the type is one of the supported types | ||
supported_types = ['string', 'integer', 'float', 'reference', | ||
'boolean'] | ||
'boolean', 'prep_template'] | ||
if ptype not in supported_types and not ptype.startswith( | ||
('choice', 'artifact')): | ||
supported_types.extend(['choice', 'artifact']) | ||
|
@@ -281,6 +284,17 @@ def create(cls, software, name, description, parameters): | |
for at in atypes] | ||
qdb.sql_connection.TRN.add(sql_type, sql_params, many=True) | ||
|
||
# Add the outputs to the command | ||
if outputs: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just want to confirm that now there are no tests without output. I think is fine due to how it work but want to double check it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
sql = """INSERT INTO qiita.command_output | ||
(name, command_id, artifact_type_id) | ||
VALUES (%s, %s, %s)""" | ||
sql_args = [ | ||
[pname, c_id, qdb.util.convert_to_id(at, 'artifact_type')] | ||
for pname, at in outputs.items()] | ||
qdb.sql_connection.TRN.add(sql, sql_args, many=True) | ||
qdb.sql_connection.TRN.execute() | ||
|
||
return cls(c_id) | ||
|
||
@property | ||
|
@@ -425,6 +439,31 @@ def outputs(self): | |
qdb.sql_connection.TRN.add(sql, [self.id]) | ||
return qdb.sql_connection.TRN.execute_fetchindex() | ||
|
||
@property | ||
def active(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't have an actual tests, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested it through the function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. K |
||
"""Returns if the command is active or not | ||
|
||
Returns | ||
------- | ||
bool | ||
Whether the command is active or not | ||
""" | ||
with qdb.sql_connection.TRN: | ||
sql = """SELECT active | ||
FROM qiita.software_command | ||
WHERE command_id = %s""" | ||
qdb.sql_connection.TRN.add(sql, [self.id]) | ||
return qdb.sql_connection.TRN.execute_fetchlast() | ||
|
||
def activate(self): | ||
"""Activates the command""" | ||
with qdb.sql_connection.TRN: | ||
sql = """UPDATE qiita.software_command | ||
SET active = %s | ||
WHERE command_id = %s""" | ||
qdb.sql_connection.TRN.add(sql, [True, self.id]) | ||
return qdb.sql_connection.TRN.execute() | ||
|
||
|
||
class Software(qdb.base.QiitaObject): | ||
r"""A software package available in the system | ||
|
@@ -456,6 +495,8 @@ def deactivate_all(cls): | |
with qdb.sql_connection.TRN: | ||
sql = "UPDATE qiita.software SET active = False" | ||
qdb.sql_connection.TRN.add(sql) | ||
sql = "UPDATE qiita.software_command SET active = False" | ||
qdb.sql_connection.TRN.add(sql) | ||
qdb.sql_connection.TRN.execute() | ||
|
||
@classmethod | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the only type of unacceptable artifact a duplicate one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is creating a new artifact type (not a new artifact) and I couldn't think in any other case where a new type is unacceptable.