2018-01-30 16:48:16 +00:00
|
|
|
import logging, os, sys
|
2018-02-09 17:38:42 +00:00
|
|
|
from abc import ABC
|
2018-01-30 16:48:16 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger('app.logger')
|
|
|
|
|
|
|
|
class PluginBase(ABC):
|
|
|
|
def __init__(self):
|
|
|
|
self.name = self.get_module_name().split(".")[-2]
|
|
|
|
|
|
|
|
def register(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def get_path(self, *paths):
|
|
|
|
"""
|
|
|
|
Gets the path of the directory of the plugin, optionally chained with paths
|
|
|
|
:return: path
|
|
|
|
"""
|
|
|
|
return os.path.join(os.path.dirname(sys.modules[self.get_module_name()].__file__), *paths)
|
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def get_module_name(self):
|
|
|
|
return self.__class__.__module__
|
|
|
|
|
2018-01-30 22:41:32 +00:00
|
|
|
def get_include_js_urls(self):
|
|
|
|
return ["/plugins/{}/{}".format(self.get_name(), js_file) for js_file in self.include_js_files()]
|
|
|
|
|
2018-02-09 17:38:42 +00:00
|
|
|
def get_include_css_urls(self):
|
|
|
|
return ["/plugins/{}/{}".format(self.get_name(), css_file) for css_file in self.include_css_files()]
|
|
|
|
|
2018-01-30 16:48:16 +00:00
|
|
|
def has_public_path(self):
|
|
|
|
return os.path.isdir(self.get_path("public"))
|
|
|
|
|
2018-01-30 22:41:32 +00:00
|
|
|
def include_js_files(self):
|
|
|
|
"""
|
|
|
|
Should be overriden by plugins to communicate
|
|
|
|
which JS files should be included in the WebODM interface
|
|
|
|
All paths are relative to a plugin's /public folder.
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
2018-02-09 17:38:42 +00:00
|
|
|
def include_css_files(self):
|
|
|
|
"""
|
|
|
|
Should be overriden by plugins to communicate
|
|
|
|
which CSS files should be included in the WebODM interface
|
|
|
|
All paths are relative to a plugin's /public folder.
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
2018-01-30 16:48:16 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "[{}]".format(self.get_module_name())
|