mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-13 04:02:29 +00:00
3e3f5555ff
We've changed the way plugins are activated, and removed the notion of deactivated plugins. Now plugins activate asynchronously. When calling a plugin, it will be activated if it wasn't, and the call will wait for the plugin to be fully activated.
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
import sys
|
|
from .models import Error
|
|
from .extensions import Senpy
|
|
from . import api
|
|
|
|
|
|
def argv_to_dict(argv):
|
|
'''Turns parameters in the form of '--key value' into a dict {'key': 'value'}
|
|
'''
|
|
cli_dict = {}
|
|
|
|
for i in range(len(argv)):
|
|
if argv[i][0] == '-':
|
|
key = argv[i].strip('-')
|
|
value = argv[i + 1] if len(argv) > i + 1 else None
|
|
if not value or value[0] == '-':
|
|
cli_dict[key] = True
|
|
else:
|
|
cli_dict[key] = value
|
|
return cli_dict
|
|
|
|
|
|
def main_function(argv):
|
|
'''This is the method for unit testing
|
|
'''
|
|
params = api.parse_params(argv_to_dict(argv),
|
|
api.CLI_PARAMS,
|
|
api.API_PARAMS,
|
|
api.NIF_PARAMS)
|
|
plugin_folder = params['plugin_folder']
|
|
sp = Senpy(default_plugins=False, plugin_folder=plugin_folder)
|
|
request = api.parse_call(params)
|
|
algos = request.parameters.get('algorithm', sp.plugins.keys())
|
|
for algo in algos:
|
|
sp.activate_plugin(algo)
|
|
res = sp.analyse(request)
|
|
return res
|
|
|
|
|
|
def main():
|
|
'''This method is the entrypoint for the CLI (as configured un setup.py)
|
|
'''
|
|
try:
|
|
res = main_function(sys.argv[1:])
|
|
print(res.to_JSON())
|
|
except Error as err:
|
|
print(err.to_JSON())
|
|
sys.exit(2)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|