def get_manifests_from_conf( conf_file: Optional[str] = None) -> Mapping[str, Manifest]: import platypush from platypush.config import Config conf_args = [] if conf_file: conf_args.append(conf_file) Config.init(*conf_args) app_dir = os.path.dirname(inspect.getfile(platypush)) manifest_files = set() for name in Config.get_backends().keys(): manifest_files.add( os.path.join(app_dir, 'backend', *name.split('.'), 'manifest.yaml')) for name in Config.get_plugins().keys(): manifest_files.add( os.path.join(app_dir, 'plugins', *name.split('.'), 'manifest.yaml')) return { manifest_file: Manifest.from_file(manifest_file) for manifest_file in manifest_files }
def __init__(self, config_file=None, backend=None, on_response=None): """ Constructor. Params: config_file -- Path to the configuration file - default: ~/.config/platypush/config.yaml or /etc/platypush/config.yaml) backend -- Name of the backend where pusher will send the request and wait for the response (kafka or pushbullet). Default: whatever is specified with pusher=true in your configuration file on_response -- Method that will be invoked upon response receipt. Takes a platypush.message.response.Response as arg. Default: print the response and exit. """ # Initialize the configuration self.config_file = config_file log_conf = Config.get('logging') Config.init(config_file) logging.basicConfig(level=log_conf['level'] if log_conf and 'level' in log_conf else logging.info, stream=sys.stdout) self.on_response = on_response or self.default_on_response() self.backend = backend or Config.get_default_pusher_backend() self.bus = Bus()
def build(args): global workdir ports = set() deps = set() parser = argparse.ArgumentParser(prog='platydock build', description='Build a Platypush image ' + 'from a config.yaml') parser.add_argument('-c', '--config', type=str, required=True, help='Path to the platypush configuration file') opts, args = parser.parse_known_args(args) cfgfile = os.path.abspath(os.path.expanduser(opts.config)) Config.init(cfgfile) register_backends() backend_config = Config.get_backends() if backend_config.get('http'): http_backend = get_backend('http') ports.add(http_backend.port) if http_backend.websocket_port: ports.add(http_backend.websocket_port) if backend_config.get('tcp'): ports.add(get_backend('tcp').port) if backend_config.get('websocket'): ports.add(get_backend('websocket').port) for name in Config.get_backends().keys(): deps.update(_parse_deps(get_backend(name))) for name in Config.get_plugins().keys(): try: deps.update(_parse_deps(get_plugin(name))) except: pass devdir = os.path.join(workdir, Config.get('device_id')) generate_dockerfile(deps=deps, ports=ports, cfgfile=cfgfile, devdir=devdir) subprocess.call([ 'docker', 'build', '-t', 'platypush-{}'.format(Config.get('device_id')), devdir ])
import os import sys testdir = os.path.dirname(__file__) sys.path.insert(0, os.path.abspath(os.path.join(testdir, '..'))) config_file = os.path.join(testdir, 'etc', 'config.yaml') from platypush.config import Config Config.init(config_file) import platypush class TestTimeoutException(RuntimeError): def __init__(self, msg): self.msg = msg # vim:sw=4:ts=4:et: