- Support for workdir

- Prepared draft for HttpPoll backend
This commit is contained in:
Fabio Manganiello 2018-01-09 01:26:51 +01:00
parent 411874c6a7
commit b074e03d45
2 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,50 @@
import json
import requests
from threading import Thread
from platypush.message.response import Response
from .. import Backend
class HttpPollBackend(Backend):
"""
This backend will poll multiple HTTP endpoints/services and return events
the bus whenever something new happened. Example configuration:
backend.http.poll:
services:
-
type: platypush.backend.http.service.ota.booking.GetReservations
args:
token: YOUR_TOKEN
poll_seconds: 10 # Check for updates on this endpoint every 10 seconds
limit: 5 # Return the first 5 (new) results (default: all)
"""
def __init__(self, services, *args, **kwargs):
"""
Params:
services -- List/iterable of HttpService objects
"""
super().__init__(*args, **kwargs)
self.services = services
def run(self):
super().run()
def send_message(self, msg):
pass
def on_stop(self):
pass
def stop(self):
super().stop()
# vim:sw=4:ts=4:et:

View file

@ -1,3 +1,4 @@
import errno
import logging
import os
import socket
@ -30,6 +31,8 @@ class Config(object):
os.path.join(os.sep, 'etc', 'platypush', 'config.yaml'),
]
_workdir_location = os.path.join(os.environ['HOME'], '.local', 'share', 'platypush')
def __init__(self, cfgfile=None):
"""
Constructor. Always use the class as a singleton (i.e. through
@ -49,6 +52,10 @@ class Config(object):
self._cfgfile = cfgfile
self._config = self._read_config_file(self._cfgfile)
if 'workdir' not in self._config:
self._config['workdir'] = self._workdir_location
mkdir_p(self._config['workdir'])
if 'logging' not in self._config:
self._config['logging'] = logging.INFO
else:
@ -182,5 +189,13 @@ class Config(object):
if _default_config_instance is None: _default_config_instance = Config()
_default_config_instance._config[key] = key
def mkdir_p(path):
try: os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path): pass
else: raise
# vim:sw=4:ts=4:et: