kopia lustrzana https://github.com/Yakifo/amqtt
Add console script for broker
rodzic
a8e5879551
commit
d8527fb206
|
@ -1,4 +1,5 @@
|
|||
transitions==0.2.5
|
||||
blinker
|
||||
websockets
|
||||
passlib
|
||||
passlib
|
||||
docopt
|
||||
pyyaml
|
|
@ -0,0 +1,10 @@
|
|||
listeners:
|
||||
default:
|
||||
type: tcp
|
||||
bind: 0.0.0.0:1883
|
||||
sys_interval: 20
|
||||
auth:
|
||||
allow-anonymous: true
|
||||
plugins:
|
||||
- auth_file
|
||||
- auth_anonymous
|
|
@ -0,0 +1,81 @@
|
|||
# Copyright (c) 2015 Nicolas JOUANIN
|
||||
#
|
||||
# See the file license.txt for copying permission.
|
||||
"""
|
||||
HBMQTT - MQTT 3.1.1 broker
|
||||
|
||||
Usage:
|
||||
hbmqtt --version
|
||||
hbmqtt (-h | --help)
|
||||
hbmqtt [-c <config_file> ] [-d]
|
||||
|
||||
Options:
|
||||
-h --help Show this screen.
|
||||
--version Show version.
|
||||
-c <config_file> Broker configuration file (YAML format)
|
||||
-d Enable debug messages
|
||||
"""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import asyncio
|
||||
import os
|
||||
from hbmqtt.broker import Broker
|
||||
from hbmqtt.version import get_version
|
||||
from docopt import docopt
|
||||
from .utils import read_yaml_config
|
||||
|
||||
|
||||
default_config = {
|
||||
'listeners': {
|
||||
'default': {
|
||||
'type': 'tcp',
|
||||
'bind': '0.0.0.0:1883',
|
||||
},
|
||||
},
|
||||
'sys_interval': 10,
|
||||
'auth': {
|
||||
'allow-anonymous': True,
|
||||
'password-file': os.path.join(os.path.dirname(os.path.realpath(__file__)), "passwd"),
|
||||
'plugins': [
|
||||
'auth_file', 'auth_anonymous'
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main(*args, **kwargs):
|
||||
if sys.version_info[:2] < (3, 5):
|
||||
logger.fatal("Error: Python 3.5 is required")
|
||||
sys.exit(-1)
|
||||
|
||||
arguments = docopt(__doc__, version=get_version())
|
||||
formatter = "[%(asctime)s] :: %(levelname)s - %(message)s"
|
||||
|
||||
if arguments['-d']:
|
||||
level = logging.DEBUG
|
||||
else:
|
||||
level = logging.INFO
|
||||
logging.basicConfig(level=level, format=formatter)
|
||||
|
||||
config = None
|
||||
if arguments['-c']:
|
||||
config = read_yaml_config(arguments['-c'])
|
||||
else:
|
||||
config = read_yaml_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'default_broker.yaml'))
|
||||
logger.warning("Using default configuration")
|
||||
loop = asyncio.get_event_loop()
|
||||
broker = Broker(config)
|
||||
try:
|
||||
loop.run_until_complete(broker.start())
|
||||
loop.run_forever()
|
||||
except KeyboardInterrupt:
|
||||
asyncio.get_event_loop().run_until_complete(broker.shutdown())
|
||||
finally:
|
||||
loop.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -0,0 +1,17 @@
|
|||
# Copyright (c) 2015 Nicolas JOUANIN
|
||||
#
|
||||
# See the file license.txt for copying permission.
|
||||
import yaml
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def read_yaml_config(config_file):
|
||||
config = None
|
||||
try:
|
||||
with open(config_file, 'r') as stream:
|
||||
config = yaml.load(stream)
|
||||
except yaml.YAMLError as exc:
|
||||
logger.error("Invalid config_file %s: %s" % (config_file, exc))
|
||||
return config
|
10
setup.py
10
setup.py
|
@ -17,9 +17,10 @@ setup(
|
|||
platforms='all',
|
||||
install_requires=[
|
||||
'transitions==0.2.5',
|
||||
'blinker',
|
||||
'websockets',
|
||||
'passlib'
|
||||
'passlib',
|
||||
'docopt',
|
||||
'pyyaml'
|
||||
],
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Alpha',
|
||||
|
@ -47,6 +48,11 @@ setup(
|
|||
],
|
||||
'hbmqtt.client.plugins': [
|
||||
'packet_logger_plugin = hbmqtt.plugins.logging:PacketLoggerPlugin',
|
||||
],
|
||||
'console_scripts': [
|
||||
'hbmqtt = scripts.hbmqtt:main',
|
||||
'hbmqtt_pub = scripts.hbmqtt_pub:main',
|
||||
'hbmqtt_sub = scripts.hbmqtt_sub:main',
|
||||
]
|
||||
}
|
||||
)
|
Ładowanie…
Reference in New Issue