-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from hautof/dev-3.0.0
add plugin manager to support third party plugin
- Loading branch information
Showing
14 changed files
with
194 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import pluggy | ||
|
||
|
||
hookimpl = pluggy.HookimplMarker("haf") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pluggy | ||
|
||
|
||
hookspec = pluggy.HookspecMarker("haf") | ||
|
||
|
||
@hookspec | ||
def add_option(parse): | ||
"""add option to parse | ||
:param run args | ||
:return: None | ||
""" | ||
|
||
|
||
@hookspec | ||
def load_from_file(file_name): | ||
"""add option to parse | ||
:param run args | ||
:return: file_name | ||
""" | ||
|
||
|
||
@hookspec | ||
def publish_to_sql(args, results): | ||
"""publish result to sql | ||
:param publish : or not | ||
:param result : publish result | ||
:return : None | ||
""" | ||
|
||
@hookspec | ||
def start_web_server(args, bus_client): | ||
"""start web server | ||
:param args: | ||
:return: | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import haf | ||
from haf.utils import LoadFromConfig | ||
from haf.common.log import Log | ||
|
||
logger = Log.getLogger(__name__) | ||
|
||
|
||
@haf.hookimpl | ||
def add_option(): | ||
args = [] | ||
return args | ||
|
||
|
||
@haf.hookimpl | ||
def load_from_file(file_name): | ||
if file_name.endswith(".xlsx"): | ||
output = LoadFromConfig.load_from_xlsx(file_name) | ||
elif file_name.endswith(".json"): | ||
output = LoadFromConfig.load_from_json(file_name) | ||
elif file_name.endswith(".yml"): | ||
output = LoadFromConfig.load_from_yml(file_name) | ||
elif file_name.endswith(".py"): | ||
output = LoadFromConfig.load_from_py(file_name) | ||
return output | ||
|
||
|
||
@haf.hookimpl | ||
def publish_to_sql(args, results): | ||
pass | ||
|
||
|
||
@haf.hookimpl | ||
def start_web_server(args, bus_client): | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import itertools | ||
import random | ||
|
||
import pluggy | ||
import json | ||
import os | ||
import sys | ||
import argparse | ||
from haf import hookspecs, lib | ||
|
||
|
||
class PluginManager(object): | ||
def __init__(self): | ||
self.get_plugin_manager() | ||
|
||
def add_options(self, sub_run_arg_program): | ||
pm = self.pm | ||
return pm.hook.add_option(parse = sub_run_arg_program) | ||
|
||
def load_from_file(self, file_name): | ||
pm = self.pm | ||
inputs = pm.hook.load_from_file(file_name = file_name) | ||
if isinstance(inputs, list): | ||
return inputs[0] | ||
elif isinstance(inputs, dict): | ||
return inputs | ||
|
||
def publish_to_sql(self, args, results): | ||
pm = self.pm | ||
publish_result = pm.hook.publish_to_sql(args=args, results=results) | ||
return publish_result | ||
|
||
def start_web_server(self, args, bus_client): | ||
pm = self.pm | ||
result = pm.hook.start_web_server(args=args, bus_client=bus_client) | ||
return result | ||
|
||
def get_plugin_manager(self): | ||
self.pm = pluggy.PluginManager("haf") | ||
self.pm.add_hookspecs(hookspecs) | ||
self.pm.load_setuptools_entrypoints("haf") | ||
self.pm.register(lib) | ||
return self.pm | ||
|
||
|
||
plugin_manager = PluginManager() |
Oops, something went wrong.