Skip to content

Commit

Permalink
Service uploader can be in 'user modules' directory
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed May 21, 2018
1 parent c66000a commit b734880
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.5.0'
_release = '1532'
_commit = 'ac9c014'
_release = '1533'
_commit = 'c66000a'
15 changes: 12 additions & 3 deletions src/pywws/regulartasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import importlib
import logging
import os
import sys

from pywws.calib import Calib
import pywws.plot
Expand Down Expand Up @@ -56,6 +57,8 @@ def __init__(self, context):
'paths', 'graph_templates', os.path.expanduser('~/weather/graph_templates/'))
self.local_dir = self.params.get(
'paths', 'local_files', os.path.expanduser('~/weather/results/'))
self.module_dir = self.params.get(
'paths', 'modules', os.path.expanduser('~/weather/modules/'))
# create calibration object
self.calibrator = Calib(self.params, self.raw_data)
# create templater object
Expand Down Expand Up @@ -90,24 +93,30 @@ def __init__(self, context):
self.cron[section].get_next()
# create service uploader objects
self.services = {}
sys.path.insert(0, self.module_dir)
for section in list(self.cron.keys()) + [
'live', 'logged', 'hourly', '12 hourly', 'daily']:
for name in eval(self.params.get(section, 'services', '[]')):
if name in self.services:
continue
mod = None
try:
mod = importlib.import_module('pywws.service.' + name)
self.services[name] = getattr(mod, 'ToService')(context)
except ImportError:
logger.error(
'no uploader found for service "{:s}"'.format(name))
try:
mod = importlib.import_module(name)
except ImportError:
logger.error('no uploader found for service "{:s}"'.format(name))
if mod:
self.services[name] = mod.ToService(context)
# check for obsolete entries
if self.params.get(section, 'twitter'):
logger.error(
'Obsolete twitter entry in weather.ini [%s]', section)
if self.params.get(section, 'yowindow'):
logger.error(
'Obsolete yowindow entry in weather.ini [%s]', section)
del sys.path[0]
# check for 'local' template results
if os.path.isdir(self.local_dir):
return
Expand Down

0 comments on commit b734880

Please sign in to comment.