summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2015-08-22 10:00:00 -0500
committerDavid McMackins II <contact@mcmackins.org>2015-08-22 10:00:00 -0500
commit3fd6222801a6443586d73698e78bbccb7afec79e (patch)
tree5ac682de737cd7ad34e56ea446d274c10e9ed298
parenta5d77aea7efc8a012414b8d7a464fbaf79a346da (diff)
Added default plugin loading function
-rw-r--r--coinfetch.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/coinfetch.py b/coinfetch.py
index af36d92..e6f206e 100644
--- a/coinfetch.py
+++ b/coinfetch.py
@@ -16,7 +16,7 @@
##
from os import listdir
-from os.path import isdir
+from os.path import dirname, exists, expanduser, isdir, join, realpath
from requests import get
__version__ = '5.0.0'
@@ -68,8 +68,19 @@ _INDEX = {
'value': 1
}
+_PATH = [
+ '/usr/share/coinfetch',
+ dirname(realpath(__file__)),
+ join(expanduser('~'), '.coinfetch')
+]
+
_tickers = {}
+## Adds a directory to the configuration path.
+# @param path The directory to be added.
+def add_to_path(path):
+ _PATH.append(path)
+
## Gets the registered tickers and their descriptions.
# @return A list of tuples containing the ticker name and description.
def get_registered_tickers():
@@ -91,11 +102,19 @@ def get_ticker(key):
def load(path):
if isdir(path):
for f in listdir:
- load(join(path, f))
+ if f.endswith('.py'):
+ load(join(path, f))
else:
with open(path) as plugin:
exec(plugin.read(), globals(), locals())
+## Loads all default plugins.
+def load_default_plugins():
+ for d in _PATH:
+ plugindir = join(d, 'plugins')
+ if exists(plugindir):
+ load(plugindir)
+
## Registers a new ticker API.
# @param name Name of this ticker.
# @param description A brief description of this ticker.